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 8C793431FAF
\r
6 for <notmuch@notmuchmail.org>; Mon, 3 Feb 2014 11:52:59 -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
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 5e1cKsBHvdZj for <notmuch@notmuchmail.org>;
\r
17 Mon, 3 Feb 2014 11:52:52 -0800 (PST)
\r
18 Received: from mail-ee0-f46.google.com (mail-ee0-f46.google.com
\r
19 [74.125.83.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
20 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
21 1B7B1429E51 for <notmuch@notmuchmail.org>; Mon, 3 Feb 2014 11:52:19 -0800
\r
23 Received: by mail-ee0-f46.google.com with SMTP id c13so3867562eek.33
\r
24 for <notmuch@notmuchmail.org>; Mon, 03 Feb 2014 11:52:19 -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=RmAJ5gFXk/Jopawe+UrzcinIxcV7L25580CaQCkmSzk=;
\r
30 b=JEqZ9VOGWcjCVoPEnpXwV8Zh9xhnMZVQ5khlVcTfG4OxpfaypPhBhnt7LQXAmxyHr+
\r
31 FlCB2ulwWbnkH4SmCHAbrTgUBejP1aGdG5m+Dnf4LUrVknqkyabjeloEnqx1G5Wfp00s
\r
32 svyhUA9dFUZiqlgXdCfwIuJzEGNAX7E+PHzO9svW6wjC+3jU9H2MjVdr0A9r1nfNXAk3
\r
33 3oJdbcR8pat/KEHuMrfPnwRy/HvecNnHCUt53KaavLtewgbe4zPArXLr0WvOIq8I/Yfh
\r
34 wQ5bo1g59mL6ScmxEje2n7XL6r3WpNhM9zxiz79vhXJaPxM4Fm9IzU9x7nakqrEFqCqz
\r
37 ALoCoQmg1Gh4ewsWQKByEZN/mO3d3twMR06eufDJfjycekidSc1BqGjx1cVzGmxaEhrxcbp7W56g
\r
38 X-Received: by 10.15.54.72 with SMTP id s48mr45078878eew.3.1391457138946;
\r
39 Mon, 03 Feb 2014 11:52:18 -0800 (PST)
\r
40 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.
\r
42 by mx.google.com with ESMTPSA id m1sm78834700een.7.2014.02.03.11.52.16
\r
43 for <multiple recipients>
\r
44 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
45 Mon, 03 Feb 2014 11:52:18 -0800 (PST)
\r
46 From: Jani Nikula <jani@nikula.org>
\r
47 To: notmuch@notmuchmail.org
\r
48 Subject: [PATCH v3 6/6] lib: parse messages only once
\r
49 Date: Mon, 3 Feb 2014 21:51:46 +0200
\r
51 <31d785c4a3e4b90862a0fdc545d4e900a4c898e2.1391456555.git.jani@nikula.org>
\r
52 X-Mailer: git-send-email 1.8.5.2
\r
53 In-Reply-To: <cover.1391456555.git.jani@nikula.org>
\r
54 References: <cover.1391456555.git.jani@nikula.org>
\r
55 In-Reply-To: <cover.1391456555.git.jani@nikula.org>
\r
56 References: <cover.1391456555.git.jani@nikula.org>
\r
57 X-BeenThere: notmuch@notmuchmail.org
\r
58 X-Mailman-Version: 2.1.13
\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: Mon, 03 Feb 2014 19:52:59 -0000
\r
71 Use the previously parsed gmime message for indexing instead of
\r
72 running an extra parsing pass.
\r
74 After this change, we'll only do unnecessary parsing of the message
\r
75 body for duplicates and non-messages. For regular non-duplicate
\r
76 messages, we have now shaved off an extra header parsing round during
\r
79 lib/database.cc | 2 +-
\r
80 lib/index.cc | 59 ++++++---------------------------------------------
\r
81 lib/message-file.c | 9 ++++++++
\r
82 lib/notmuch-private.h | 16 ++++++++++++--
\r
83 4 files changed, 30 insertions(+), 56 deletions(-)
\r
85 diff --git a/lib/database.cc b/lib/database.cc
\r
86 index d1bea88..3a29fe7 100644
\r
87 --- a/lib/database.cc
\r
88 +++ b/lib/database.cc
\r
89 @@ -2029,7 +2029,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
90 date = notmuch_message_file_get_header (message_file, "date");
\r
91 _notmuch_message_set_header_values (message, date, from, subject);
\r
93 - ret = _notmuch_message_index_file (message, filename);
\r
94 + ret = _notmuch_message_index_file (message, message_file);
\r
98 diff --git a/lib/index.cc b/lib/index.cc
\r
99 index 976e49f..71397da 100644
\r
102 @@ -425,52 +425,15 @@ _index_mime_part (notmuch_message_t *message,
\r
105 _notmuch_message_index_file (notmuch_message_t *message,
\r
106 - const char *filename)
\r
107 + notmuch_message_file_t *message_file)
\r
109 - GMimeStream *stream = NULL;
\r
110 - GMimeParser *parser = NULL;
\r
111 - GMimeMessage *mime_message = NULL;
\r
112 + GMimeMessage *mime_message;
\r
113 InternetAddressList *addresses;
\r
114 - FILE *file = NULL;
\r
115 const char *from, *subject;
\r
116 - notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
117 - static int initialized = 0;
\r
118 - char from_buf[5];
\r
119 - bool is_mbox = false;
\r
121 - if (! initialized) {
\r
122 - g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS);
\r
126 - file = fopen (filename, "r");
\r
128 - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
\r
129 - ret = NOTMUCH_STATUS_FILE_ERROR;
\r
133 - /* Is this mbox? */
\r
134 - if (fread (from_buf, sizeof (from_buf), 1, file) == 1 &&
\r
135 - strncmp (from_buf, "From ", 5) == 0)
\r
139 - /* Evil GMime steals my FILE* here so I won't fclose it. */
\r
140 - stream = g_mime_stream_file_new (file);
\r
142 - parser = g_mime_parser_new_with_stream (stream);
\r
143 - g_mime_parser_set_scan_from (parser, is_mbox);
\r
145 - mime_message = g_mime_parser_construct_message (parser);
\r
148 - if (!g_mime_parser_eos (parser)) {
\r
149 - /* This is a multi-message mbox. */
\r
150 - ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;
\r
154 + mime_message = notmuch_message_file_get_mime_message (message_file);
\r
155 + if (! mime_message)
\r
156 + return NOTMUCH_STATUS_FILE_NOT_EMAIL; /* more like internal error */
\r
158 from = g_mime_message_get_sender (mime_message);
\r
160 @@ -491,15 +454,5 @@ _notmuch_message_index_file (notmuch_message_t *message,
\r
162 _index_mime_part (message, g_mime_message_get_mime_part (mime_message));
\r
165 - if (mime_message)
\r
166 - g_object_unref (mime_message);
\r
169 - g_object_unref (parser);
\r
172 - g_object_unref (stream);
\r
175 + return NOTMUCH_STATUS_SUCCESS;
\r
177 diff --git a/lib/message-file.c b/lib/message-file.c
\r
178 index 33f6468..99e1dc8 100644
\r
179 --- a/lib/message-file.c
\r
180 +++ b/lib/message-file.c
\r
181 @@ -250,6 +250,15 @@ mboxes is deprecated and may be removed in the future.\n", message->filename);
\r
182 return NOTMUCH_STATUS_SUCCESS;
\r
186 +notmuch_message_file_get_mime_message (notmuch_message_file_t *message)
\r
188 + if (! message->parsed)
\r
191 + return message->message;
\r
194 /* return NULL on errors, empty string for non-existing headers */
\r
196 notmuch_message_file_get_header (notmuch_message_file_t *message,
\r
197 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
198 index 7277df1..7559521 100644
\r
199 --- a/lib/notmuch-private.h
\r
200 +++ b/lib/notmuch-private.h
\r
201 @@ -46,6 +46,8 @@ NOTMUCH_BEGIN_DECLS
\r
203 #include <talloc.h>
\r
205 +#include <gmime/gmime.h>
\r
208 #include "error_util.h"
\r
210 @@ -320,9 +322,11 @@ notmuch_message_get_author (notmuch_message_t *message);
\r
214 +typedef struct _notmuch_message_file notmuch_message_file_t;
\r
217 _notmuch_message_index_file (notmuch_message_t *message,
\r
218 - const char *filename);
\r
219 + notmuch_message_file_t *message_file);
\r
221 /* message-file.c */
\r
223 @@ -330,7 +334,6 @@ _notmuch_message_index_file (notmuch_message_t *message,
\r
224 * into the public interface in notmuch.h
\r
227 -typedef struct _notmuch_message_file notmuch_message_file_t;
\r
229 /* Open a file containing a single email message.
\r
231 @@ -377,6 +380,15 @@ void
\r
232 notmuch_message_file_restrict_headersv (notmuch_message_file_t *message,
\r
233 va_list va_headers);
\r
235 +/* Get the gmime message of a parsed message file.
\r
237 + * Returns NULL if the message file has not been parsed.
\r
239 + * XXX: Would be nice to not have to expose GMimeMessage here.
\r
242 +notmuch_message_file_get_mime_message (notmuch_message_file_t *message);
\r
244 /* Get the value of the specified header from the message as a UTF-8 string.
\r
246 * The header name is case insensitive.
\r