[PATCH] Don't bother checking for mbox files

Subject: [PATCH] Don't bother checking for mbox files

Date: Wed, 09 Mar 2016 16:08:17 -0800

To: notmuch@notmuchmail.org

Cc:

From: Keith Packard


Postfix adds mbox-style From lines when used in combination with
maildrop or .forward files. If they have another line starting with
'From ' in them, notmuch complains about them not being mail files.

If we assume the user hasn't screwed up and misconfigured their mail
system, then we can safely ignore whether the file started with an
mbox header and just parse it as a single-message file.

I can't see any harm in doing this; in the worst case, you'll have a
single 'message' which contains multiple emails now, while the
alternative is to miss mail entirely.

I could be convinced to add a config option to enable this behaviour,
but I'd really rather not.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 lib/message-file.c | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)

diff --git a/lib/message-file.c b/lib/message-file.c
index ee30520..f03e1db 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -98,22 +98,6 @@ _notmuch_message_file_close (notmuch_message_file_t *message)
     talloc_free (message);
 }
 
-static notmuch_bool_t
-_is_mbox (FILE *file)
-{
-    char from_buf[5];
-    notmuch_bool_t ret = FALSE;
-
-    /* Is this mbox? */
-    if (fread (from_buf, sizeof (from_buf), 1, file) == 1 &&
-	strncmp (from_buf, "From ", 5) == 0)
-	ret = TRUE;
-
-    rewind (file);
-
-    return ret;
-}
-
 notmuch_status_t
 _notmuch_message_file_parse (notmuch_message_file_t *message)
 {
@@ -121,13 +105,10 @@ _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;
 
-    is_mbox = _is_mbox (message->file);
-
     if (! initialized) {
 	g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS);
 	initialized = 1;
@@ -144,7 +125,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, is_mbox);
+    g_mime_parser_set_scan_from (parser, FALSE);
 
     message->message = g_mime_parser_construct_message (parser);
     if (! message->message) {
@@ -152,14 +133,6 @@ _notmuch_message_file_parse (notmuch_message_file_t *message)
 	goto DONE;
     }
 
-    if (is_mbox && ! g_mime_parser_eos (parser)) {
-	/*
-	 * This is a multi-message mbox. (For historical reasons, we
-	 * do support single-message mboxes.)
-	 */
-	status = NOTMUCH_STATUS_FILE_NOT_EMAIL;
-    }
-
   DONE:
     g_object_unref (stream);
     g_object_unref (parser);
-- 
2.7.0


-- 
-keith
signature.asc (application/pgp-signature)

Thread: