]> git.notmuchmail.org Git - notmuch/blobdiff - lib/index.cc
lib: drop support for single-message mbox files
[notmuch] / lib / index.cc
index e377732220effdcb537934bf6036d01528829db3..2100cce047803f6acc059553afd32a794bb9257c 100644 (file)
@@ -435,9 +435,10 @@ _notmuch_message_index_file (notmuch_message_t *message,
     const char *from, *subject;
     notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
     static int initialized = 0;
+    char from_buf[5];
 
     if (! initialized) {
-       g_mime_init (0);
+       g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS);
        initialized = 1;
     }
 
@@ -448,20 +449,35 @@ _notmuch_message_index_file (notmuch_message_t *message,
        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);
 
     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);