]> diplodocus.org Git - nmh/blobdiff - uip/sendsbr.c
Make sure scan.curses is installed & distributed.
[nmh] / uip / sendsbr.c
index 96c6b52a46882030def634e4ab581fe93f9fb707..bfd651574288b311a5eeb7f91ca948d2e97b9948 100644 (file)
@@ -613,8 +613,10 @@ mime_type (const char *file_name) {
     if ((int) snprintf (cmd, sizeof cmd, mimetypeproc, file_name) <
         (int) sizeof cmd) {
         if ((fp = popen (cmd, "r")) != NULL) {
-            if (fgets (buf, sizeof cmd, fp)) {
-                char *cp;
+            /* Make sure that buf has space for one additional
+               character, the semicolon that might be added below. */
+            if (fgets (buf, sizeof buf - 1, fp)) {
+                char *cp, *space;
 
                 /* Skip leading <filename>:<whitespace>, if present. */
                 if ((content_type = strchr (buf, ':')) != NULL) {
@@ -630,6 +632,23 @@ mime_type (const char *file_name) {
                 if ((cp = strpbrk (content_type, "\n\n")) != NULL) {
                     *cp = '\0';
                 }
+
+                /* If necessary, insert semicolon between content type
+                   and charset.  Assume that the first space is between
+                   them. */
+                if ((space = strchr (content_type, ' ')) != NULL) {
+                    ssize_t len = strlen (content_type);
+
+                    if (space - content_type > 0  &&
+                        len > space - content_type + 1) {
+                        if (*(space - 1) != ';') {
+                            /* The +1 is for the terminating NULL. */
+                            memmove (space + 1, space,
+                                     len - (space - content_type) + 1);
+                            *space = ';';
+                        }
+                    }
+                }
             } else {
                 advise (NULL, "unable to read mime type");
             }