]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_fetch.c
* Use syslog-compatible logging levels in lprintf(); the loglevel chosen
[citadel.git] / citadel / imap_fetch.c
index c614e6e7420f9468bf399be3b91110923174d06b..007db16832461ecafaca02c33f7aca256360d723 100644 (file)
@@ -125,8 +125,8 @@ void imap_fetch_rfc822(int msgnum, char *whichfmt, struct CtdlMessage *msg) {
 
        tmp = tmpfile();
        if (tmp == NULL) {
-               lprintf(1, "Cannot open temp file: %s\n",
-                                               strerror(errno));
+               lprintf(CTDL_CRIT, "Cannot open temp file: %s\n",
+                               strerror(errno));
                return;
        }
 
@@ -139,7 +139,7 @@ void imap_fetch_rfc822(int msgnum, char *whichfmt, struct CtdlMessage *msg) {
                                HEADERS_ALL, 0, 1);
        CtdlRedirectOutput(NULL, -1);
        if (!is_valid_message(msg)) {
-               lprintf(1, "WARNING: output clobbered the message!\n");
+               lprintf(CTDL_ERR, "WARNING: output clobbered the message!\n");
        }
 
        /*
@@ -290,12 +290,58 @@ void imap_output_envelope_from(struct CtdlMessage *msg) {
 }
 
 
+
+/*
+ * Output an envelope address (or set of addresses) in the official,
+ * Crispin-approved braindead format.  (Note that we can't use this for
+ * the "From" address because its data may come from a number of different
+ * fields.  But we can use it for "To" and possibly others.
+ */
+void imap_output_envelope_addr(char *addr) {
+       char individual_addr[SIZ];
+       int num_addrs;
+       int i;
+       char user[SIZ];
+       char node[SIZ];
+       char name[SIZ];
+
+       if (addr == NULL) {
+               cprintf("NIL ");
+               return;
+       }
+
+       if (strlen(addr) == 0) {
+               cprintf("NIL ");
+               return;
+       }
+
+       cprintf("(");
+
+       /* How many addresses are listed here? */
+       num_addrs = num_tokens(addr, ',');
+
+       /* Output them one by one. */
+       for (i=0; i<num_addrs; ++i) {
+               extract_token(individual_addr, addr, i, ',');
+               striplt(individual_addr);
+               process_rfc822_addr(individual_addr, user, node, name);
+               cprintf("(");
+               imap_strout(name);
+               cprintf(" NIL ");
+               imap_strout(user);
+               cprintf(" ");
+               imap_strout(node);
+               cprintf(")");
+               if (i < (num_addrs-1)) cprintf(" ");
+       }
+
+       cprintf(") ");
+}
+
+
 /*
  * Implements the ENVELOPE fetch item
  * 
- * FIXME ... we only output some of the fields right now.  Definitely need
- *           to do all of them.  Accurately, too.
- *
  * Note that the imap_strout() function can cleverly output NULL fields as NIL,
  * so we don't have to check for that condition like we do elsewhere.
  */
@@ -332,27 +378,38 @@ void imap_fetch_envelope(long msgnum, struct CtdlMessage *msg) {
        /* From */
        imap_output_envelope_from(msg);
 
-       /* Sender */
-       if (0) {
-               /* FIXME */
+       /* Sender (default to same as 'From' if not present) */
+       fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Sender");
+       if (fieldptr != NULL) {
+               imap_output_envelope_addr(fieldptr);
+               phree(fieldptr);
        }
        else {
                imap_output_envelope_from(msg);
        }
 
        /* Reply-to */
-       if (0) {
-               /* FIXME */
+       fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Reply-to");
+       if (fieldptr != NULL) {
+               imap_output_envelope_addr(fieldptr);
+               phree(fieldptr);
        }
        else {
                imap_output_envelope_from(msg);
        }
 
-       cprintf("NIL ");        /* to */
+       /* To */
+       imap_output_envelope_addr(msg->cm_fields['R']);
 
-       cprintf("NIL ");        /* cc */
+       /* Cc */
+       fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Cc");
+       imap_output_envelope_addr(fieldptr);
+       if (fieldptr != NULL) phree(fieldptr);
 
-       cprintf("NIL ");        /* bcc */
+       /* Bcc */
+       fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Bcc");
+       imap_output_envelope_addr(fieldptr);
+       if (fieldptr != NULL) phree(fieldptr);
 
        /* In-reply-to */
        fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "In-reply-to");
@@ -471,7 +528,7 @@ void imap_fetch_body(long msgnum, char *item, int is_peek,
        for (i=0; i<strlen(section); ++i) {
                if (section[i]==']') section[i] = 0;
        }
-       lprintf(9, "Section is %s\n", section);
+       lprintf(CTDL_DEBUG, "Section is %s\n", section);
 
        /* extract partial */
        strcpy(partial, item);
@@ -485,11 +542,11 @@ void imap_fetch_body(long msgnum, char *item, int is_peek,
                if (partial[i]=='>') partial[i] = 0;
        }
        if (is_partial == 0) strcpy(partial, "");
-       if (strlen(partial) > 0) lprintf(9, "Partial is %s\n", partial);
+       if (strlen(partial) > 0) lprintf(CTDL_DEBUG, "Partial is %s\n", partial);
 
        tmp = tmpfile();
        if (tmp == NULL) {
-               lprintf(1, "Cannot open temp file: %s\n", strerror(errno));
+               lprintf(CTDL_CRIT, "Cannot open temp file: %s\n", strerror(errno));
                return;
        }