]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Reject multi-message mboxes and deprecate single-message mbox
authorAustin Clements <amdragon@MIT.EDU>
Sun, 25 Nov 2012 06:16:01 +0000 (01:16 -0500)
committerDavid Bremner <bremner@debian.org>
Tue, 27 Nov 2012 01:12:10 +0000 (21:12 -0400)
Previously, we would treat multi-message mboxes as one giant email,
which, besides the obvious incorrect indexing, often led to
out-of-memory errors for archival mboxes.  Now we explicitly reject
multi-message mboxes.  For historical reasons, we retain support for
single-message mboxes, but official deprecate this behavior.

lib/database.cc
lib/index.cc
test/new

index 4df321738f1a5fe25e6f0e048fbcb909bb16f0bf..91d43298f3795a30aa833196c2f196e49382d671 100644 (file)
@@ -1821,7 +1821,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
            date = notmuch_message_file_get_header (message_file, "date");
            _notmuch_message_set_header_values (message, date, from, subject);
 
-           _notmuch_message_index_file (message, filename);
+           ret = _notmuch_message_index_file (message, filename);
+           if (ret)
+               goto DONE;
        } else {
            ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
        }
index e377732220effdcb537934bf6036d01528829db3..da0e6cebd7c327ee3fdb35ffdf15110f89ce2fc0 100644 (file)
@@ -435,6 +435,9 @@ _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];
+    bool is_mbox = false;
+    static bool mbox_warning = false;
 
     if (! initialized) {
        g_mime_init (0);
@@ -448,13 +451,38 @@ _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)
+       is_mbox = true;
+    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, is_mbox);
 
     mime_message = g_mime_parser_construct_message (parser);
 
+    if (is_mbox) {
+       if (!g_mime_parser_eos (parser)) {
+           /* This is a multi-message mbox. */
+           ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;
+           goto DONE;
+       }
+       /* For historical reasons, we support single-message mboxes,
+        * but this behavior is likely to change in the future, so
+        * warn. */
+       if (!mbox_warning) {
+           mbox_warning = true;
+           fprintf (stderr, "\
+Warning: %s is an mbox containing a single message,\n\
+likely caused by misconfigured mail delivery.  Support for single-message\n\
+mboxes is deprecated and may be removed in the future.\n", filename);
+       }
+    }
+
     from = g_mime_message_get_sender (mime_message);
     addresses = internet_address_list_parse_string (from);
 
index 29f9affc20c616f33c07470da0009a02c93de9be..f562cec1239e504a1a2f8c28b6999ba42b36e0ee 100755 (executable)
--- a/test/new
+++ b/test/new
@@ -163,7 +163,7 @@ rm -rf "${MAIL_DIR}"/two
 output=$(NOTMUCH_NEW)
 test_expect_equal "$output" "No new mail. Removed 3 messages."
 
-test_begin_subtest "Support single-message mbox"
+test_begin_subtest "Support single-message mbox (deprecated)"
 cat > "${MAIL_DIR}"/mbox_file1 <<EOF
 From test_suite@notmuchmail.org Fri Jan  5 15:43:57 2001
 From: Notmuch Test Suite <test_suite@notmuchmail.org>
@@ -174,11 +174,13 @@ Body.
 EOF
 output=$(NOTMUCH_NEW 2>&1)
 test_expect_equal "$output" \
-"Added 1 new message to the database."
+"Warning: ${MAIL_DIR}/mbox_file1 is an mbox containing a single message,
+likely caused by misconfigured mail delivery.  Support for single-message
+mboxes is deprecated and may be removed in the future.
+Added 1 new message to the database."
 
 # This test requires that notmuch new has been run at least once.
 test_begin_subtest "Skip and report non-mail files"
-test_subtest_known_broken
 generate_message
 mkdir -p "${MAIL_DIR}"/.git && touch "${MAIL_DIR}"/.git/config
 touch "${MAIL_DIR}"/ignored_file