X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Findex.cc;h=e1e2a3828f024988d59b8d28d9524a4a0ba99f28;hb=827a69f639b91de2503c7dfc0bdd74b6e17f501d;hp=e377732220effdcb537934bf6036d01528829db3;hpb=40edc971a82e236704216058591d4c7684f8058f;p=notmuch diff --git a/lib/index.cc b/lib/index.cc index e3777322..e1e2a382 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -425,58 +425,36 @@ _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; + notmuch_status_t status; - if (! initialized) { - g_mime_init (0); - 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; - } - - /* 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); - - 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); - addresses = internet_address_list_parse_string (from); - _index_address_list (message, "from", addresses); + addresses = internet_address_list_parse_string (from); + if (addresses) { + _index_address_list (message, "from", addresses); + g_object_unref (addresses); + } addresses = g_mime_message_get_all_recipients (mime_message); - _index_address_list (message, "to", addresses); + if (addresses) { + _index_address_list (message, "to", addresses); + g_object_unref (addresses); + } subject = g_mime_message_get_subject (mime_message); _notmuch_message_gen_terms (message, "subject", subject); _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; }