[PATCH] Remove/replace vertical whitespace in subject header field body.
authorJames Vasile <james@hackervisions.org>
Thu, 17 Mar 2011 01:44:28 +0000 (21:44 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:00 +0000 (09:38 -0800)
4e/337c49f52a82834e1b4791a197814bfaa80fd9 [new file with mode: 0644]

diff --git a/4e/337c49f52a82834e1b4791a197814bfaa80fd9 b/4e/337c49f52a82834e1b4791a197814bfaa80fd9
new file mode 100644 (file)
index 0000000..b0f285e
--- /dev/null
@@ -0,0 +1,175 @@
+Return-Path: <vasile@softwarefreedom.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 10BC2431FB6\r
+       for <notmuch@notmuchmail.org>; Wed, 16 Mar 2011 18:44:35 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id kTlDYTy33rYk for <notmuch@notmuchmail.org>;\r
+       Wed, 16 Mar 2011 18:44:34 -0700 (PDT)\r
+Received: from mail.sflc.info (mail.sflc.info [216.27.154.199])\r
+       (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 286DD431FB5\r
+       for <notmuch@notmuchmail.org>; Wed, 16 Mar 2011 18:44:34 -0700 (PDT)\r
+Received: from localhost (ool-18bd39a4.dyn.optonline.net [24.189.57.164])\r
+       by mail.sflc.info (Postfix) with ESMTPSA id 5DDF5680003\r
+       for <notmuch@notmuchmail.org>; Thu, 17 Mar 2011 01:44:28 +0000 (UTC)\r
+From: James Vasile <james@hackervisions.org>\r
+To: notmuch <notmuch@notmuchmail.org>\r
+Subject: [PATCH] Remove/replace vertical whitespace in subject header field\r
+       body.\r
+User-Agent: Notmuch/0.5-213-gc96d76a (http://notmuchmail.org) Emacs/23.2.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Wed, 16 Mar 2011 21:44:28 -0400\r
+Message-ID: <87ipvifrlv.fsf@softwarefreedom.org>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/mixed; boundary="=-=-="\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 17 Mar 2011 01:44:35 -0000\r
+\r
+--=-=-=\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+RFC 822 specifies that headers are one-liners of ASCII:\r
+\r
+> The field-body may be composed of any ASCII characters, except CR or\r
+> LF.  (While CR and/or LF may be present in the actual text, they are\r
+> removed by the action of unfolding the field.)\r
+\r
+RFC 5335 allows UTF-8 in header field bodies, but as I read the docs,\r
+the RFC 822 specification that they end up as one-liners still applies.\r
+\r
+RFC 5322 describes folding and unfolding as follows:\r
+\r
+> Each header field is logically a single line of characters comprising\r
+> the field name, the colon, and the field body. For convenience\r
+> however, and to deal with the 998/78 character limitations per line,\r
+> the field body portion of a header field can be split into a\r
+> multiple-line representation; this is called "folding". The general\r
+> rule is that wherever this specification allows for folding white\r
+> space (not simply WSP characters), a CRLF may be inserted before any\r
+> WSP.\r
+...\r
+> The process of moving from this folded multiple-line representation of\r
+> a header field to its single line representation is called\r
+> "unfolding". Unfolding is accomplished by simply removing any CRLF\r
+> that is immediately followed by WSP.\r
+\r
+Again, unfolded subjects should be one-liners.\r
+\r
+An email was sent to me from pingg.com (I think it's a pretentious\r
+version of evite) came with a subject of\r
+"=3D?utf-8?Q?bring_small_items_for_a_pi=3DC3=3DB1ata=3D21=3D21=3D21=3D21=3D=\r
+0A?=3D", which\r
+"notmuch search" displays as "Subject: bring small items for a\r
+pi=C3=B1ata!!!!" with a \n at the end.  This befuddles the emacs UI ("Error:\r
+Unexpected output from notmuch search:").  I've attached an email that\r
+reproduces the error.\r
+\r
+I don't think ending the subject with a utf-8-encoded 0x0A followed by\r
+the usual CRLF is RFC-compliant.  Still, notmuch should surely follow\r
+the deplorable "accept liberally/emit conservatively" doctrine.\r
+\r
+Here is a patch that trims leading and trailing whitespace from subjects\r
+and replaces internal non-space, non-horizontal-tab whitespace with\r
+spaces.  It fixes the problem described in this message.\r
+---\r
+ lib/thread.cc |   36 ++++++++++++++++++++++++++++++++----\r
+ 1 files changed, 32 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/lib/thread.cc b/lib/thread.cc\r
+index 5190a66..7a816ea 100644\r
+--- a/lib/thread.cc\r
++++ b/lib/thread.cc\r
+@@ -266,6 +266,34 @@ _thread_add_message (notmuch_thread_t *thread,\r
+     }\r
+ }\r
+=20\r
++/* Remove leading/trailing whitespace and replace internal vertical\r
++ * whitespace with spaces.\r
++ */\r
++static char *\r
++rectify_whitespace (char *str)\r
++{\r
++  char *last;\r
++  char *curr;\r
++\r
++  while (isspace (*str))\r
++    str++;\r
++\r
++  if (*str =3D=3D 0)\r
++    return str;\r
++\r
++  last =3D str + strlen(str) - 1;\r
++  while (last > str && isspace (*last))\r
++    last--;\r
++\r
++  curr =3D str;\r
++  do\r
++    if ((*curr >=3D 10) && (*curr <=3D 13))\r
++      *curr =3D 32; //space\r
++  while (curr++ < last);\r
++\r
++  return str;\r
++}\r
++\r
+ static void\r
+ _thread_set_subject_from_message (notmuch_thread_t *thread,\r
+                                 notmuch_message_t *message)\r
+@@ -282,11 +310,11 @@ _thread_set_subject_from_message (notmuch_thread_t *t=\r
+hread,\r
+       (strncasecmp (subject, "Vs: ", 4) =3D=3D 0) ||\r
+       (strncasecmp (subject, "Sv: ", 4) =3D=3D 0)) {\r
+=20\r
+-      cleaned_subject =3D talloc_strndup (thread,\r
+-                                        subject + 4,\r
+-                                        strlen(subject) - 4);\r
++      cleaned_subject =3D rectify_whitespace(talloc_strndup (thread,\r
++                                                         subject + 4,\r
++                                                         strlen(subject) - 4));\r
+     } else {\r
+-      cleaned_subject =3D talloc_strdup (thread, subject);\r
++      cleaned_subject =3D rectify_whitespace(talloc_strdup (thread, subjec=\r
+t));\r
+     }\r
+=20\r
+     if (thread->subject)\r
+--=20\r
+1.7.2.3\r
+\r
+\r
+\r
+\r
+--=-=-=\r
+Content-Type: application/octet-stream\r
+Content-Disposition: attachment; filename=malformed_subject\r
+Content-Transfer-Encoding: base64\r
+\r
+RGF0ZTogRnJpLCAxMSBNYXIgMjAxMSAxODo0MDowMCArMDAwMApGcm9tOiAicmVkYWN0ZWQiIDxo\r
+b3N0QGludml0ZS5waW5nZy5jb20+ClRvOiByZWRhY3RlZEBleGFtcGxlLmNvbQpNZXNzYWdlLUlk\r
+OiA8MjAxMTAzMTExODM3NDkuNTI2NzcxLjMxNDUzLjk4NDE4NDFAc2VuZGVyLnBpbmdnLmNvbT4K\r
+U3ViamVjdDogPT91dGYtOD9RP2JyaW5nX3NtYWxsX2l0ZW1zX2Zvcl9hX3BpPUMzPUIxYXRhPTIx\r
+PTIxPTIxPTIxPTBBPz0KTWltZS1WZXJzaW9uOiAxLjAKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWlu\r
+OyBjaGFyc2V0PSJ1cy1hc2NpaSIKQ29udGVudC1UcmFuc2Zlci1FbmNvZGluZzogN2JpdAoKSWdu\r
+b3JlIHRoaXMuCg==\r
+--=-=-=--\r