[PATCH v4 3/5] dump: Disallow \n in message IDs
authorAustin Clements <amdragon@MIT.EDU>
Mon, 31 Dec 2012 06:42:40 +0000 (01:42 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:53 +0000 (09:52 -0800)
f9/ccdbc96d264dff210fc3bfcc8485ec23316a8d [new file with mode: 0644]

diff --git a/f9/ccdbc96d264dff210fc3bfcc8485ec23316a8d b/f9/ccdbc96d264dff210fc3bfcc8485ec23316a8d
new file mode 100644 (file)
index 0000000..5d8bca1
--- /dev/null
@@ -0,0 +1,128 @@
+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 07812431FBD\r
+       for <notmuch@notmuchmail.org>; Sun, 30 Dec 2012 22:42:53 -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 EbO6ohPmdR2V for <notmuch@notmuchmail.org>;\r
+       Sun, 30 Dec 2012 22:42:52 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+       [18.9.25.15])\r
+       by olra.theworths.org (Postfix) with ESMTP id 26502431FB6\r
+       for <notmuch@notmuchmail.org>; Sun, 30 Dec 2012 22:42:52 -0800 (PST)\r
+X-AuditID: 1209190f-b7f016d000000e07-af-50e133eb4e52\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id FB.5C.03591.BE331E05; Mon, 31 Dec 2012 01:42:51 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBV6gohR026113; \r
+       Mon, 31 Dec 2012 01:42:50 -0500\r
+Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
+       [76.21.105.205]) (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 qBV6gkFX009881\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Mon, 31 Dec 2012 01:42:49 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1TpZ5C-0000ij-2u; Mon, 31 Dec 2012 01:42:46 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 3/5] dump: Disallow \n in message IDs\r
+Date: Mon, 31 Dec 2012 01:42:40 -0500\r
+Message-Id: <1356936162-2589-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1356936162-2589-1-git-send-email-amdragon@mit.edu>\r
+References: <1356936162-2589-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrNIsWRmVeSWpSXmKPExsUixG6nrvva+GGAwf5XhhY3WrsZLZqmO1us\r
+       nstjcf3mTGaLNyvnsTqweuycdZfd4/DXhSwet+6/Zvd4tuoWs8eWQ++ZA1ijuGxSUnMyy1KL\r
+       9O0SuDKuzO9nLVguWLHr+RXmBsZbvF2MnBwSAiYSD058ZIewxSQu3FvP1sXIxSEksI9RYuqb\r
+       q6wQzgZGifcvT0BlLjJJHNu4nhnCmcso8enYOkaQfjYBDYlt+5eD2SIC0hI7784Ga2cWaGKU\r
+       uLZpLhtIQljAQmLDnx1gC1kEVCUWvHrIDGLzCthL/Fz0ihXiEEWJ7mcTwOo5BRwkdj6bxQJi\r
+       CwHV7N57nnECI/8CRoZVjLIpuVW6uYmZOcWpybrFyYl5ealFuiZ6uZkleqkppZsYQWHIKcm/\r
+       g/HbQaVDjAIcjEo8vBxMDwOEWBPLiitzDzFKcjApifIqAYNYiC8pP6UyI7E4I76oNCe1+BCj\r
+       BAezkgjvWy2gHG9KYmVValE+TEqag0VJnPdqyk1/IYH0xJLU7NTUgtQimKwMB4eSBO8GI6BG\r
+       waLU9NSKtMycEoQ0EwcnyHAeoOEfQWp4iwsSc4sz0yHypxgVpcR5n4MkBEASGaV5cL2wNPGK\r
+       URzoFWHe8yBVPMAUA9f9CmgwE9BgLYYHIINLEhFSUg2MUUJHXxYEbH3FM6fqzRqPaQvOzOGc\r
+       ceGlwypJseB5yuE/jwYXzpO2WavDJ8hWGSZxrOFkbvmDT94VDYXiIm3PP4ecXrHBllumYfbT\r
+       jYKr4iet35157Zrkq+mM1jdnzItfJtA7XY65ITH2xNGO2Fdz1bbwbAhhv21SvO/f/eAX7+/O\r
+       6Xco3BUgqsRSnJFoqMVcVJwIAD8eXB/uAgAA\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: Mon, 31 Dec 2012 06:42:53 -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       |    9 +++++++++\r
+ test/random-corpus.c |    4 +++-\r
+ 2 files changed, 12 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+index d2dad40..29d79da 100644\r
+--- a/notmuch-dump.c\r
++++ b/notmuch-dump.c\r
+@@ -132,6 +132,15 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+       if (output_format == DUMP_FORMAT_SUP) {\r
+           fputs (")\n", output);\r
+       } else {\r
++          if (strchr (message_id, '\n')) {\r
++              /* This will produce a line break in the output, which\r
++               * would be difficult to handle in tools.  However,\r
++               * it's also impossible to produce an email containing\r
++               * a line break in a message ID because of unfolding,\r
++               * so we can safely disallow it. */\r
++              fprintf (stderr, "Error: cannot dump message id containing line break: %s\n", message_id);\r
++              return 1;\r
++          }\r
+           if (hex_encode (notmuch, message_id,\r
+                           &buffer, &buffer_size) != HEX_SUCCESS) {\r
+                   fprintf (stderr, "Error: failed to hex-encode msg-id %s\n",\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