]> granicus.if.org Git - mutt/commitdiff
Allow initial blank lines in local mailboxes.
authorDavid Champion <dgc@bikeshed.us>
Sun, 15 Jan 2017 03:18:45 +0000 (19:18 -0800)
committerDavid Champion <dgc@bikeshed.us>
Sun, 15 Jan 2017 03:18:45 +0000 (19:18 -0800)
Some mailbox-creation tools erroneously append a blank line to a file
before appending a UNIXv7-format mail message, resulting in mailboxes
that are intended to be valid "mbox" folders but are not.  Notably old
versions of Mailman do this, making archive files that cannot be read by
mutt.

This patch causes mutt to skip leading NLs and CRs when detecting magic.

mx.c

diff --git a/mx.c b/mx.c
index a961937754711db45d362a0ab604b2423c68e315..8b78a09cd456222e847a6deac6033e08c533fbbd 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -423,6 +423,14 @@ int mx_get_magic (const char *path)
   else if ((f = fopen (path, "r")) != NULL)
   {
     struct utimbuf times;
+    int ch = 0;
+
+    /* Some mailbox creation tools erroneously append a blank line to
+     * a file before appending a mail message.  This allows mutt to
+     * detect magic for and thus open those files. */
+    while ((ch = fgetc(f)) && (ch == '\n' || ch == '\r'));
+    if (!feof(f) && ch)
+      ungetc(ch, f);
 
     fgets (tmp, sizeof (tmp), f);
     if (mutt_strncmp ("From ", tmp, 5) == 0)