]> code.citadel.org Git - citadel.git/commitdiff
The MIME parser now correctly handles both LF and CRLF
authorArt Cancro <ajc@citadel.org>
Thu, 22 Mar 2007 02:53:56 +0000 (02:53 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 22 Mar 2007 02:53:56 +0000 (02:53 +0000)
newline styles, rendering the correct number of bytes per part
in either case.

citadel/mime_parser.c

index abe1f4a99abc82bc436a9925685da5cac83279ff..15a67ce5eb184411f29c8ac1cc4e290e0f9dcddf 100644 (file)
@@ -267,7 +267,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;
@@ -395,7 +397,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,
@@ -426,6 +431,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;
                                }