Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 30 / 25243821de7aa244e362a041a5ca6520643e1a
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 F24E6431FBC\r
6         for <notmuch@notmuchmail.org>; Thu,  8 Mar 2012 13:48:28 -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 nq504gGFks6h for <notmuch@notmuchmail.org>;\r
16         Thu,  8 Mar 2012 13:48:27 -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 42BE1431FAE\r
21         for <notmuch@notmuchmail.org>; Thu,  8 Mar 2012 13:48:27 -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 1S5lCC-0006Qd-SI; Thu, 08 Mar 2012 17:48:25 -0400\r
27 Received: from bremner by zancas.localnet with local (Exim 4.77)\r
28         (envelope-from <bremner@tethera.net>)\r
29         id 1S5lC7-00077J-AF; Thu, 08 Mar 2012 17:48:19 -0400\r
30 From: David Bremner <david@tethera.net>\r
31 To: notmuch@notmuchmail.org\r
32 Subject: [PATCH] mime_node_open: check if the file is in mbox format,\r
33         and inform gmime.\r
34 Date: Thu,  8 Mar 2012 17:48:15 -0400\r
35 Message-Id: <1331243295-27324-1-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.9.1\r
37 In-Reply-To: <87vcme3kf6.fsf@pip.fifthhorseman.net>\r
38 References: <87vcme3kf6.fsf@pip.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: Thu, 08 Mar 2012 21:48:29 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 It seems that it has always been an error to try to parse an mbox\r
58 format file with gmime without calling g_mime_parser_set_scan_from.\r
59 \r
60 This change reads the first 5 bytes of the file, and if they are "From ",\r
61 declares the file to be an mbox.\r
62 ---\r
63 \r
64 This patch seems to fix the problem for me. I don't think the\r
65 performance impact should be too bad, but I didn't really test it.\r
66 \r
67  mime-node.c |   21 +++++++++++++++++++++\r
68  1 files changed, 21 insertions(+), 0 deletions(-)\r
69 \r
70 diff --git a/mime-node.c b/mime-node.c\r
71 index a95bdab..8939147 100644\r
72 --- a/mime-node.c\r
73 +++ b/mime-node.c\r
74 @@ -72,6 +72,8 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
75      mime_node_context_t *mctx;\r
76      mime_node_t *root;\r
77      notmuch_status_t status;\r
78 +    char from_buf[6]; /* From space NULL */\r
79 +    int is_mbox = 0;\r
80  \r
81      root = talloc_zero (ctx, mime_node_t);\r
82      if (root == NULL) {\r
83 @@ -96,6 +98,23 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
84         goto DONE;\r
85      }\r
86  \r
87 +    if (fread (from_buf, 1, 5, mctx->file) != 5) {\r
88 +       fprintf (stderr, "Failed to read 5 bytes from %s: %s\n",\r
89 +                filename, strerror (errno));\r
90 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
91 +       goto DONE;\r
92 +    }\r
93 +    from_buf[5] = '\0';\r
94 +\r
95 +    if (fseek (mctx->file, 0L, SEEK_SET)) {\r
96 +       fprintf (stderr, "Failed to rewind %s: %s\n",\r
97 +                filename, strerror (errno));\r
98 +       status = NOTMUCH_STATUS_FILE_ERROR;\r
99 +       goto DONE;\r
100 +    }\r
101 +\r
102 +    is_mbox = (strcmp (from_buf, "From ") == 0);\r
103 +\r
104      mctx->stream = g_mime_stream_file_new (mctx->file);\r
105      if (!mctx->stream) {\r
106         fprintf (stderr, "Out of memory.\n");\r
107 @@ -111,7 +130,9 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
108         goto DONE;\r
109      }\r
110  \r
111 +    g_mime_parser_set_scan_from (mctx->parser, is_mbox);\r
112      mctx->mime_message = g_mime_parser_construct_message (mctx->parser);\r
113 +\r
114      if (!mctx->mime_message) {\r
115         fprintf (stderr, "Failed to parse %s\n", filename);\r
116         status = NOTMUCH_STATUS_FILE_ERROR;\r
117 -- \r
118 1.7.9.1\r
119 \r