On Sat, Jan 14, 2017 at 07:22:21PM -0800, Brendan Cully wrote: > changeset: 6903:945a3f4b15c7 > user: David Champion <[email protected]> > date: Sat Jan 14 19:18:45 2017 -0800 > link: http://dev.mutt.org/hg/mutt/rev/945a3f4b15c7 > > Allow initial blank lines in local mailboxes. > > 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. > > diffs (18 lines): > > diff -r 79306170e367 -r 945a3f4b15c7 mx.c > --- a/mx.c Tue Jan 10 14:48:08 2017 -0800 > +++ b/mx.c Sat Jan 14 19:18:45 2017 -0800 > @@ -423,6 +423,14 @@ > else if ((f = fopen (path, "r")) != NULL) > { > struct utimbuf times; > + int ch = 0;
The first iteration of the while-loop will initialize ch. I would
drop the initialization here as it confused me into thinking the
"&& ch" check in the if below verifies if the loop was run at
least once. But that will be always true.
> + /* 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'));
I'd move the ; to th next line to make it more visible or use
continue, e.g.
while (...)
continue;
> + if (!feof(f) && ch)
ch will be either EOF on error or end-of-file or contain the
first byte. Why the check for != 0 here? This will break if there
was an error during reading and will put EOF (Oxff) into the
stream. ch will only be 0 if there's a NUL-byte in the file which
is unexpected for Mboxes but not a problem with the issue the
comment is talking about.
I think this should be
if (ch != EOF)
> + ungetc(ch, f);
>
> fgets (tmp, sizeof (tmp), f);
But independent from that fgets() should check for possible errors.
> if (mutt_strncmp ("From ", tmp, 5) == 0)
Regards
Simon
--
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9
signature.asc
Description: PGP signature
