[Patch v3 5/8] emacs: show: mark tags changed since buffer loaded
[notmuch-archives.git] / 4e / 337c49f52a82834e1b4791a197814bfaa80fd9
1 Return-Path: <vasile@softwarefreedom.org>\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 10BC2431FB6\r
6         for <notmuch@notmuchmail.org>; Wed, 16 Mar 2011 18:44:35 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 kTlDYTy33rYk for <notmuch@notmuchmail.org>;\r
16         Wed, 16 Mar 2011 18:44:34 -0700 (PDT)\r
17 Received: from mail.sflc.info (mail.sflc.info [216.27.154.199])\r
18         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 286DD431FB5\r
21         for <notmuch@notmuchmail.org>; Wed, 16 Mar 2011 18:44:34 -0700 (PDT)\r
22 Received: from localhost (ool-18bd39a4.dyn.optonline.net [24.189.57.164])\r
23         by mail.sflc.info (Postfix) with ESMTPSA id 5DDF5680003\r
24         for <notmuch@notmuchmail.org>; Thu, 17 Mar 2011 01:44:28 +0000 (UTC)\r
25 From: James Vasile <james@hackervisions.org>\r
26 To: notmuch <notmuch@notmuchmail.org>\r
27 Subject: [PATCH] Remove/replace vertical whitespace in subject header field\r
28         body.\r
29 User-Agent: Notmuch/0.5-213-gc96d76a (http://notmuchmail.org) Emacs/23.2.1\r
30         (x86_64-pc-linux-gnu)\r
31 Date: Wed, 16 Mar 2011 21:44:28 -0400\r
32 Message-ID: <87ipvifrlv.fsf@softwarefreedom.org>\r
33 MIME-Version: 1.0\r
34 Content-Type: multipart/mixed; boundary="=-=-="\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Thu, 17 Mar 2011 01:44:35 -0000\r
48 \r
49 --=-=-=\r
50 Content-Type: text/plain; charset=utf-8\r
51 Content-Transfer-Encoding: quoted-printable\r
52 \r
53 RFC 822 specifies that headers are one-liners of ASCII:\r
54 \r
55 > The field-body may be composed of any ASCII characters, except CR or\r
56 > LF.  (While CR and/or LF may be present in the actual text, they are\r
57 > removed by the action of unfolding the field.)\r
58 \r
59 RFC 5335 allows UTF-8 in header field bodies, but as I read the docs,\r
60 the RFC 822 specification that they end up as one-liners still applies.\r
61 \r
62 RFC 5322 describes folding and unfolding as follows:\r
63 \r
64 > Each header field is logically a single line of characters comprising\r
65 > the field name, the colon, and the field body. For convenience\r
66 > however, and to deal with the 998/78 character limitations per line,\r
67 > the field body portion of a header field can be split into a\r
68 > multiple-line representation; this is called "folding". The general\r
69 > rule is that wherever this specification allows for folding white\r
70 > space (not simply WSP characters), a CRLF may be inserted before any\r
71 > WSP.\r
72 ...\r
73 > The process of moving from this folded multiple-line representation of\r
74 > a header field to its single line representation is called\r
75 > "unfolding". Unfolding is accomplished by simply removing any CRLF\r
76 > that is immediately followed by WSP.\r
77 \r
78 Again, unfolded subjects should be one-liners.\r
79 \r
80 An email was sent to me from pingg.com (I think it's a pretentious\r
81 version of evite) came with a subject of\r
82 "=3D?utf-8?Q?bring_small_items_for_a_pi=3DC3=3DB1ata=3D21=3D21=3D21=3D21=3D=\r
83 0A?=3D", which\r
84 "notmuch search" displays as "Subject: bring small items for a\r
85 pi=C3=B1ata!!!!" with a \n at the end.  This befuddles the emacs UI ("Error:\r
86 Unexpected output from notmuch search:").  I've attached an email that\r
87 reproduces the error.\r
88 \r
89 I don't think ending the subject with a utf-8-encoded 0x0A followed by\r
90 the usual CRLF is RFC-compliant.  Still, notmuch should surely follow\r
91 the deplorable "accept liberally/emit conservatively" doctrine.\r
92 \r
93 Here is a patch that trims leading and trailing whitespace from subjects\r
94 and replaces internal non-space, non-horizontal-tab whitespace with\r
95 spaces.  It fixes the problem described in this message.\r
96 ---\r
97  lib/thread.cc |   36 ++++++++++++++++++++++++++++++++----\r
98  1 files changed, 32 insertions(+), 4 deletions(-)\r
99 \r
100 diff --git a/lib/thread.cc b/lib/thread.cc\r
101 index 5190a66..7a816ea 100644\r
102 --- a/lib/thread.cc\r
103 +++ b/lib/thread.cc\r
104 @@ -266,6 +266,34 @@ _thread_add_message (notmuch_thread_t *thread,\r
105      }\r
106  }\r
107 =20\r
108 +/* Remove leading/trailing whitespace and replace internal vertical\r
109 + * whitespace with spaces.\r
110 + */\r
111 +static char *\r
112 +rectify_whitespace (char *str)\r
113 +{\r
114 +  char *last;\r
115 +  char *curr;\r
116 +\r
117 +  while (isspace (*str))\r
118 +    str++;\r
119 +\r
120 +  if (*str =3D=3D 0)\r
121 +    return str;\r
122 +\r
123 +  last =3D str + strlen(str) - 1;\r
124 +  while (last > str && isspace (*last))\r
125 +    last--;\r
126 +\r
127 +  curr =3D str;\r
128 +  do\r
129 +    if ((*curr >=3D 10) && (*curr <=3D 13))\r
130 +      *curr =3D 32; //space\r
131 +  while (curr++ < last);\r
132 +\r
133 +  return str;\r
134 +}\r
135 +\r
136  static void\r
137  _thread_set_subject_from_message (notmuch_thread_t *thread,\r
138                                   notmuch_message_t *message)\r
139 @@ -282,11 +310,11 @@ _thread_set_subject_from_message (notmuch_thread_t *t=\r
140 hread,\r
141         (strncasecmp (subject, "Vs: ", 4) =3D=3D 0) ||\r
142         (strncasecmp (subject, "Sv: ", 4) =3D=3D 0)) {\r
143 =20\r
144 -       cleaned_subject =3D talloc_strndup (thread,\r
145 -                                         subject + 4,\r
146 -                                         strlen(subject) - 4);\r
147 +      cleaned_subject =3D rectify_whitespace(talloc_strndup (thread,\r
148 +                                                          subject + 4,\r
149 +                                                          strlen(subject) - 4));\r
150      } else {\r
151 -       cleaned_subject =3D talloc_strdup (thread, subject);\r
152 +      cleaned_subject =3D rectify_whitespace(talloc_strdup (thread, subjec=\r
153 t));\r
154      }\r
155 =20\r
156      if (thread->subject)\r
157 --=20\r
158 1.7.2.3\r
159 \r
160 \r
161 \r
162 \r
163 --=-=-=\r
164 Content-Type: application/octet-stream\r
165 Content-Disposition: attachment; filename=malformed_subject\r
166 Content-Transfer-Encoding: base64\r
167 \r
168 RGF0ZTogRnJpLCAxMSBNYXIgMjAxMSAxODo0MDowMCArMDAwMApGcm9tOiAicmVkYWN0ZWQiIDxo\r
169 b3N0QGludml0ZS5waW5nZy5jb20+ClRvOiByZWRhY3RlZEBleGFtcGxlLmNvbQpNZXNzYWdlLUlk\r
170 OiA8MjAxMTAzMTExODM3NDkuNTI2NzcxLjMxNDUzLjk4NDE4NDFAc2VuZGVyLnBpbmdnLmNvbT4K\r
171 U3ViamVjdDogPT91dGYtOD9RP2JyaW5nX3NtYWxsX2l0ZW1zX2Zvcl9hX3BpPUMzPUIxYXRhPTIx\r
172 PTIxPTIxPTIxPTBBPz0KTWltZS1WZXJzaW9uOiAxLjAKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWlu\r
173 OyBjaGFyc2V0PSJ1cy1hc2NpaSIKQ29udGVudC1UcmFuc2Zlci1FbmNvZGluZzogN2JpdAoKSWdu\r
174 b3JlIHRoaXMuCg==\r
175 --=-=-=--\r