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