Brought over the updated MIME parser from Citadel.
authorArt Cancro <ajc@citadel.org>
Thu, 22 Mar 2007 02:55:44 +0000 (02:55 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 22 Mar 2007 02:55:44 +0000 (02:55 +0000)
webcit/mime_parser.c

index 79d3116c4cf5e05b2ae8abd5770fb12793521b67..2baa96a5011ffe5a0a06ed9cce9e42f866e86186 100644 (file)
@@ -13,8 +13,6 @@
 #include "webserver.h"
 #include "mime_parser.h"
 
-
-
 void extract_key(char *target, char *source, char *key)
 {
        int a, b;
@@ -255,7 +253,9 @@ void the_mime_parser(char *partnum,
        int part_seq = 0;
        int i;
        size_t length;
-       char nested_partnum[SIZ];
+       char nested_partnum[256];
+       int crlf_in_use = 0;
+       char *evaluate_crlf_ptr = NULL;
 
        ptr = content_start;
        content_length = 0;
@@ -383,7 +383,10 @@ void the_mime_parser(char *partnum,
 
                        if ( (part_start != NULL) && (next_boundary != NULL) ) {
                                part_end = next_boundary;
-                               --part_end;
+                               --part_end;             /* omit the trailing LF */
+                               if (crlf_in_use) {
+                                       --part_end;     /* omit the trailing CR */
+                               }
 
                                if (strlen(partnum) > 0) {
                                        snprintf(nested_partnum,
@@ -414,6 +417,18 @@ void the_mime_parser(char *partnum,
                                else {
                                        /* Set up for the next part. */
                                        part_start = strstr(next_boundary, "\n");
+                                       
+                                       /* Determine whether newlines are LF or CRLF */
+                                       evaluate_crlf_ptr = part_start;
+                                       --evaluate_crlf_ptr;
+                                       if (!memcmp(evaluate_crlf_ptr, "\r\n", 2)) {
+                                               crlf_in_use = 1;
+                                       }
+                                       else {
+                                               crlf_in_use = 0;
+                                       }
+
+                                       /* Advance past the LF ... now we're in the next part */
                                        ++part_start;
                                        ptr = part_start;
                                }
@@ -592,6 +607,4 @@ void mime_parser(char *content_start,
                        userdata, dont_decode);
 }
 
-
-
 /*@}*/