From 3d854ea6ef0a149b0bb54fa51fc6b510d7cd1be6 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 10 Mar 2012 09:56:26 +2000 Subject: [PATCH] [PATCH] mime_node_open: skip envelope from lines at the start of messages --- e6/ef5f39490ed0502b031b044252b4de0b7ebdc5 | 139 ++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 e6/ef5f39490ed0502b031b044252b4de0b7ebdc5 diff --git a/e6/ef5f39490ed0502b031b044252b4de0b7ebdc5 b/e6/ef5f39490ed0502b031b044252b4de0b7ebdc5 new file mode 100644 index 000000000..142f7609f --- /dev/null +++ b/e6/ef5f39490ed0502b031b044252b4de0b7ebdc5 @@ -0,0 +1,139 @@ +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 99CE6431FB6 + for ; Fri, 9 Mar 2012 05:56:37 -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 CY6UqosvXWQ7 for ; + Fri, 9 Mar 2012 05:56:37 -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 F3179431FAE + for ; Fri, 9 Mar 2012 05:56:36 -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 1S60J9-00079K-Ul; Fri, 09 Mar 2012 09:56:36 -0400 +Received: from bremner by zancas.localnet with local (Exim 4.77) + (envelope-from ) + id 1S60J4-00069f-L9; Fri, 09 Mar 2012 09:56:30 -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:56:26 -0400 +Message-Id: <1331301387-23630-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:56:37 -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 | 24 ++++++++++++++++++++++++ + 1 files changed, 24 insertions(+), 0 deletions(-) + +diff --git a/mime-node.c b/mime-node.c +index a95bdab..cf84423 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 *first_line=NULL; ++ size_t first_line_size=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 (getline(&first_line, &first_line_size, mctx->file) < 0) { ++ fprintf (stderr, "Failed to read first line from %s: %s\n", ++ filename, strerror (errno)); ++ status = NOTMUCH_STATUS_FILE_ERROR; ++ goto DONE; ++ } ++ ++ if (strcmp (first_line, "From ") != 0) { ++ /* No envelope from line */ ++ 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; ++ } ++ } ++ + 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, FALSE); + 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; +@@ -136,6 +157,9 @@ mime_node_open (const void *ctx, notmuch_message_t *message, + return NOTMUCH_STATUS_SUCCESS; + + DONE: ++ if (first_line != NULL) ++ free (first_line); ++ + talloc_free (root); + return status; + } +-- +1.7.9.1 + -- 2.26.2