]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_fetch.c
* The size constant "256" which shows up everywhere as a buffer size has now
[citadel.git] / citadel / imap_fetch.c
index 895a03feed44b704c792fba51fd1be2b0b3c0c83..1e1890ef8d42d3b050fbdf0e0b490c6f15b3762b 100644 (file)
@@ -45,7 +45,7 @@
 
 
 struct imap_fetch_part {
-       char desired_section[256];
+       char desired_section[SIZ];
        FILE *output_fp;
 };
 
@@ -64,7 +64,7 @@ void imap_fetch_flags(struct CtdlMessage *msg) {
 }
 
 void imap_fetch_internaldate(struct CtdlMessage *msg) {
-       char buf[256];
+       char buf[SIZ];
        time_t msgdate;
 
        if (msg->cm_fields['T'] != NULL) {
@@ -108,6 +108,9 @@ void imap_fetch_rfc822(int msgnum, char *whichfmt, struct CtdlMessage *msg) {
        CtdlRedirectOutput(tmp, -1);
        CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 0, 0, 1);
        CtdlRedirectOutput(NULL, -1);
+       if (!is_valid_message(msg)) {
+               lprintf(1, "WARNING: output clobbered the message!\n");
+       }
 
        /*
         * Now figure out where the headers/text break is.  IMAP considers the
@@ -253,9 +256,9 @@ void imap_output_envelope_from(struct CtdlMessage *msg) {
  * so we don't have to check for that condition like we do elsewhere.
  */
 void imap_fetch_envelope(long msgnum, struct CtdlMessage *msg) {
-       char datestringbuf[256];
+       char datestringbuf[SIZ];
        time_t msgdate;
-
+       char *fieldptr = NULL;
 
        /* Parse the message date into an IMAP-format date string */
        if (msg->cm_fields['T'] != NULL) {
@@ -273,21 +276,32 @@ void imap_fetch_envelope(long msgnum, struct CtdlMessage *msg) {
         */
        cprintf("ENVELOPE (");
 
-       /* date */
+       /* Date */
        imap_strout(datestringbuf);
        cprintf(" ");
 
-       /* subject */
+       /* Subject */
        imap_strout(msg->cm_fields['U']);
        cprintf(" ");
 
-       /* from */
+       /* From */
        imap_output_envelope_from(msg);
 
-       /* Sender (always in the RFC822 header) */
-       cprintf("NIL ");
+       /* Sender */
+       if (0) {
+               /* FIXME ... check for a *real* Sender: field */
+       }
+       else {
+               imap_output_envelope_from(msg);
+       }
 
-       cprintf("NIL ");        /* reply-to */
+       /* Reply-to */
+       if (0) {
+               /* FIXME ... check for a *real* Reply-to: field */
+       }
+       else {
+               imap_output_envelope_from(msg);
+       }
 
        cprintf("NIL ");        /* to */
 
@@ -295,8 +309,11 @@ void imap_fetch_envelope(long msgnum, struct CtdlMessage *msg) {
 
        cprintf("NIL ");        /* bcc */
 
-       cprintf("NIL ");        /* in-reply-to */
-
+       /* In-reply-to */
+       fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "In-reply-to");
+       imap_strout(fieldptr);
+       cprintf(" ");
+       if (fieldptr != NULL) phree(fieldptr);
 
        /* message ID */
        imap_strout(msg->cm_fields['I']);
@@ -718,6 +735,10 @@ void imap_pick_range(char *range, int is_uid) {
        int s;
        char setstr[1024], lostr[1024], histr[1024];
        int lo, hi;
+       char *actual_range;
+
+       actual_range = range;
+       if (!strcasecmp(range, "ALL")) actual_range = "1:*";
 
        /*
         * Clear out the IMAP_FETCHED flags for all messages.
@@ -729,9 +750,9 @@ void imap_pick_range(char *range, int is_uid) {
        /*
         * Now set it for all specified messages.
         */
-       num_sets = num_tokens(range, ',');
+       num_sets = num_tokens(actual_range, ',');
        for (s=0; s<num_sets; ++s) {
-               extract_token(setstr, range, s, ',');
+               extract_token(setstr, actual_range, s, ',');
 
                extract_token(lostr, setstr, 0, ':');
                if (num_tokens(setstr, ':') >= 2) {
@@ -770,7 +791,7 @@ void imap_pick_range(char *range, int is_uid) {
  */
 void imap_fetch(int num_parms, char *parms[]) {
        char items[1024];
-       char *itemlist[256];
+       char *itemlist[SIZ];
        int num_items;
        int i;
 
@@ -802,7 +823,7 @@ void imap_fetch(int num_parms, char *parms[]) {
  */
 void imap_uidfetch(int num_parms, char *parms[]) {
        char items[1024];
-       char *itemlist[256];
+       char *itemlist[SIZ];
        int num_items;
        int i;
        int have_uid_item = 0;