* imap_fetch.c: added support for fetch-->envelope-->from
authorArt Cancro <ajc@citadel.org>
Mon, 25 Dec 2000 20:43:24 +0000 (20:43 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 25 Dec 2000 20:43:24 +0000 (20:43 +0000)
citadel/ChangeLog
citadel/imap_fetch.c
citadel/serv_imap.c

index 3bae209ec36195d9b57ae355dc914e49a0a0beca..d9d2d4faf2f97a49cfe5c7828131ca8c17b699f9 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 573.55  2000/12/25 20:43:24  ajc
+ * imap_fetch.c: added support for fetch-->envelope-->from
+
  Revision 573.54  2000/12/20 04:09:24  ajc
  * A few memory handling fixes to netproc.
 
@@ -2234,4 +2237,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 9b653b85f6073e0f7ed23d20144b62a9075bb70c..895a03feed44b704c792fba51fd1be2b0b3c0c83 100644 (file)
@@ -210,6 +210,39 @@ void imap_load_part(char *name, char *filename, char *partnum, char *disp,
 }
 
 
+/* 
+ * Called by imap_fetch_envelope() to output the "From" field.
+ * This is in its own function because its logic is kind of complex.  We
+ * really need to make this suck less.
+ */
+void imap_output_envelope_from(struct CtdlMessage *msg) {
+       char user[1024], node[1024], name[1024];
+
+       cprintf("((");                          /* open double-parens */
+       imap_strout(msg->cm_fields['A']);       /* personal name */
+       cprintf(" NIL ");                       /* source route (not used) */
+
+       if (msg->cm_fields['F'] != NULL) {
+               process_rfc822_addr(msg->cm_fields['F'], user, node, name);
+               imap_strout(user);              /* mailbox name (user id) */
+               cprintf(" ");
+               if (!strcasecmp(node, config.c_nodename)) {
+                       imap_strout(config.c_fqdn);
+               }
+               else {
+                       imap_strout(node);              /* host name */
+               }
+       }
+       else {
+               imap_strout(msg->cm_fields['A']); /* mailbox name (user id) */
+               cprintf(" ");
+               imap_strout(msg->cm_fields['N']);       /* host name */
+       }
+       
+       cprintf(")) ");                         /* close double-parens */
+}
+
+
 /*
  * Implements the ENVELOPE fetch item
  * 
@@ -220,35 +253,51 @@ void imap_load_part(char *name, char *filename, char *partnum, char *disp,
  * so we don't have to check for that condition like we do elsewhere.
  */
 void imap_fetch_envelope(long msgnum, struct CtdlMessage *msg) {
-       char buf[256];
+       char datestringbuf[256];
        time_t msgdate;
 
+
+       /* Parse the message date into an IMAP-format date string */
        if (msg->cm_fields['T'] != NULL) {
                msgdate = atol(msg->cm_fields['T']);
        }
        else {
                msgdate = time(NULL);
        }
+       datestring(datestringbuf, msgdate, DATESTRING_IMAP);
 
-       datestring(buf, msgdate, DATESTRING_IMAP);
-
+       /* Now start spewing data fields.  The order is important, as it is
+        * defined by the protocol specification.  Nonexistent fields must
+        * be output as NIL, existent fields must be quoted or literalled.
+        * The imap_strout() function conveniently does all this for us.
+        */
        cprintf("ENVELOPE (");
 
        /* date */
-       cprintf("\"%s\" ", buf);
+       imap_strout(datestringbuf);
+       cprintf(" ");
 
        /* subject */
        imap_strout(msg->cm_fields['U']);
        cprintf(" ");
 
-       cprintf("NIL ");        /* from */
-       cprintf("NIL ");        /* sender */
+       /* from */
+       imap_output_envelope_from(msg);
+
+       /* Sender (always in the RFC822 header) */
+       cprintf("NIL ");
+
        cprintf("NIL ");        /* reply-to */
+
        cprintf("NIL ");        /* to */
+
        cprintf("NIL ");        /* cc */
+
        cprintf("NIL ");        /* bcc */
+
        cprintf("NIL ");        /* in-reply-to */
 
+
        /* message ID */
        imap_strout(msg->cm_fields['I']);
 
index 3f463b6943e439511f0b32113eea840a4a5b2b86..3b544fd29eb883b622132b6a0a48a24b28499513 100644 (file)
@@ -382,7 +382,6 @@ void imap_command_loop(void) {
        char cmdbuf[256];
        char *parms[256];
        int num_parms;
-       int i;
 
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
@@ -416,9 +415,6 @@ void imap_command_loop(void) {
 
        /* grab the tag */
        num_parms = imap_parameterize(parms, cmdbuf);
-       for (i=0; i<num_parms; ++i) {
-               lprintf(9, " parms[%d]='%s'\n", i, parms[i]);
-       }
 
        /* commands which may be executed in any state */