Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / e6 / ef5f39490ed0502b031b044252b4de0b7ebdc5
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 99CE6431FB6\r
6         for <notmuch@notmuchmail.org>; Fri,  9 Mar 2012 05:56:37 -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 CY6UqosvXWQ7 for <notmuch@notmuchmail.org>;\r
16         Fri,  9 Mar 2012 05:56:37 -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 F3179431FAE\r
21         for <notmuch@notmuchmail.org>; Fri,  9 Mar 2012 05:56:36 -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 1S60J9-00079K-Ul; Fri, 09 Mar 2012 09:56:36 -0400\r
27 Received: from bremner by zancas.localnet with local (Exim 4.77)\r
28         (envelope-from <bremner@tethera.net>)\r
29         id 1S60J4-00069f-L9; Fri, 09 Mar 2012 09:56:30 -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:56:26 -0400\r
35 Message-Id: <1331301387-23630-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:56:37 -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 |   24 ++++++++++++++++++++++++\r
78  1 files changed, 24 insertions(+), 0 deletions(-)\r
79 \r
80 diff --git a/mime-node.c b/mime-node.c\r
81 index a95bdab..cf84423 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 *first_line=NULL;\r
89 +    size_t first_line_size=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 (getline(&first_line, &first_line_size, mctx->file) < 0) {\r
98 +       fprintf (stderr, "Failed to read first line from %s: %s\n",\r
99 +                filename, strerror (errno));\r
100 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
101 +       goto DONE;\r
102 +    }\r
103 +\r
104 +    if (strcmp (first_line, "From ") != 0) {\r
105 +       /* No envelope from line */\r
106 +       if (fseek (mctx->file, 0L, SEEK_SET)) {\r
107 +           fprintf (stderr, "Failed to rewind %s: %s\n",\r
108 +                    filename, strerror (errno));\r
109 +           status = NOTMUCH_STATUS_FILE_ERROR;\r
110 +           goto DONE;\r
111 +       }\r
112 +    }\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, FALSE);\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 @@ -136,6 +157,9 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
128      return NOTMUCH_STATUS_SUCCESS;\r
129  \r
130  DONE:\r
131 +    if (first_line != NULL)\r
132 +       free (first_line);\r
133 +\r
134      talloc_free (root);\r
135      return status;\r
136  }\r
137 -- \r
138 1.7.9.1\r
139 \r