From a8c4c0979f9de63cb38b093c807452fa5ebac256 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 10 Mar 2012 09:31:59 +2000 Subject: [PATCH] [PATCH] mime_node_open: skip envelope from lines at the start of messages --- 37/f6974007da8b409727fc2a9c423f485b93c9b6 | 129 ++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 37/f6974007da8b409727fc2a9c423f485b93c9b6 diff --git a/37/f6974007da8b409727fc2a9c423f485b93c9b6 b/37/f6974007da8b409727fc2a9c423f485b93c9b6 new file mode 100644 index 000000000..015db0c8f --- /dev/null +++ b/37/f6974007da8b409727fc2a9c423f485b93c9b6 @@ -0,0 +1,129 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 1CFBF431FB6 + for ; Fri, 9 Mar 2012 05:32:24 -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 8zBUOc24ffYk for ; + Fri, 9 Mar 2012 05:32:23 -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 72658431FAE + for ; Fri, 9 Mar 2012 05:32:23 -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 1S5zvf-00078P-Ls; Fri, 09 Mar 2012 09:32:19 -0400 +Received: from bremner by zancas.localnet with local (Exim 4.77) + (envelope-from ) + id 1S5zva-0005eN-Em; Fri, 09 Mar 2012 09:32:14 -0400 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH] mime_node_open: skip envelope from lines at the start of + messages +Date: Fri, 9 Mar 2012 09:31:59 -0400 +Message-Id: <1331299919-21688-1-git-send-email-david@tethera.net> +X-Mailer: git-send-email 1.7.9.1 +In-Reply-To: +References: +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: Fri, 09 Mar 2012 13:32:24 -0000 + +From: David Bremner + +Some MDAs such as procmail (in MH mode), and exim (doing local +delivery in some configurations of the appendfile transport) add a +line to the front of a message with "From " followed by envelope +sender. Since this is not a proper RFC822 header field, gmime (at +least since version 2.6) refuses to parse it, unless in mbox mode. + +This change reads the line of the file, and if they start with +"From ", pass the stream to gmime starting from the second line. + +This makes mime_node_open more consistent with (but still stricter +than) the permissive behaviour of notmuch_file_get_header +(message-file.c), which allows a certain number of "broken_headers". + +We avoid putting gmime into mbox mode in case of side effects; this +leaves the situation of mboxes accidentally indexed by notmuch the +same as before, namely "undefined behaviour". Ideally they should at +least be warned by notmuch-new. Although strict rfc822 adherence +would be one way to detect mboxes, it doesn't seem to fit with the +spirit or code of message-file.c. +--- + 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 + -- 2.26.2