* More changes required to be able to do embedded message/rfc822 and still be
[citadel.git] / webcit / mime_parser.c
index 1c82b001a2462b04673df5c80a9725d3920109c5..f3fb942bd8384ba163e9227478a8955b7975e548 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $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.
@@ -397,7 +397,6 @@ void the_mime_parser(char *partnum,
 
                part_start = NULL;
                do {
-       
                        next_boundary = NULL;
                        for (srch=ptr; srch<content_end; ++srch) {
                                if (!memcmp(srch, startary, startary_len)) {
@@ -465,9 +464,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) ) {
@@ -484,13 +483,61 @@ void the_mime_parser(char *partnum,
                else {
                        name = content_type_name;
                }
-               
+       
+               /*
+               lprintf(9, "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
+               );
+
+               /*
+                * Now if it's an encapsulated message/rfc822 then we have to recurse into it
+                */
+               if (!strcasecmp(content_type, "message/rfc822")) {
+
+                       if (PreMultiPartCallBack != NULL) {
+                               PreMultiPartCallBack("", "", partnum, "",
+                                       NULL, content_type, charset,
+                                       0, encoding, userdata);
+                       }
+                       if (CallBack != NULL) {
+                               if (strlen(partnum) > 0) {
+                                       snprintf(nested_partnum,
+                                                sizeof nested_partnum,
+                                                "%s.%d", partnum,
+                                                ++part_seq);
+                               }
+                               else {
+                                       snprintf(nested_partnum,
+                                                sizeof nested_partnum,
+                                                "%d", ++part_seq);
+                               }
+                               the_mime_parser(nested_partnum,
+                                       part_start, part_end,
+                                       CallBack,
+                                       PreMultiPartCallBack,
+                                       PostMultiPartCallBack,
+                                       userdata,
+                                       dont_decode
+                               );
+                       }
+                       if (PostMultiPartCallBack != NULL) {
+                               PostMultiPartCallBack("", "", partnum, "", NULL,
+                                       content_type, charset, 0, encoding, userdata);
+                       }
+
+
+               }
+
        }
 
 end_parser:    /* free the buffers!  end the oppression!! */