[PATCH] mime_node_open: check if the file is in mbox format, and inform gmime.
authorDavid Bremner <david@tethera.net>
Thu, 8 Mar 2012 21:48:15 +0000 (17:48 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:19 +0000 (09:45 -0800)
30/25243821de7aa244e362a041a5ca6520643e1a [new file with mode: 0644]

diff --git a/30/25243821de7aa244e362a041a5ca6520643e1a b/30/25243821de7aa244e362a041a5ca6520643e1a
new file mode 100644 (file)
index 0000000..23574ff
--- /dev/null
@@ -0,0 +1,119 @@
+Return-Path: <bremner@tethera.net>\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 F24E6431FBC\r
+       for <notmuch@notmuchmail.org>; Thu,  8 Mar 2012 13:48:28 -0800 (PST)\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 nq504gGFks6h for <notmuch@notmuchmail.org>;\r
+       Thu,  8 Mar 2012 13:48:27 -0800 (PST)\r
+Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
+       (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 42BE1431FAE\r
+       for <notmuch@notmuchmail.org>; Thu,  8 Mar 2012 13:48:27 -0800 (PST)\r
+Received: from fctnnbsc30w-142166230117.dhcp-dynamic.fibreop.nb.bellaliant.net\r
+       ([142.166.230.117] helo=zancas.localnet)\r
+       by tesseract.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)\r
+       (Exim 4.72) (envelope-from <bremner@tethera.net>)\r
+       id 1S5lCC-0006Qd-SI; Thu, 08 Mar 2012 17:48:25 -0400\r
+Received: from bremner by zancas.localnet with local (Exim 4.77)\r
+       (envelope-from <bremner@tethera.net>)\r
+       id 1S5lC7-00077J-AF; Thu, 08 Mar 2012 17:48:19 -0400\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] mime_node_open: check if the file is in mbox format,\r
+       and inform gmime.\r
+Date: Thu,  8 Mar 2012 17:48:15 -0400\r
+Message-Id: <1331243295-27324-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <87vcme3kf6.fsf@pip.fifthhorseman.net>\r
+References: <87vcme3kf6.fsf@pip.fifthhorseman.net>\r
+X-Spam_bar: -\r
+Cc: David Bremner <bremner@debian.org>\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, 08 Mar 2012 21:48:29 -0000\r
+\r
+From: David Bremner <bremner@debian.org>\r
+\r
+It seems that it has always been an error to try to parse an mbox\r
+format file with gmime without calling g_mime_parser_set_scan_from.\r
+\r
+This change reads the first 5 bytes of the file, and if they are "From ",\r
+declares the file to be an mbox.\r
+---\r
+\r
+This patch seems to fix the problem for me. I don't think the\r
+performance impact should be too bad, but I didn't really test it.\r
+\r
+ mime-node.c |   21 +++++++++++++++++++++\r
+ 1 files changed, 21 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/mime-node.c b/mime-node.c\r
+index a95bdab..8939147 100644\r
+--- a/mime-node.c\r
++++ b/mime-node.c\r
+@@ -72,6 +72,8 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
+     mime_node_context_t *mctx;\r
+     mime_node_t *root;\r
+     notmuch_status_t status;\r
++    char from_buf[6]; /* From space NULL */\r
++    int is_mbox = 0;\r
+ \r
+     root = talloc_zero (ctx, mime_node_t);\r
+     if (root == NULL) {\r
+@@ -96,6 +98,23 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
+       goto DONE;\r
+     }\r
+ \r
++    if (fread (from_buf, 1, 5, mctx->file) != 5) {\r
++      fprintf (stderr, "Failed to read 5 bytes from %s: %s\n",\r
++               filename, strerror (errno));\r
++      status = NOTMUCH_STATUS_FILE_ERROR;\r
++      goto DONE;\r
++    }\r
++    from_buf[5] = '\0';\r
++\r
++    if (fseek (mctx->file, 0L, SEEK_SET)) {\r
++      fprintf (stderr, "Failed to rewind %s: %s\n",\r
++               filename, strerror (errno));\r
++      status = NOTMUCH_STATUS_FILE_ERROR;\r
++      goto DONE;\r
++    }\r
++\r
++    is_mbox = (strcmp (from_buf, "From ") == 0);\r
++\r
+     mctx->stream = g_mime_stream_file_new (mctx->file);\r
+     if (!mctx->stream) {\r
+       fprintf (stderr, "Out of memory.\n");\r
+@@ -111,7 +130,9 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
+       goto DONE;\r
+     }\r
+ \r
++    g_mime_parser_set_scan_from (mctx->parser, is_mbox);\r
+     mctx->mime_message = g_mime_parser_construct_message (mctx->parser);\r
++\r
+     if (!mctx->mime_message) {\r
+       fprintf (stderr, "Failed to parse %s\n", filename);\r
+       status = NOTMUCH_STATUS_FILE_ERROR;\r
+-- \r
+1.7.9.1\r
+\r