X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/847940e28795d71c9d9e58c7b6380ca82d916e55..2181cd0442664bf083825fd5b2d789714ba1812d:/uip/sendsbr.c diff --git a/uip/sendsbr.c b/uip/sendsbr.c index 6d76e9cd..bfd65157 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -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 buf, 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 :, 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"); }