X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Findex.cc;h=da0e6cebd7c327ee3fdb35ffdf15110f89ce2fc0;hp=e377732220effdcb537934bf6036d01528829db3;hb=5505d55515594025fe319c5150fdb360b0ffcd60;hpb=40edc971a82e236704216058591d4c7684f8058f diff --git a/lib/index.cc b/lib/index.cc index e3777322..da0e6ceb 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -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);