[PATCH v5 4/6] dump: Disallow \n in message IDs
authorAustin Clements <amdragon@MIT.EDU>
Sun, 6 Jan 2013 20:22:40 +0000 (15:22 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:58 +0000 (09:52 -0800)
bf/f76a79fbc2277a03872dac51d1e544719c26ee [new file with mode: 0644]

diff --git a/bf/f76a79fbc2277a03872dac51d1e544719c26ee b/bf/f76a79fbc2277a03872dac51d1e544719c26ee
new file mode 100644 (file)
index 0000000..b60b57c
--- /dev/null
@@ -0,0 +1,131 @@
+Return-Path: <amdragon@mit.edu>\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 96349431FDC\r
+       for <notmuch@notmuchmail.org>; Sun,  6 Jan 2013 12:23:14 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 eWvGPSbW8JwR for <notmuch@notmuchmail.org>;\r
+       Sun,  6 Jan 2013 12:23:14 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id D0189431FBF\r
+       for <notmuch@notmuchmail.org>; Sun,  6 Jan 2013 12:23:13 -0800 (PST)\r
+X-AuditID: 12074423-b7ef96d000000725-23-50e9dd31753a\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 27.D1.01829.13DD9E05; Sun,  6 Jan 2013 15:23:13 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id r06KNBfY002905; \r
+       Sun, 6 Jan 2013 15:23:11 -0500\r
+Received: from drake.dyndns.org (a069.catapulsion.net [70.36.81.69])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id r06KMvMj020351\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sun, 6 Jan 2013 15:23:09 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1Trwk7-0007YH-LX; Sun, 06 Jan 2013 15:22:51 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 4/6] dump: Disallow \n in message IDs\r
+Date: Sun,  6 Jan 2013 15:22:40 -0500\r
+Message-Id: <1357503762-28759-5-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1357503762-28759-1-git-send-email-amdragon@mit.edu>\r
+References: <1357503762-28759-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrFIsWRmVeSWpSXmKPExsUixG6nomt492WAweJPahY3WrsZLZqmO1us\r
+       nstjcf3mTGaLNyvnsTqweuycdZfd4/DXhSwet+6/Zvd4tuoWs8eWQ++ZA1ijuGxSUnMyy1KL\r
+       9O0SuDKWbDvEUvBSsOLbtLnMDYzT+LoYOTkkBEwkFv85zwxhi0lcuLeerYuRi0NIYB+jxIwj\r
+       JxkhnPWMEvMvvYfK7GeSuNzczQThzGWU2HJzGwtIP5uAhsS2/csZQWwRAWmJnXdns4IUMQs0\r
+       MUpc2zSXDSQhLGAhcebiGyYQm0VAVeL0s/1gDbwCDhLdH1vZIQ5RlOh+NgGonoODU8BR4uM8\r
+       WZCwEFDJnR332Scw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiXl1qka6aXm1mil5pSuokRHIQu\r
+       yjsY/xxUOsQowMGoxMN7YeeLACHWxLLiytxDjJIcTEqivLsvvgwQ4kvKT6nMSCzOiC8qzUkt\r
+       PsQowcGsJMK77xhQjjclsbIqtSgfJiXNwaIkznst5aa/kEB6YklqdmpqQWoRTFaGg0NJglfy\r
+       DlCjYFFqempFWmZOCUKaiYMTZDgP0PCXt0GGFxck5hZnpkPkTzEqSonzyoA0C4AkMkrz4Hph\r
+       SeIVozjQK8K8BiBVPMAEA9f9CmgwE9Dg1MfPQQaXJCKkpBoYs9cw+R4/ssvfZVJ0jur53KvK\r
+       Tzvaz+buKotd9PvUqtNf2hnPXws4oOWqVXt++sTlN3852+z9cih5Ve77iafPSJ63mz1J+IP6\r
+       makxE5IXeN4+/Toz56LI8fp161aYfn6/zqdm52WNmjIGxWcXLvH3PuG91te+umzi3836V03X\r
+       KemLWqedi+B1XqzEUpyRaKjFXFScCACVouas7QIAAA==\r
+Cc: tomi.ollila@iki.fi\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: Sun, 06 Jan 2013 20:23:14 -0000\r
+\r
+When we switch to using regular Xapian queries in the dump format, \n\r
+will cause problems, so we disallow it.  Specially, while Xapian can\r
+quote and parse queries containing \n without difficultly, quoted\r
+queries containing \n still span multiple lines, which breaks the\r
+line-orientedness of the dump format.  Strictly speaking, we could\r
+still round-trip these, but it would significantly complicate restore\r
+as well as scripts that deal with tag dumps.  This complexity would\r
+come at absolutely no benefit: because of the RFC 2822 unfolding\r
+rules, no amount of standards negligence can produce a message with a\r
+message ID containing a line break (not even Outlook can do it!).\r
+\r
+Hence, we simply disallow it.\r
+---\r
+ notmuch-dump.c       |   12 ++++++++++++\r
+ test/random-corpus.c |    4 +++-\r
+ 2 files changed, 15 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+index d2dad40..5bbda36 100644\r
+--- a/notmuch-dump.c\r
++++ b/notmuch-dump.c\r
+@@ -102,6 +102,18 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+       message = notmuch_messages_get (messages);\r
+       message_id = notmuch_message_get_message_id (message);\r
\r
++      if (output_format == DUMP_FORMAT_BATCH_TAG &&\r
++          strchr (message_id, '\n')) {\r
++          /* This will produce a line break in the output, which\r
++           * would be difficult to handle in tools.  However, it's\r
++           * also impossible to produce an email containing a line\r
++           * break in a message ID because of unfolding, so we can\r
++           * safely disallow it. */\r
++          fprintf (stderr, "Warning: skipping message id containing line break: \"%s\"\n", message_id);\r
++          notmuch_message_destroy (message);\r
++          continue;\r
++      }\r
++\r
+       if (output_format == DUMP_FORMAT_SUP) {\r
+           fprintf (output, "%s (", message_id);\r
+       }\r
+diff --git a/test/random-corpus.c b/test/random-corpus.c\r
+index f354d4b..8b7748e 100644\r
+--- a/test/random-corpus.c\r
++++ b/test/random-corpus.c\r
+@@ -96,7 +96,9 @@ random_utf8_string (void *ctx, size_t char_count)\r
+           buf = talloc_realloc (ctx, buf, gchar, buf_size);\r
+       }\r
\r
+-      randomchar = random_unichar ();\r
++      do {\r
++          randomchar = random_unichar ();\r
++      } while (randomchar == '\n');\r
\r
+       written = g_unichar_to_utf8 (randomchar, buf + offset);\r
\r
+-- \r
+1.7.10.4\r
+\r