]> code.citadel.org Git - citadel.git/commitdiff
Be more tolerant about whitespace between keys and values
authorArt Cancro <ajc@citadel.org>
Sun, 25 Mar 2007 04:14:20 +0000 (04:14 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 25 Mar 2007 04:14:20 +0000 (04:14 +0000)
in the MIME headers.  Some b0rken mailers generate some weird stuff...

webcit/mime_parser.c

index 2baa96a5011ffe5a0a06ed9cce9e42f866e86186..e68f99c317d9b9fa02897bd9bf1d853d5f3484fe 100644 (file)
@@ -313,8 +313,9 @@ void the_mime_parser(char *partnum,
                }
 
                if (!isspace(buf[0])) {
-                       if (!strncasecmp(header, "Content-type: ", 14)) {
-                               strcpy(content_type, &header[14]);
+                       if (!strncasecmp(header, "Content-type:", 13)) {
+                               strcpy(content_type, &header[13]);
+                               striplt(content_type);
                                extract_key(content_type_name, content_type, "name");
                                extract_key(charset, content_type, "charset");
                                /* Deal with weird headers */
@@ -323,23 +324,29 @@ void the_mime_parser(char *partnum,
                                if (strchr(content_type, ';'))
                                        *(strchr(content_type, ';')) = '\0';
                        }
-                       if (!strncasecmp(header, "Content-Disposition: ", 21)) {
-                               strcpy(disposition, &header[21]);
+                       if (!strncasecmp(header, "Content-Disposition:", 20)) {
+                               strcpy(disposition, &header[20]);
+                               striplt(disposition);
                                extract_key(content_disposition_name, disposition, "name");
                                extract_key(filename, disposition, "filename");
                        }
-                       if (!strncasecmp(header, "Content-length: ", 16)) {
-                               content_length = (size_t) atol(&header[16]);
+                       if (!strncasecmp(header, "Content-length: ", 15)) {
+                               char clbuf[10];
+                               safestrncpy(clbuf, &header[15], sizeof clbuf);
+                               striplt(clbuf);
+                               content_length = (size_t) atol(clbuf);
+                       }
+                       if (!strncasecmp(header, "Content-transfer-encoding: ", 26)) {
+                               strcpy(encoding, &header[26]);
+                               striplt(encoding);
                        }
-                       if (!strncasecmp(header,
-                                     "Content-transfer-encoding: ", 27))
-                               strcpy(encoding, &header[27]);
                        if (strlen(boundary) == 0)
                                extract_key(boundary, header, "boundary");
                        strcpy(header, "");
                }
-               if ((strlen(header) + strlen(buf) + 2) < SIZ)
+               if ((strlen(header) + strlen(buf) + 2) < SIZ) {
                        strcat(header, buf);
+               }
        } while ((strlen(buf) > 0) && (*ptr != 0));
 
        if (strchr(disposition, ';'))