Added the ability to supply both start and end pointers to mime_parser()
authorArt Cancro <ajc@citadel.org>
Wed, 20 Jan 1999 20:06:31 +0000 (20:06 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 20 Jan 1999 20:06:31 +0000 (20:06 +0000)
in order to facilitate recursive handling of multipart content.

citadel/mime_parser.c
citadel/mime_parser.h
citadel/msgbase.c

index a882bc4ebcd68218a8b4440f16b6292c274f745c..4ea32081267054cfb4025b551913addace344762 100644 (file)
@@ -77,8 +77,10 @@ char *memreadline(char *start, char *buf, int maxlen) {
 /*
  * Break out the components of a multipart message
  * (This function expects to be fed HEADERS + CONTENT)
+ * Note: NULL can be supplied as content_end; in this case, the message is
+ * considered to have ended when the parser encounters a 0x00 byte.
  */
-void mime_parser(char *content,
+void mime_parser(char *content_start, char *content_end,
                void (*CallBack)
                        (char *cbname,
                        char *cbfilename,
@@ -98,7 +100,7 @@ void mime_parser(char *content,
        int content_length;
        int i;
 
-       ptr = content;
+       ptr = content_start;
        bzero(boundary, sizeof boundary);
        bzero(content_type, sizeof content_type);
        bzero(encoding, sizeof encoding);
@@ -108,6 +110,10 @@ void mime_parser(char *content,
        strcpy(header, "");
        do {
                ptr = memreadline(ptr, buf, sizeof buf);
+               if (*ptr == 0) return; /* premature end of message */
+               if (content_end != NULL)
+                       if (ptr >= content_end) return;
+
                for (i=0; i<strlen(buf); ++i)
                        if (isspace(buf[i])) buf[i]=' ';
                if (!isspace(buf[0])) {
@@ -131,7 +137,6 @@ void mime_parser(char *content,
        cprintf("Content length is %d\n", content_length);
        cprintf("Boundary is <%s>\n", boundary);
 
-       if (*ptr == 0) return; /* premature end of message */
 
        /* If this is a multipart message, then recursively process it */
        if (strlen(boundary)>0) {
index 84dfdeef35e49c0c455808975dcf162fb87f9dc6..67e3afc650f126779299827449c0147ef768da8c 100644 (file)
@@ -1,6 +1,6 @@
 void extract_key(char *target, char *source, char *key);
 
-void mime_parser(char *content,
+void mime_parser(char *content_start, char *content_end,
                void (*CallBack)
                        (char *cbname,
                        char *cbfilename,
index f59ef82acdbb95ad34d7d9995f557fef994ef93d..8cdcf8b6a36d0a9d51545c5af839f06d7235a5ea 100644 (file)
@@ -551,7 +551,7 @@ time_t output_message(char *msgid, int mode, int headers_only) {
 
        /* do some sort of MIME output */
        if ( (mode == MT_MIME) && (format_type == 4) ) {
-               mime_parser(mptr, *part_handler);
+               mime_parser(mptr, NULL, *part_handler);
                cprintf("000\n");
                cdb_free(dmsgtext);
                return(xtime);