]> code.citadel.org Git - citadel.git/commitdiff
* Changed the mime_parser() API (again) to allow "don't decode" mode
authorArt Cancro <ajc@citadel.org>
Mon, 6 Nov 2000 05:10:01 +0000 (05:10 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 6 Nov 2000 05:10:01 +0000 (05:10 +0000)
citadel/ChangeLog
citadel/imap_fetch.c
citadel/mime_parser.c
citadel/mime_parser.h
citadel/msgbase.c

index 47d1af2a3cc0bd62a886034de321efa87f28d0ff..567066a949c48131eaea2ed8d6d03bb39e711ed2 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 573.20  2000/11/06 05:10:01  ajc
+ * Changed the mime_parser() API (again) to allow "don't decode" mode
+
  Revision 573.19  2000/10/29 18:11:07  ajc
  * Start numbering top-level MIME parts as 1, 2... not 1.1, 1.2...
 
@@ -2116,4 +2119,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index 7c35b37a352a189edf6b7ca803ea2b25e9656bfa..2dcb373e79197b5ae6a8a0d9fd0cad7fcea0b49e 100644 (file)
@@ -162,10 +162,16 @@ void imap_fetch_rfc822(int msgnum, char *whichfmt) {
 
 
 /*
- * FIXME this is TOTALLY BROKEN!!!
+ * Load a specific part of a message into the temp file to be output to a
+ * client.  FIXME we can handle parts like "2" and "2.1" but we still have
+ * to handle parts like "2.MIME" and "2.HEADER" (the latter maybe not ...
+ * Mark Crispy's server doesn't seem to)
+ *
+ * Note: mime_parser() was called with dont_decode set to 1, so we have the
+ * luxury of simply spewing without having to re-encode.
  */
-void imap_fetch_part(char *name, char *filename, char *partnum, char *disp,
-                   void *content, char *cbtype, size_t length,
+void imap_load_part(char *name, char *filename, char *partnum, char *disp,
+                   void *content, char *cbtype, size_t length, char *encoding,
                    void *cbuserdata)
 {
        struct imap_fetch_part *imfp;
@@ -173,9 +179,9 @@ void imap_fetch_part(char *name, char *filename, char *partnum, char *disp,
        imfp = (struct imap_fetch_part *)cbuserdata;
 
        if (!strcasecmp(partnum, imfp->desired_section)) {
-               cprintf("part=%s|%s|%s|%s|%s|%d\r\n",
-                       name, filename, partnum, disp, cbtype, length, NULL);
+               fwrite(content, length, 1, imfp->output_fp);
        }
+
 }
 
 
@@ -248,6 +254,7 @@ void imap_fetch_body(long msgnum, char *item, int is_peek,
 
        /*
         * Anything else must be a part specifier.
+        * (Note value of 1 passed as 'dont_decode' so client gets it encoded)
         */
        else {
                safestrncpy(imfp.desired_section, section,
@@ -255,8 +262,9 @@ void imap_fetch_body(long msgnum, char *item, int is_peek,
                imfp.output_fp = tmp;
 
                mime_parser(msg->cm_fields['M'], NULL,
-                               *imap_fetch_part,
-                               (void *)&imfp);
+                               *imap_load_part,
+                               (void *)&imfp,
+                               1);
        }
 
 
index 9904f4607a6fae866bfce4e8782b9df94397f993..64e64670397ebd28661950242cf14b3274ccba8e 100644 (file)
@@ -92,8 +92,10 @@ void mime_decode(char *partnum,
                   void *cbcontent,
                   char *cbtype,
                   size_t cblength,
+                  char *cbencoding,
                   void *cbuserdata),
-                 void *userdata
+                 void *userdata,
+                 int dont_decode
 )
 {
 
@@ -118,9 +120,9 @@ void mime_decode(char *partnum,
                strcpy(encoding, "");
 
        /* If this part is not encoded, send as-is */
-       if (strlen(encoding) == 0) {
+       if ( (strlen(encoding) == 0) || (dont_decode)) {
                CallBack(name, filename, partnum, disposition, part_start,
-                        content_type, length, userdata);
+                        content_type, length, encoding, userdata);
                return;
        }
        if ((strcasecmp(encoding, "base64"))
@@ -199,7 +201,7 @@ void mime_decode(char *partnum,
 
        if (bytes_recv > 0)
                CallBack(name, filename, partnum, disposition, decoded,
-                        content_type, bytes_recv, userdata);
+                        content_type, bytes_recv, "binary", userdata);
 
        phree(decoded);
 }
@@ -220,8 +222,10 @@ void the_mime_parser(char *partnum,
                       void *cbcontent,
                       char *cbtype,
                       size_t cblength,
+                      char *cbencoding,
                       void *cbuserdata),
-                     void *userdata
+                     void *userdata,
+                     int dont_decode
 )
 {
 
@@ -307,7 +311,8 @@ void the_mime_parser(char *partnum,
        if (is_multipart) {
 
                /* Tell the client about this message's multipartedness */
-               CallBack("", "", partnum, "", NULL, content_type, 0, userdata);
+               CallBack("", "", partnum, "", NULL, content_type, 0,
+                               encoding, userdata);
 
                /* Figure out where the boundaries are */
                sprintf(startary, "--%s", boundary);
@@ -333,7 +338,8 @@ void the_mime_parser(char *partnum,
                                        }
                                        the_mime_parser(nested_partnum,
                                                    part_start, part_end,
-                                                       CallBack, userdata);
+                                                       CallBack, userdata,
+                                                       dont_decode);
                                }
                                part_start = ptr;
                        }
@@ -352,7 +358,7 @@ void the_mime_parser(char *partnum,
                mime_decode(partnum,
                            part_start, length,
                            content_type, encoding, disposition,
-                           name, filename, CallBack, userdata);
+                           name, filename, CallBack, userdata, dont_decode);
        }
 
 
@@ -375,11 +381,14 @@ void mime_parser(char *content_start, char *content_end,
                   void *cbcontent,
                   char *cbtype,
                   size_t cblength,
+                  char *cbencoding,
                   void *cbuserdata),
-                 void *userdata
+                 void *userdata,
+                 int dont_decode
 )
 {
 
        lprintf(9, "mime_parser() called\n");
-       the_mime_parser("", content_start, content_end, CallBack, userdata);
+       the_mime_parser("", content_start, content_end, CallBack,
+                       userdata, dont_decode);
 }
index fff67f42c187c160b944834448067b70bc40903f..93dd34037bb9a4939f3d3938fe3b3d3eca01bb51 100644 (file)
@@ -14,6 +14,8 @@ void mime_parser(char *content_start, char *content_end,
                        void *cbcontent,
                        char *cbtype,
                        size_t cblength,
+                       char *cbencoding,
                        void *cbuserdata),
-               void *userdata
+               void *userdata,
+               int dont_decode
                );
index a8d1069665261b1c1df993de65c936aa815740e6..5177e470e93a963012f84cfd75d41dea52ccc2eb 100644 (file)
@@ -573,7 +573,7 @@ void memfmout(
  * Callback function for mime parser that simply lists the part
  */
 void list_this_part(char *name, char *filename, char *partnum, char *disp,
-                   void *content, char *cbtype, size_t length,
+                   void *content, char *cbtype, size_t length, char *encoding,
                    void *cbuserdata)
 {
 
@@ -586,7 +586,7 @@ void list_this_part(char *name, char *filename, char *partnum, char *disp,
  * Callback function for mime parser that opens a section for downloading
  */
 void mime_download(char *name, char *filename, char *partnum, char *disp,
-                  void *content, char *cbtype, size_t length,
+                  void *content, char *cbtype, size_t length, char *encoding,
                   void *cbuserdata)
 {
 
@@ -722,7 +722,7 @@ void CtdlFreeMessage(struct CtdlMessage *msg)
  * Callback function for mime parser that wants to display text
  */
 void fixed_output(char *name, char *filename, char *partnum, char *disp,
-               void *content, char *cbtype, size_t length,
+               void *content, char *cbtype, size_t length, char *encoding,
                void *cbuserdata)
        {
                char *ptr;
@@ -853,7 +853,7 @@ int CtdlOutputMsg(long msg_num,             /* message number (local) to fetch */
                } else {
                        /* Parse the message text component */
                        mptr = TheMessage->cm_fields['M'];
-                       mime_parser(mptr, NULL, *mime_download, NULL);
+                       mime_parser(mptr, NULL, *mime_download, NULL, 0);
                        /* If there's no file open by this time, the requested
                         * section wasn't found, so print an error
                         */
@@ -1011,10 +1011,10 @@ int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
        /* Tell the client about the MIME parts in this message */
        if (TheMessage->cm_format_type == FMT_RFC822) {
                if (mode == MT_CITADEL) {
-                       mime_parser(mptr, NULL, *list_this_part, NULL);
+                       mime_parser(mptr, NULL, *list_this_part, NULL, 0);
                }
                else if (mode == MT_MIME) {     /* list parts only */
-                       mime_parser(mptr, NULL, *list_this_part, NULL);
+                       mime_parser(mptr, NULL, *list_this_part, NULL, 0);
                        if (do_proto) cprintf("000\n");
                        CtdlFreeMessage(TheMessage);
                        return(om_ok);
@@ -1092,7 +1092,7 @@ int CtdlOutputMsg(long msg_num,           /* message number (local) to fetch */
        if (TheMessage->cm_format_type == FMT_RFC822) {
                CtdlAllocUserData(SYM_MA_INFO, sizeof(struct ma_info));
                memset(ma, 0, sizeof(struct ma_info));
-               mime_parser(mptr, NULL, *fixed_output, NULL);
+               mime_parser(mptr, NULL, *fixed_output, NULL, 0);
        }
 
        /* now we're done */