changeset: 7110:a533c22715c8
user:      Kevin McCarthy <ke...@8t8.us>
date:      Thu Jul 20 17:30:05 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/a533c22715c8

When guessing an attachment type, don't allow text/plain if there is a null 
character. (see #2933)

Type text/plain should not contain any null characters.  Slightly
improve the type guesser by forcing an attachment with any null
characters to be application/octet-stream.

Note the type guesser could use much more improvement, but this is an
easy and obvious fix.

diffs (60 lines):

diff -r 2204d7ed4d94 -r a533c22715c8 mutt.h
--- a/mutt.h    Wed Jul 19 14:12:01 2017 -0700
+++ b/mutt.h    Thu Jul 20 17:30:05 2017 -0700
@@ -651,6 +651,7 @@
 {
   long hibin;              /* 8-bit characters */
   long lobin;              /* unprintable 7-bit chars (eg., control chars) */
+  long nulbin;             /* null characters (0x0) */
   long crlf;              /* '\r' and '\n' characters */
   long ascii;              /* number of ascii chars */
   long linemax;            /* length of the longest line in the file */
diff -r 2204d7ed4d94 -r a533c22715c8 sendlib.c
--- a/sendlib.c Wed Jul 19 14:12:01 2017 -0700
+++ b/sendlib.c Thu Jul 20 17:30:05 2017 -0700
@@ -572,6 +572,11 @@
       info->ascii++;
       whitespace++;
     }
+    else if (ch == 0)
+    {
+      info->nulbin++;
+      info->lobin++;
+    }
     else if (ch < 32 || ch == 127)
       info->lobin++;
     else
@@ -1362,23 +1367,8 @@
   /* Attempt to determine the appropriate content-type based on the filename
    * suffix.
    */
-
-#if 0
-
-  if ((n = mutt_lookup_mime_type (buf, sizeof (buf), xbuf, sizeof (xbuf), 
path)) != TYPEOTHER
-      || *xbuf != '\0')
-  {
-    att->type = n;
-    att->subtype = safe_strdup (buf);
-    att->xtype = safe_strdup (xbuf);
-  }
-
-#else
-
   mutt_lookup_mime_type (att, path);
 
-#endif
-
   if ((info = mutt_get_content_info (path, att)) == NULL)
   {
     mutt_free_body (&att);
@@ -1387,7 +1377,8 @@
 
   if (!att->subtype)
   {
-    if (info->lobin == 0 || (info->lobin + info->hibin + info->ascii)/ 
info->lobin >= 10)
+    if ((info->nulbin == 0) &&
+        (info->lobin == 0 || (info->lobin + info->hibin + info->ascii)/ 
info->lobin >= 10))
     {
       /*
        * Statistically speaking, there should be more than 10% "lobin"

Reply via email to