Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / a2 / b269d6b3519ecc0cea66f39e39a863333f3582
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 52961431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 10 Mar 2012 05:25:49 -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 Ot5Yw95sqGED for <notmuch@notmuchmail.org>;\r
16         Sat, 10 Mar 2012 05:25:47 -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 2F43F431FAE\r
21         for <notmuch@notmuchmail.org>; Sat, 10 Mar 2012 05:25:47 -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 1S6MIr-0007z7-Lq; Sat, 10 Mar 2012 09:25:46 -0400\r
27 Received: from bremner by zancas.localnet with local (Exim 4.77)\r
28         (envelope-from <bremner@tethera.net>)\r
29         id 1S6MIm-0000Qc-CP; Sat, 10 Mar 2012 09:25:40 -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: Sat, 10 Mar 2012 09:25:31 -0400\r
35 Message-Id: <1331385931-1610-1-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.9.1\r
37 In-Reply-To: <4F5A2DB1.7040301@fifthhorseman.net>\r
38 References: <4F5A2DB1.7040301@fifthhorseman.net>\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: Sat, 10 Mar 2012 13:25:49 -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 This version fixes a few formatting issues, and one bug (the strncmp).\r
78 \r
79  mime-node.c |   24 ++++++++++++++++++++++++\r
80  1 files changed, 24 insertions(+), 0 deletions(-)\r
81 \r
82 diff --git a/mime-node.c b/mime-node.c\r
83 index a95bdab..25e9d11 100644\r
84 --- a/mime-node.c\r
85 +++ b/mime-node.c\r
86 @@ -72,6 +72,8 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
87      mime_node_context_t *mctx;\r
88      mime_node_t *root;\r
89      notmuch_status_t status;\r
90 +    char *first_line = NULL;\r
91 +    size_t first_line_size = 0;\r
92  \r
93      root = talloc_zero (ctx, mime_node_t);\r
94      if (root == NULL) {\r
95 @@ -96,6 +98,23 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
96         goto DONE;\r
97      }\r
98  \r
99 +    if (getline (&first_line, &first_line_size, mctx->file) < 0) {\r
100 +       fprintf (stderr, "Failed to read first line from %s: %s\n",\r
101 +                filename, strerror (errno));\r
102 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
103 +       goto DONE;\r
104 +    }\r
105 +\r
106 +    if (strncmp (first_line, "From ", 5) != 0) {\r
107 +       /* No envelope from line */\r
108 +       if (fseek (mctx->file, 0L, SEEK_SET)) {\r
109 +           fprintf (stderr, "Failed to rewind %s: %s\n",\r
110 +                    filename, strerror (errno));\r
111 +           status = NOTMUCH_STATUS_FILE_ERROR;\r
112 +           goto DONE;\r
113 +       }\r
114 +    }\r
115 +\r
116      mctx->stream = g_mime_stream_file_new (mctx->file);\r
117      if (!mctx->stream) {\r
118         fprintf (stderr, "Out of memory.\n");\r
119 @@ -111,7 +130,9 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
120         goto DONE;\r
121      }\r
122  \r
123 +    g_mime_parser_set_scan_from (mctx->parser, FALSE);\r
124      mctx->mime_message = g_mime_parser_construct_message (mctx->parser);\r
125 +\r
126      if (!mctx->mime_message) {\r
127         fprintf (stderr, "Failed to parse %s\n", filename);\r
128         status = NOTMUCH_STATUS_FILE_ERROR;\r
129 @@ -136,6 +157,9 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
130      return NOTMUCH_STATUS_SUCCESS;\r
131  \r
132  DONE:\r
133 +    if (first_line != NULL)\r
134 +       free (first_line);\r
135 +\r
136      talloc_free (root);\r
137      return status;\r
138  }\r
139 -- \r
140 1.7.9.1\r
141 \r