Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 49 / b74c48da886298f1642ae9dcbc2385897404c0
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 26323431FAF\r
6         for <notmuch@notmuchmail.org>; Fri, 11 Oct 2013 06:53:55 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id E7NuJZOKdixg for <notmuch@notmuchmail.org>;\r
16         Fri, 11 Oct 2013 06:53:48 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu\r
18         [18.9.25.14])\r
19         by olra.theworths.org (Postfix) with ESMTP id BFF62431FAE\r
20         for <notmuch@notmuchmail.org>; Fri, 11 Oct 2013 06:53:48 -0700 (PDT)\r
21 X-AuditID: 1209190e-b7f828e0000009cf-44-525802ecb503\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id A3.32.02511.CE208525; Fri, 11 Oct 2013 09:53:48 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id r9BDrjx0010092; \r
27         Fri, 11 Oct 2013 09:53:46 -0400\r
28 Received: from drake.dyndns.org\r
29         (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [216.15.114.40]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r9BDrhku029569\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Fri, 11 Oct 2013 09:53:44 -0400\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
36         (envelope-from <amdragon@mit.edu>)\r
37         id 1VUd9y-0003jS-Ha; Fri, 11 Oct 2013 09:53:42 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH WIP] emacs: Sanitize authors and subjects in search and show\r
41 Date: Fri, 11 Oct 2013 09:53:39 -0400\r
42 Message-Id: <1381499619-14219-1-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.8.4.rc3\r
44 X-Brightmail-Tracker:\r
45  H4sIAAAAAAAAA+NgFlrMIsWRmVeSWpSXmKPExsUixG6nrvuGKSLIYGWPsEXTdGeL6zdnMjsw\r
46         edy6/5rd49mqW8wBTFFcNimpOZllqUX6dglcGX/+72EveCBVcaoro4HxlmgXIyeHhICJxMK/\r
47         r9khbDGJC/fWs3UxcnEICexjlOhoXgLlbGSUWDD1EjOEc4dJYtvpx4wQzlxGiRn3LoD1swlo\r
48         SGzbv5wRxBYRkJbYeXc2axcjBwezgLnEzZY4kLCwgI/ErW/XmEFsFgFViV9zvzOB2LwCDhKr\r
49         7h9nhjhDSWLhqW2sExh5FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdI11svNLNFLTSndxAgK\r
50         C05Jvh2MXw8qHWIU4GBU4uG1YAgPEmJNLCuuzD3EKMnBpCTKa/cHKMSXlJ9SmZFYnBFfVJqT\r
51         WnyIUYKDWUmEt+0vUI43JbGyKrUoHyYlzcGiJM57k8M+SEggPbEkNTs1tSC1CCYrw8GhJMHr\r
52         Dwx/IcGi1PTUirTMnBKENBMHJ8hwHqDhMSA1vMUFibnFmekQ+VOMilLivGUgCQGQREZpHlwv\r
53         LG5fMYoDvSLMmwxSxQOMebjuV0CDmYAGb/8eAjK4JBEhJdXAmGW4rXbCjp5W11g/nmLLe9O7\r
54         OGc6Oxxz37Z2bc+q/zLekicTWf7N3ZR/Ncb/zeOYjXtdZos+j9+k05O4V5r35fGCqPCMFJ9d\r
55         B4/m+x7b3Z6Vea2PwXXJ7cSFB3Rjd/9onMwYlvNQnzXg8AsHNyv3qKsC2f+ex4nZy3Wnzd+8\r
56         akrGEjPVsMYcJZbijERDLeai4kQA03XnbLYCAAA=\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Fri, 11 Oct 2013 13:53:55 -0000\r
70 \r
71 Authors and subjects can contain embedded, encoded control characters\r
72 like "\n" and "\t" that mess up display.  Transform control characters\r
73 into spaces everywhere we display them in search and show.\r
74 ---\r
75 \r
76 This could obviously use some tests, but I thought I'd get it out\r
77 there to see what people thought or if the behavior should be tweaked.\r
78 \r
79 Of course, I can't guarantee that this is all of the places we display\r
80 untrusted header text.  I'm really not sure how to make that guarantee\r
81 (suggestions welcome).\r
82 \r
83  emacs/notmuch-lib.el  | 6 ++++++\r
84  emacs/notmuch-show.el | 7 ++++---\r
85  emacs/notmuch.el      | 6 ++++--\r
86  3 files changed, 14 insertions(+), 5 deletions(-)\r
87 \r
88 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
89 index 58f3313..6541282 100644\r
90 --- a/emacs/notmuch-lib.el\r
91 +++ b/emacs/notmuch-lib.el\r
92 @@ -243,6 +243,12 @@ depending on the value of `notmuch-poll-script'."\r
93         "[No Subject]"\r
94        subject)))\r
95  \r
96 +(defun notmuch-sanitize (str)\r
97 +  "Sanitize control character in STR.\r
98 +\r
99 +This includes newlines, tabs, and other funny characters."\r
100 +  (replace-regexp-in-string "[[:cntrl:]\x7f\u2028\u2029]+" " " str))\r
101 +\r
102  (defun notmuch-escape-boolean-term (term)\r
103    "Escape a boolean term for use in a query.\r
104  \r
105 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
106 index 7325792..fa11d98 100644\r
107 --- a/emacs/notmuch-show.el\r
108 +++ b/emacs/notmuch-show.el\r
109 @@ -407,7 +407,8 @@ unchanged ADDRESS if parsing fails."\r
110  message at DEPTH in the current thread."\r
111    (let ((start (point)))\r
112      (insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-width depth))\r
113 -           (notmuch-show-clean-address (plist-get headers :From))\r
114 +           (notmuch-sanitize\r
115 +            (notmuch-show-clean-address (plist-get headers :From)))\r
116             " ("\r
117             date\r
118             ") ("\r
119 @@ -417,7 +418,7 @@ message at DEPTH in the current thread."\r
120  \r
121  (defun notmuch-show-insert-header (header header-value)\r
122    "Insert a single header."\r
123 -  (insert header ": " header-value "\n"))\r
124 +  (insert header ": " (notmuch-sanitize header-value) "\n"))\r
125  \r
126  (defun notmuch-show-insert-headers (headers)\r
127    "Insert the headers of the current message."\r
128 @@ -1154,7 +1155,7 @@ function is used."\r
129        (jit-lock-register #'notmuch-show-buttonise-links)\r
130  \r
131        ;; Set the header line to the subject of the first message.\r
132 -      (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-subject)))\r
133 +      (setq header-line-format (notmuch-sanitize (notmuch-show-strip-re (notmuch-show-get-subject))))\r
134  \r
135        (run-hooks 'notmuch-show-hook))))\r
136  \r
137 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
138 index c47c6b5..44cd2fd 100644\r
139 --- a/emacs/notmuch.el\r
140 +++ b/emacs/notmuch.el\r
141 @@ -791,11 +791,13 @@ non-authors is found, assume that all of the authors match."\r
142                                         (plist-get result :total)))\r
143                         'face 'notmuch-search-count)))\r
144     ((string-equal field "subject")\r
145 -    (insert (propertize (format format-string (plist-get result :subject))\r
146 +    (insert (propertize (format format-string\r
147 +                               (notmuch-sanitize (plist-get result :subject)))\r
148                         'face 'notmuch-search-subject)))\r
149  \r
150     ((string-equal field "authors")\r
151 -    (notmuch-search-insert-authors format-string (plist-get result :authors)))\r
152 +    (notmuch-search-insert-authors\r
153 +     format-string (notmuch-sanitize (plist-get result :authors))))\r
154  \r
155     ((string-equal field "tags")\r
156      (let ((tags (plist-get result :tags)))\r
157 -- \r
158 1.8.4.rc3\r
159 \r