]> code.citadel.org Git - citadel.git/blobdiff - citadel/mime_parser.c
* MSG4 (and CtdlOutputMsg() as well) now accepts an optional MIME part
[citadel.git] / citadel / mime_parser.c
index cd98c538c06f553b4a7d26a5a3db09bf8bd70f6d..edbdc52cb0bc0773d17ad246128d9e7ebac32ccf 100644 (file)
@@ -1,17 +1,13 @@
 /*
  * $Id$
  *
- * This is the MIME parser for Citadel.  Sometimes it actually works.
+ * This is the MIME parser for Citadel.
  *
  * Copyright (c) 1998-2005 by Art Cancro
  * This code is distributed under the terms of the GNU General Public License.
  *
  */
 
-#ifdef DLL_EXPORT
-#define IN_LIBCIT
-#endif
-
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -275,11 +271,13 @@ void the_mime_parser(char *partnum,
 {
 
        char *ptr;
+       char *srch = NULL;
        char *part_start, *part_end = NULL;
        char buf[SIZ];
        char *header;
        char *boundary;
        char *startary;
+       size_t startary_len = 0;
        char *endary;
        char *next_boundary;
        char *content_type;
@@ -409,10 +407,18 @@ void the_mime_parser(char *partnum,
                /* Figure out where the boundaries are */
                snprintf(startary, SIZ, "--%s", boundary);
                snprintf(endary, SIZ, "--%s--", boundary);
+               startary_len = strlen(startary);
 
                part_start = NULL;
                do {
-                       next_boundary = bmstrstr(ptr, startary, strncmp);
+                       next_boundary = NULL;
+                       for (srch=ptr; srch<content_end; ++srch) {
+                               if (!memcmp(srch, startary, startary_len)) {
+                                       next_boundary = srch;
+                                       srch = content_end;
+                               }
+                       }
+
                        if ( (part_start != NULL) && (next_boundary != NULL) ) {
                                part_end = next_boundary;
                                --part_end;
@@ -438,8 +444,8 @@ void the_mime_parser(char *partnum,
                        }
 
                        if (next_boundary != NULL) {
-                               /* If we pass out of scope, don't attempt to read
-                                * past the end boundary. */
+                               /* If we pass out of scope, don't attempt to
+                                * read past the end boundary. */
                                if (!strcmp(next_boundary, endary)) {
                                        ptr = content_end;
                                }
@@ -472,9 +478,9 @@ void the_mime_parser(char *partnum,
                        ++length;
                }
                part_end = content_end;
-                /* fix an off-by-one error */
-                --part_end;
-                --length;
+               /* fix an off-by-one error */
+               --part_end;
+               --length;
                
                /* Truncate if the header told us to */
                if ( (content_length > 0) && (length > content_length) ) {
@@ -491,13 +497,19 @@ void the_mime_parser(char *partnum,
                else {
                        name = content_type_name;
                }
-               
+       
+               /* lprintf(CTDL_DEBUG, "mime_decode part=%s, len=%d, type=%s, charset=%s, encoding=%s\n",
+                       partnum, length, content_type, charset, encoding); */
+
+               /* Ok, we've got a non-multipart part here, so do something with it.
+                */
                mime_decode(partnum,
-                           part_start, length,
-                           content_type, charset, encoding, disposition,
-                           name, filename,
-                           CallBack, NULL, NULL,
-                           userdata, dont_decode);
+                       part_start, length,
+                       content_type, charset, encoding, disposition,
+                       name, filename,
+                       CallBack, NULL, NULL,
+                       userdata, dont_decode
+               );
        }
 
 end_parser:    /* free the buffers!  end the oppression!! */