diff options
author | Jani Nikula <jani@nikula.org> | 2014-03-31 00:21:49 +0300 |
---|---|---|
committer | David Bremner <david@tethera.net> | 2014-04-05 12:53:04 -0300 |
commit | 473930bb6fb167078a9428ad85f53accf7d4559f (patch) | |
tree | 4cdf734de80569e918ff29116a0419f2ab66f4b4 /lib/index.cc | |
parent | 6812136bf576d894591606d9e10096719054d1f9 (diff) |
lib: replace the header parser with gmime
The notmuch library includes a full blown message header parser. Yet
the same message headers are parsed by gmime during indexing. Switch
to gmime parsing completely.
These are the main changes:
* Gmime stops header parsing at the first invalid header, and presumes
the message body starts from there. The current parser is quite
liberal in accepting broken headers. The change means we will be
much pickier about accepting invalid messages.
* The current parser converts tabs used in header folding to
spaces. Gmime preserve the tabs. Due to a broken python library used
in mailman, there are plenty of mailing lists that produce headers
with tabs in header folding, and we'll see plenty of tabs. (This
change has been mitigated in preparatory patches.)
* For pure header parsing, the current parser is likely faster than
gmime, which parses the whole message rather than just the
headers. Since we parse the message and its headers using gmime for
indexing anyway, this avoids and extra header parsing round when
adding new messages. In case of duplicate messages, we'll end up
parsing the full message although just headers would be
sufficient. All in all this should still speed up 'notmuch new'.
* Calls to notmuch_message_get_header() may be slightly slower than
previously for headers that are not indexed in the database, due to
parsing of the whole message. Within the notmuch code base, notmuch
reply is the only such user.
Diffstat (limited to 'lib/index.cc')
-rw-r--r-- | lib/index.cc | 54 |
1 files changed, 8 insertions, 46 deletions
diff --git a/lib/index.cc b/lib/index.cc index 2100cce0..e1e2a382 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -425,45 +425,17 @@ _index_mime_part (notmuch_message_t *message, notmuch_status_t _notmuch_message_index_file (notmuch_message_t *message, - const char *filename) + notmuch_message_file_t *message_file) { - GMimeStream *stream = NULL; - GMimeParser *parser = NULL; - GMimeMessage *mime_message = NULL; + GMimeMessage *mime_message; InternetAddressList *addresses; - FILE *file = NULL; const char *from, *subject; - notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; - static int initialized = 0; - char from_buf[5]; + notmuch_status_t status; - if (! initialized) { - g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS); - initialized = 1; - } - - file = fopen (filename, "r"); - if (! file) { - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno)); - ret = NOTMUCH_STATUS_FILE_ERROR; - goto DONE; - } - - /* Is this mbox? */ - if (fread (from_buf, sizeof (from_buf), 1, file) == 1 && - strncmp (from_buf, "From ", 5) == 0) { - ret = NOTMUCH_STATUS_FILE_NOT_EMAIL; - goto DONE; - } - rewind (file); - - /* Evil GMime steals my FILE* here so I won't fclose it. */ - stream = g_mime_stream_file_new (file); - - parser = g_mime_parser_new_with_stream (stream); - g_mime_parser_set_scan_from (parser, FALSE); - - mime_message = g_mime_parser_construct_message (parser); + status = _notmuch_message_file_get_mime_message (message_file, + &mime_message); + if (status) + return status; from = g_mime_message_get_sender (mime_message); @@ -484,15 +456,5 @@ _notmuch_message_index_file (notmuch_message_t *message, _index_mime_part (message, g_mime_message_get_mime_part (mime_message)); - DONE: - if (mime_message) - g_object_unref (mime_message); - - if (parser) - g_object_unref (parser); - - if (stream) - g_object_unref (stream); - - return ret; + return NOTMUCH_STATUS_SUCCESS; } |