changeset: 6904:ac1a2af3aff4
user: Kevin McCarthy <[email protected]>
date: Sun Jan 15 10:00:55 2017 -0800
link: http://dev.mutt.org/hg/mutt/rev/ac1a2af3aff4
Improve error handling in mbox magic detection.
Thanks to Simon Ruderich for pointing out several small issues with
the previous commit.
diffs (40 lines):
diff -r 945a3f4b15c7 -r ac1a2af3aff4 mx.c
--- a/mx.c Sat Jan 14 19:18:45 2017 -0800
+++ b/mx.c Sun Jan 15 10:00:55 2017 -0800
@@ -423,20 +423,27 @@
else if ((f = fopen (path, "r")) != NULL)
{
struct utimbuf times;
- int ch = 0;
+ int ch;
/* 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);
+ while ((ch = fgetc (f)) != EOF)
+ {
+ if (ch != '\n' && ch != '\r')
+ {
+ ungetc (ch, f);
+ break;
+ }
+ }
- fgets (tmp, sizeof (tmp), f);
- if (mutt_strncmp ("From ", tmp, 5) == 0)
- magic = MUTT_MBOX;
- else if (mutt_strcmp (MMDF_SEP, tmp) == 0)
- magic = MUTT_MMDF;
+ if (fgets (tmp, sizeof (tmp), f))
+ {
+ if (mutt_strncmp ("From ", tmp, 5) == 0)
+ magic = MUTT_MBOX;
+ else if (mutt_strcmp (MMDF_SEP, tmp) == 0)
+ magic = MUTT_MMDF;
+ }
safe_fclose (&f);
if (!option(OPTCHECKMBOXSIZE))