]> code.citadel.org Git - citadel.git/commitdiff
* Worked on the fetching of mime parts using imap
authorArt Cancro <ajc@citadel.org>
Thu, 2 Nov 2000 22:58:21 +0000 (22:58 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 2 Nov 2000 22:58:21 +0000 (22:58 +0000)
citadel/imap_fetch.c
citadel/mime_parser.c
citadel/mime_parser.h
citadel/msgbase.c
citadel/serv_imap.h

index 9f4a242c83852911c84240302d054ed659a087dc..7c35b37a352a189edf6b7ca803ea2b25e9656bfa 100644 (file)
 
 
 
+struct imap_fetch_part {
+       char desired_section[256];
+       FILE *output_fp;
+};
+
 /*
  * Individual field functions for imap_do_fetch_msg() ...
  */
@@ -160,12 +165,16 @@ void imap_fetch_rfc822(int msgnum, char *whichfmt) {
  * FIXME this is TOTALLY BROKEN!!!
  */
 void imap_fetch_part(char *name, char *filename, char *partnum, char *disp,
-                   void *content, char *cbtype, size_t length)
+                   void *content, char *cbtype, size_t length,
+                   void *cbuserdata)
 {
+       struct imap_fetch_part *imfp;
+
+       imfp = (struct imap_fetch_part *)cbuserdata;
 
-       if (!strcasecmp(partnum, IMAP->desired_part)) {
+       if (!strcasecmp(partnum, imfp->desired_section)) {
                cprintf("part=%s|%s|%s|%s|%s|%d\r\n",
-                       name, filename, partnum, disp, cbtype, length);
+                       name, filename, partnum, disp, cbtype, length, NULL);
        }
 }
 
@@ -187,6 +196,7 @@ void imap_fetch_body(long msgnum, char *item, int is_peek,
        long bytes_remaining = 0;
        long blocksize;
        long pstart, pbytes;
+       struct imap_fetch_part imfp;
 
        /* extract section */
        strcpy(section, item);
@@ -240,9 +250,13 @@ void imap_fetch_body(long msgnum, char *item, int is_peek,
         * Anything else must be a part specifier.
         */
        else {
-               safestrncpy(IMAP->desired_part, section,
-                               sizeof(IMAP->desired_part));
-               mime_parser(msg->cm_fields['M'], NULL, *imap_fetch_part);
+               safestrncpy(imfp.desired_section, section,
+                               sizeof(imfp.desired_section));
+               imfp.output_fp = tmp;
+
+               mime_parser(msg->cm_fields['M'], NULL,
+                               *imap_fetch_part,
+                               (void *)&imfp);
        }
 
 
index 057ec6c4ebea19d1988b104cc86ae92ab2b22854..9904f4607a6fae866bfce4e8782b9df94397f993 100644 (file)
@@ -91,7 +91,9 @@ void mime_decode(char *partnum,
                   char *cbdisp,
                   void *cbcontent,
                   char *cbtype,
-                  size_t cblength)
+                  size_t cblength,
+                  void *cbuserdata),
+                 void *userdata
 )
 {
 
@@ -118,7 +120,7 @@ void mime_decode(char *partnum,
        /* If this part is not encoded, send as-is */
        if (strlen(encoding) == 0) {
                CallBack(name, filename, partnum, disposition, part_start,
-                        content_type, length);
+                        content_type, length, userdata);
                return;
        }
        if ((strcasecmp(encoding, "base64"))
@@ -197,7 +199,7 @@ void mime_decode(char *partnum,
 
        if (bytes_recv > 0)
                CallBack(name, filename, partnum, disposition, decoded,
-                        content_type, bytes_recv);
+                        content_type, bytes_recv, userdata);
 
        phree(decoded);
 }
@@ -217,7 +219,9 @@ void the_mime_parser(char *partnum,
                       char *cbdisp,
                       void *cbcontent,
                       char *cbtype,
-                      size_t cblength)
+                      size_t cblength,
+                      void *cbuserdata),
+                     void *userdata
 )
 {
 
@@ -303,7 +307,7 @@ void the_mime_parser(char *partnum,
        if (is_multipart) {
 
                /* Tell the client about this message's multipartedness */
-               CallBack("", "", partnum, "", NULL, content_type, 0);
+               CallBack("", "", partnum, "", NULL, content_type, 0, userdata);
 
                /* Figure out where the boundaries are */
                sprintf(startary, "--%s", boundary);
@@ -329,7 +333,7 @@ void the_mime_parser(char *partnum,
                                        }
                                        the_mime_parser(nested_partnum,
                                                    part_start, part_end,
-                                                       CallBack);
+                                                       CallBack, userdata);
                                }
                                part_start = ptr;
                        }
@@ -348,7 +352,7 @@ void the_mime_parser(char *partnum,
                mime_decode(partnum,
                            part_start, length,
                            content_type, encoding, disposition,
-                           name, filename, CallBack);
+                           name, filename, CallBack, userdata);
        }
 
 
@@ -370,10 +374,12 @@ void mime_parser(char *content_start, char *content_end,
                   char *cbdisp,
                   void *cbcontent,
                   char *cbtype,
-                  size_t cblength)
+                  size_t cblength,
+                  void *cbuserdata),
+                 void *userdata
 )
 {
 
        lprintf(9, "mime_parser() called\n");
-       the_mime_parser("", content_start, content_end, CallBack);
+       the_mime_parser("", content_start, content_end, CallBack, userdata);
 }
index 88f8cc7fc22255d59a0827c1a48d268bfe26f679..fff67f42c187c160b944834448067b70bc40903f 100644 (file)
@@ -13,5 +13,7 @@ void mime_parser(char *content_start, char *content_end,
                        char *cbdisp,
                        void *cbcontent,
                        char *cbtype,
-                       size_t cblength)
+                       size_t cblength,
+                       void *cbuserdata),
+               void *userdata
                );
index 307fc3251bf26c4956a55b1842197d5029743f34..a8d1069665261b1c1df993de65c936aa815740e6 100644 (file)
@@ -573,7 +573,8 @@ 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,
+                   void *cbuserdata)
 {
 
        cprintf("part=%s|%s|%s|%s|%s|%d\n",
@@ -585,7 +586,8 @@ 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,
+                  void *cbuserdata)
 {
 
        /* Silently go away if there's already a download open... */
@@ -720,7 +722,8 @@ 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,
+               void *cbuserdata)
        {
                char *ptr;
                char *wptr;
@@ -850,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);
+                       mime_parser(mptr, NULL, *mime_download, NULL);
                        /* If there's no file open by this time, the requested
                         * section wasn't found, so print an error
                         */
@@ -1008,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);
+                       mime_parser(mptr, NULL, *list_this_part, NULL);
                }
                else if (mode == MT_MIME) {     /* list parts only */
-                       mime_parser(mptr, NULL, *list_this_part);
+                       mime_parser(mptr, NULL, *list_this_part, NULL);
                        if (do_proto) cprintf("000\n");
                        CtdlFreeMessage(TheMessage);
                        return(om_ok);
@@ -1089,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);
+               mime_parser(mptr, NULL, *fixed_output, NULL);
        }
 
        /* now we're done */
index 74769536c298d7f93681b32bfede4852ee5050d3..217b62f6f9ccd05a522071d7e6d918f249b7465d 100644 (file)
@@ -17,7 +17,6 @@ struct citimap {
        int num_msgs;           /* Number of messages being mapped */
        long *msgids;
        unsigned int *flags;
-       char desired_part[256]; /* for part fetches */
 };
 
 /*