]> granicus.if.org Git - mutt/commitdiff
When guessing an attachment type, don't allow text/plain if there is a null character...
authorKevin McCarthy <kevin@8t8.us>
Fri, 21 Jul 2017 00:30:05 +0000 (17:30 -0700)
committerKevin McCarthy <kevin@8t8.us>
Fri, 21 Jul 2017 00:30:05 +0000 (17:30 -0700)
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.

mutt.h
sendlib.c

diff --git a/mutt.h b/mutt.h
index 50684fc7d30f24811d9afae429e2c140d88b5847..465f70557228704aa5f03b5dfec4ce09eeab92c3 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -651,6 +651,7 @@ typedef struct content
 {
   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 */
index c79800db5a3ae3a8c53ddc1262bd50dabe6bc08b..75d270b2754fae36c96c6d0be81aefd257cb5ff3 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -572,6 +572,11 @@ static void update_content_info (CONTENT *info, CONTENT_STATE *s, char *d, size_
       info->ascii++;
       whitespace++;
     }
+    else if (ch == 0)
+    {
+      info->nulbin++;
+      info->lobin++;
+    }
     else if (ch < 32 || ch == 127)
       info->lobin++;
     else
@@ -1362,23 +1367,8 @@ BODY *mutt_make_file_attach (const char *path)
   /* 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 @@ BODY *mutt_make_file_attach (const char *path)
 
   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"