Re: [PATCH v4 04/16] Provide _notmuch_crypto_{set,get}_gpg_path
[notmuch-archives.git] / 79 / 73fe9c58986740e9416ca4fe40f2c09729e153
1 Return-Path: <jani@nikula.org>\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 84A8C431FBC\r
6         for <notmuch@notmuchmail.org>; Sat, 30 Nov 2013 07:34:33 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id 1fT0U0XOyEFh for <notmuch@notmuchmail.org>;\r
17         Sat, 30 Nov 2013 07:34:28 -0800 (PST)\r
18 Received: from mail-ea0-f169.google.com (mail-ea0-f169.google.com\r
19         [209.85.215.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 942F6431FD9\r
22         for <notmuch@notmuchmail.org>; Sat, 30 Nov 2013 07:34:15 -0800 (PST)\r
23 Received: by mail-ea0-f169.google.com with SMTP id l9so7787649eaj.28\r
24         for <notmuch@notmuchmail.org>; Sat, 30 Nov 2013 07:34:14 -0800 (PST)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=1e100.net; s=20130820;\r
27         h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
28         :references:in-reply-to:references;\r
29         bh=ThStNBfWxPAsiQcOkE7qqDnegjbWfHa/WVixrzqyFXQ=;\r
30         b=hcrATJSawqQa3x9zqatur70fCH4dEh4vOGp7nOucGvH8cxWYGFke4H9fqenC5p4Afb\r
31         hdiLysHHBETB4qPOg+FPyXUzznfUcVxRUEoE4NTsisuzqOWnuc2JF4PwB5ZxlYJbzJSc\r
32         FuhdtwVpzBn+0QeXwBWVel2DfVb5YGireubapnJApqBmhzz9Azukkji1vgJXaX4x2FGO\r
33         x5gMxpL1D2mc/oCrn2ceHa5SOJzY5m3A6aQ9X1cfuOhSeKao4vvrh/6vLeRPLY88OAZQ\r
34         4NmBAS5Zrcwqc/vevaIMpipX6nFBoCDjCVKAcA6EcrQ3UVFzoh/NDbn3Bb1cmS2kHv3+\r
35         H04g==\r
36 X-Gm-Message-State:\r
37  ALoCoQlF/mz7/8ygFnuTxLHfIBGlA239gzkxRbOpMrDuFemeGVlRnm8vIgndpsVAnmUVPrL9DNdY\r
38 X-Received: by 10.15.86.75 with SMTP id h51mr1603384eez.44.1385825654569;\r
39         Sat, 30 Nov 2013 07:34:14 -0800 (PST)\r
40 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
41         [88.195.111.91])\r
42         by mx.google.com with ESMTPSA id a45sm51848238eem.6.2013.11.30.07.34.13\r
43         for <multiple recipients>\r
44         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
45         Sat, 30 Nov 2013 07:34:14 -0800 (PST)\r
46 From: Jani Nikula <jani@nikula.org>\r
47 To: notmuch@notmuchmail.org\r
48 Subject: [PATCH v2 6/7] lib: parse messages only once\r
49 Date: Sat, 30 Nov 2013 17:33:55 +0200\r
50 Message-Id:\r
51  <36ef439cffa92d7889a5b1ae984016d3e944edc1.1385825425.git.jani@nikula.org>\r
52 X-Mailer: git-send-email 1.8.4.2\r
53 In-Reply-To: <cover.1385825425.git.jani@nikula.org>\r
54 References: <cover.1385825425.git.jani@nikula.org>\r
55 In-Reply-To: <cover.1385825425.git.jani@nikula.org>\r
56 References: <cover.1385825425.git.jani@nikula.org>\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Sat, 30 Nov 2013 15:34:33 -0000\r
70 \r
71 Make the necessary changes to only do one gmime parse pass during\r
72 indexing.\r
73 ---\r
74  lib/database.cc       |  2 +-\r
75  lib/index.cc          | 59 ++++++---------------------------------------------\r
76  lib/message-file.c    |  9 ++++++++\r
77  lib/notmuch-private.h | 16 ++++++++++++--\r
78  4 files changed, 30 insertions(+), 56 deletions(-)\r
79 \r
80 diff --git a/lib/database.cc b/lib/database.cc\r
81 index d1bea88..3a29fe7 100644\r
82 --- a/lib/database.cc\r
83 +++ b/lib/database.cc\r
84 @@ -2029,7 +2029,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
85             date = notmuch_message_file_get_header (message_file, "date");\r
86             _notmuch_message_set_header_values (message, date, from, subject);\r
87  \r
88 -           ret = _notmuch_message_index_file (message, filename);\r
89 +           ret = _notmuch_message_index_file (message, message_file);\r
90             if (ret)\r
91                 goto DONE;\r
92         } else {\r
93 diff --git a/lib/index.cc b/lib/index.cc\r
94 index 976e49f..71397da 100644\r
95 --- a/lib/index.cc\r
96 +++ b/lib/index.cc\r
97 @@ -425,52 +425,15 @@ _index_mime_part (notmuch_message_t *message,\r
98  \r
99  notmuch_status_t\r
100  _notmuch_message_index_file (notmuch_message_t *message,\r
101 -                            const char *filename)\r
102 +                            notmuch_message_file_t *message_file)\r
103  {\r
104 -    GMimeStream *stream = NULL;\r
105 -    GMimeParser *parser = NULL;\r
106 -    GMimeMessage *mime_message = NULL;\r
107 +    GMimeMessage *mime_message;\r
108      InternetAddressList *addresses;\r
109 -    FILE *file = NULL;\r
110      const char *from, *subject;\r
111 -    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
112 -    static int initialized = 0;\r
113 -    char from_buf[5];\r
114 -    bool is_mbox = false;\r
115 -\r
116 -    if (! initialized) {\r
117 -       g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS);\r
118 -       initialized = 1;\r
119 -    }\r
120 -\r
121 -    file = fopen (filename, "r");\r
122 -    if (! file) {\r
123 -       fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));\r
124 -       ret = NOTMUCH_STATUS_FILE_ERROR;\r
125 -       goto DONE;\r
126 -    }\r
127 -\r
128 -    /* Is this mbox? */\r
129 -    if (fread (from_buf, sizeof (from_buf), 1, file) == 1 &&\r
130 -       strncmp (from_buf, "From ", 5) == 0)\r
131 -       is_mbox = true;\r
132 -    rewind (file);\r
133 -\r
134 -    /* Evil GMime steals my FILE* here so I won't fclose it. */\r
135 -    stream = g_mime_stream_file_new (file);\r
136 -\r
137 -    parser = g_mime_parser_new_with_stream (stream);\r
138 -    g_mime_parser_set_scan_from (parser, is_mbox);\r
139  \r
140 -    mime_message = g_mime_parser_construct_message (parser);\r
141 -\r
142 -    if (is_mbox) {\r
143 -       if (!g_mime_parser_eos (parser)) {\r
144 -           /* This is a multi-message mbox. */\r
145 -           ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;\r
146 -           goto DONE;\r
147 -       }\r
148 -    }\r
149 +    mime_message = notmuch_message_file_get_mime_message (message_file);\r
150 +    if (! mime_message)\r
151 +       return NOTMUCH_STATUS_FILE_NOT_EMAIL; /* more like internal error */\r
152  \r
153      from = g_mime_message_get_sender (mime_message);\r
154  \r
155 @@ -491,15 +454,5 @@ _notmuch_message_index_file (notmuch_message_t *message,\r
156  \r
157      _index_mime_part (message, g_mime_message_get_mime_part (mime_message));\r
158  \r
159 -  DONE:\r
160 -    if (mime_message)\r
161 -       g_object_unref (mime_message);\r
162 -\r
163 -    if (parser)\r
164 -       g_object_unref (parser);\r
165 -\r
166 -    if (stream)\r
167 -       g_object_unref (stream);\r
168 -\r
169 -    return ret;\r
170 +    return NOTMUCH_STATUS_SUCCESS;\r
171  }\r
172 diff --git a/lib/message-file.c b/lib/message-file.c\r
173 index 3c653d1..0bd8c2e 100644\r
174 --- a/lib/message-file.c\r
175 +++ b/lib/message-file.c\r
176 @@ -247,6 +247,15 @@ mboxes is deprecated and may be removed in the future.\n", message->filename);\r
177      return NOTMUCH_STATUS_SUCCESS;\r
178  }\r
179  \r
180 +GMimeMessage *\r
181 +notmuch_message_file_get_mime_message (notmuch_message_file_t *message)\r
182 +{\r
183 +    if (! message->parsed)\r
184 +       return NULL;\r
185 +\r
186 +    return message->message;\r
187 +}\r
188 +\r
189  /* return NULL on errors, empty string for non-existing headers */\r
190  const char *\r
191  notmuch_message_file_get_header (notmuch_message_file_t *message,\r
192 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
193 index 7277df1..7559521 100644\r
194 --- a/lib/notmuch-private.h\r
195 +++ b/lib/notmuch-private.h\r
196 @@ -46,6 +46,8 @@ NOTMUCH_BEGIN_DECLS\r
197  \r
198  #include <talloc.h>\r
199  \r
200 +#include <gmime/gmime.h>\r
201 +\r
202  #include "xutil.h"\r
203  #include "error_util.h"\r
204  \r
205 @@ -320,9 +322,11 @@ notmuch_message_get_author (notmuch_message_t *message);\r
206  \r
207  /* index.cc */\r
208  \r
209 +typedef struct _notmuch_message_file notmuch_message_file_t;\r
210 +\r
211  notmuch_status_t\r
212  _notmuch_message_index_file (notmuch_message_t *message,\r
213 -                            const char *filename);\r
214 +                            notmuch_message_file_t *message_file);\r
215  \r
216  /* message-file.c */\r
217  \r
218 @@ -330,7 +334,6 @@ _notmuch_message_index_file (notmuch_message_t *message,\r
219   * into the public interface in notmuch.h\r
220   */\r
221  \r
222 -typedef struct _notmuch_message_file notmuch_message_file_t;\r
223  \r
224  /* Open a file containing a single email message.\r
225   *\r
226 @@ -377,6 +380,15 @@ void\r
227  notmuch_message_file_restrict_headersv (notmuch_message_file_t *message,\r
228                                         va_list va_headers);\r
229  \r
230 +/* Get the gmime message of a parsed message file.\r
231 + *\r
232 + * Returns NULL if the message file has not been parsed.\r
233 + *\r
234 + * XXX: Would be nice to not have to expose GMimeMessage here.\r
235 + */\r
236 +GMimeMessage *\r
237 +notmuch_message_file_get_mime_message (notmuch_message_file_t *message);\r
238 +\r
239  /* Get the value of the specified header from the message as a UTF-8 string.\r
240   *\r
241   * The header name is case insensitive.\r
242 -- \r
243 1.8.4.2\r
244 \r