X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fmessage-file.c;h=eda1b748e2022d73d2d8737f04151f342e0787ad;hb=3c1ad5bfa0039191f1202b0542eb3af7afd16c5c;hp=67828827e61d5a065b16e527013024c41b2abea4;hpb=473930bb6fb167078a9428ad85f53accf7d4559f;p=notmuch diff --git a/lib/message-file.c b/lib/message-file.c index 67828827..eda1b748 100644 --- a/lib/message-file.c +++ b/lib/message-file.c @@ -99,25 +99,25 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename) FAIL: fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno)); - notmuch_message_file_close (message); + _notmuch_message_file_close (message); return NULL; } notmuch_message_file_t * -notmuch_message_file_open (const char *filename) +_notmuch_message_file_open (const char *filename) { return _notmuch_message_file_open_ctx (NULL, filename); } void -notmuch_message_file_close (notmuch_message_file_t *message) +_notmuch_message_file_close (notmuch_message_file_t *message) { talloc_free (message); } static notmuch_bool_t -is_mbox (FILE *file) +_is_mbox (FILE *file) { char from_buf[5]; notmuch_bool_t ret = FALSE; @@ -139,13 +139,12 @@ _notmuch_message_file_parse (notmuch_message_file_t *message) GMimeParser *parser; notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; static int initialized = 0; + notmuch_bool_t is_mbox; if (message->message) return NOTMUCH_STATUS_SUCCESS; - /* We no longer support mboxes at all. */ - if (is_mbox (message->file)) - return NOTMUCH_STATUS_FILE_NOT_EMAIL; + is_mbox = _is_mbox (message->file); if (! initialized) { g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS); @@ -163,7 +162,7 @@ _notmuch_message_file_parse (notmuch_message_file_t *message) g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream), FALSE); parser = g_mime_parser_new_with_stream (stream); - g_mime_parser_set_scan_from (parser, FALSE); + g_mime_parser_set_scan_from (parser, is_mbox); message->message = g_mime_parser_construct_message (parser); if (! message->message) { @@ -171,6 +170,27 @@ _notmuch_message_file_parse (notmuch_message_file_t *message) goto DONE; } + if (is_mbox) { + if (! g_mime_parser_eos (parser)) { + /* This is a multi-message mbox. */ + status = 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. + */ + static notmuch_bool_t mbox_warning = FALSE; + 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", message->filename); + } + } + DONE: g_object_unref (stream); g_object_unref (parser); @@ -277,7 +297,7 @@ _notmuch_message_file_get_combined_header (notmuch_message_file_t *message, } const char * -notmuch_message_file_get_header (notmuch_message_file_t *message, +_notmuch_message_file_get_header (notmuch_message_file_t *message, const char *header) { const char *value;