Re: Hi all
[notmuch-archives.git] / 37 / f6974007da8b409727fc2a9c423f485b93c9b6
1 Return-Path: <bremner@tethera.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 1CFBF431FB6\r
6         for <notmuch@notmuchmail.org>; Fri,  9 Mar 2012 05:32:24 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id 8zBUOc24ffYk for <notmuch@notmuchmail.org>;\r
16         Fri,  9 Mar 2012 05:32:23 -0800 (PST)\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
18         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 72658431FAE\r
21         for <notmuch@notmuchmail.org>; Fri,  9 Mar 2012 05:32:23 -0800 (PST)\r
22 Received: from fctnnbsc30w-142166230117.dhcp-dynamic.fibreop.nb.bellaliant.net\r
23         ([142.166.230.117] helo=zancas.localnet)\r
24         by tesseract.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)\r
25         (Exim 4.72) (envelope-from <bremner@tethera.net>)\r
26         id 1S5zvf-00078P-Ls; Fri, 09 Mar 2012 09:32:19 -0400\r
27 Received: from bremner by zancas.localnet with local (Exim 4.77)\r
28         (envelope-from <bremner@tethera.net>)\r
29         id 1S5zva-0005eN-Em; Fri, 09 Mar 2012 09:32:14 -0400\r
30 From: David Bremner <david@tethera.net>\r
31 To: notmuch@notmuchmail.org\r
32 Subject: [PATCH] mime_node_open: skip envelope from lines at the start of\r
33         messages\r
34 Date: Fri,  9 Mar 2012 09:31:59 -0400\r
35 Message-Id: <1331299919-21688-1-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.9.1\r
37 In-Reply-To: <m2aa3qjbfo.fsf@guru.guru-group.fi>\r
38 References: <m2aa3qjbfo.fsf@guru.guru-group.fi>\r
39 X-Spam_bar: -\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Fri, 09 Mar 2012 13:32:24 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 Some MDAs such as procmail (in MH mode), and exim (doing local\r
58 delivery in some configurations of the appendfile transport) add a\r
59 line to the front of a message with "From " followed by envelope\r
60 sender.  Since this is not a proper RFC822 header field, gmime (at\r
61 least since version 2.6) refuses to parse it, unless in mbox mode.\r
62 \r
63 This change reads the line of the file, and if they start with\r
64 "From ", pass the stream to gmime starting from the second line.\r
65 \r
66 This makes mime_node_open more consistent with (but still stricter\r
67 than) the permissive behaviour of notmuch_file_get_header\r
68 (message-file.c), which allows a certain number of "broken_headers".\r
69 \r
70 We avoid putting gmime into mbox mode in case of side effects; this\r
71 leaves the situation of mboxes accidentally indexed by notmuch the\r
72 same as before, namely "undefined behaviour".  Ideally they should at\r
73 least be warned by notmuch-new.  Although strict rfc822 adherence\r
74 would be one way to detect mboxes, it doesn't seem to fit with the\r
75 spirit or code of message-file.c.\r
76 ---\r
77  mime-node.c |   21 +++++++++++++++++++++\r
78  1 files changed, 21 insertions(+), 0 deletions(-)\r
79 \r
80 diff --git a/mime-node.c b/mime-node.c\r
81 index a95bdab..8939147 100644\r
82 --- a/mime-node.c\r
83 +++ b/mime-node.c\r
84 @@ -72,6 +72,8 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
85      mime_node_context_t *mctx;\r
86      mime_node_t *root;\r
87      notmuch_status_t status;\r
88 +    char from_buf[6]; /* From space NULL */\r
89 +    int is_mbox = 0;\r
90  \r
91      root = talloc_zero (ctx, mime_node_t);\r
92      if (root == NULL) {\r
93 @@ -96,6 +98,23 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
94         goto DONE;\r
95      }\r
96  \r
97 +    if (fread (from_buf, 1, 5, mctx->file) != 5) {\r
98 +       fprintf (stderr, "Failed to read 5 bytes from %s: %s\n",\r
99 +                filename, strerror (errno));\r
100 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
101 +       goto DONE;\r
102 +    }\r
103 +    from_buf[5] = '\0';\r
104 +\r
105 +    if (fseek (mctx->file, 0L, SEEK_SET)) {\r
106 +       fprintf (stderr, "Failed to rewind %s: %s\n",\r
107 +                filename, strerror (errno));\r
108 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
109 +       goto DONE;\r
110 +    }\r
111 +\r
112 +    is_mbox = (strcmp (from_buf, "From ") == 0);\r
113 +\r
114      mctx->stream = g_mime_stream_file_new (mctx->file);\r
115      if (!mctx->stream) {\r
116         fprintf (stderr, "Out of memory.\n");\r
117 @@ -111,7 +130,9 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
118         goto DONE;\r
119      }\r
120  \r
121 +    g_mime_parser_set_scan_from (mctx->parser, is_mbox);\r
122      mctx->mime_message = g_mime_parser_construct_message (mctx->parser);\r
123 +\r
124      if (!mctx->mime_message) {\r
125         fprintf (stderr, "Failed to parse %s\n", filename);\r
126         status = NOTMUCH_STATUS_FILE_ERROR;\r
127 -- \r
128 1.7.9.1\r
129 \r