* IMAP date strings. More stupidity.
authorArt Cancro <ajc@citadel.org>
Tue, 17 Oct 2000 03:42:22 +0000 (03:42 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 17 Oct 2000 03:42:22 +0000 (03:42 +0000)
citadel/genstamp.c
citadel/genstamp.h
citadel/imap_fetch.c
citadel/msgbase.c
citadel/netmailer.c
citadel/serv_smtp.c

index 4c7cf0d005aa51e00483e4c0a160bfbd4e83e917..1ca2752cd6f2d4527dee237807137cfed3cb9a2c 100644 (file)
@@ -27,20 +27,52 @@ static char *weekdays[] = {
  * Supplied with a unix timestamp, generate an RFC822-compliant textual
  * time and date stamp.
  */
-void generate_rfc822_datestamp(char *buf, time_t xtime) {
+void datestring(char *buf, time_t xtime, int which_format) {
        struct tm *t;
 
+       long offset;
+       char offsign;
+
        t = localtime(&xtime);
 
-       sprintf(buf, "%s, %02d %s %04d %02d:%02d:%02d %s",
-               weekdays[t->tm_wday],
-               t->tm_mday,
-               months[t->tm_mon],
-               t->tm_year + 1900,
-               t->tm_hour,
-               t->tm_min,
-               t->tm_sec,
-               tzname[0]
-               );
+       /* Convert "seconds west of GMT" to "hours/minutes offset" */
+       offset = timezone;
+       if (offset > 0) {
+               offsign = '-';
+       }
+       else {
+               offset = 0L - offset;
+               offsign = '+';
+       }
+       offset = ( (offset / 3600) * 100 ) + ( offset % 60 );
+
+       switch(which_format) {
+
+               case DATESTRING_RFC822:
+                       sprintf(buf, "%s, %02d %s %04d %02d:%02d:%02d %c%04ld",
+                               weekdays[t->tm_wday],
+                               t->tm_mday,
+                               months[t->tm_mon],
+                               t->tm_year + 1900,
+                               t->tm_hour,
+                               t->tm_min,
+                               t->tm_sec,
+                               offsign, offset
+                               );
+               break;
+
+               case DATESTRING_IMAP:
+                       sprintf(buf, "%02d-%s-%04d %02d:%02d:%02d %c%04ld",
+                               t->tm_mday,
+                               months[t->tm_mon],
+                               t->tm_year + 1900,
+                               t->tm_hour,
+                               t->tm_min,
+                               t->tm_sec,
+                               offsign, offset
+                               );
+               break;
+
+       }
 }
 
index 8a654b2efb2639308b5a771d212b4cf50750986b..ce8e0f9f6685b246e6482c9a9546127f3e83deeb 100644 (file)
@@ -3,4 +3,9 @@
  *
  */
 
-void generate_rfc822_datestamp(char *buf, time_t xtime);
+void datestring(char *buf, time_t xtime, int which_format);
+
+enum {
+       DATESTRING_RFC822,
+       DATESTRING_IMAP
+};
index 5b3c457ac58d8120aadb0ce2d9b0722767ac5396..a85eba79ffd28f3254379413d0a51bb46dcb4505 100644 (file)
@@ -39,6 +39,7 @@
 #include "serv_imap.h"
 #include "imap_tools.h"
 #include "imap_fetch.h"
+#include "genstamp.h"
 
 
 
@@ -52,6 +53,21 @@ void imap_fetch_uid(int seq) {
        cprintf("UID %ld", IMAP->msgids[seq-1]);
 }
 
+void imap_fetch_internaldate(struct CtdlMessage *msg) {
+       char buf[256];
+       time_t msgdate;
+
+       if (msg->cm_fields['T'] != NULL) {
+               msgdate = atol(msg->cm_fields['T']);
+       }
+       else {
+               msgdate = time(NULL);
+       }
+
+       datestring(buf, msgdate, DATESTRING_IMAP);
+       cprintf("INTERNALDATE \"%s\"", buf);
+}
+
 
 /*
  * imap_do_fetch() calls imap_do_fetch_msg() to output the deta of an
@@ -81,7 +97,7 @@ void imap_do_fetch_msg(int seq, struct CtdlMessage *msg,
                        /* FIXME do something here */
                }
                else if (!strcasecmp(itemlist[i], "INTERNALDATE")) {
-                       /* FIXME do something here */
+                       imap_fetch_internaldate(msg);
                }
                else if (!strcasecmp(itemlist[i], "RFC822")) {
                        /* FIXME do something here */
index 5dfb5f46f71e93e6f5392fcda0cd7bdeebbea4f6..2ef26071149cd0a162bebd24d2f2440b9f9c591e 100644 (file)
@@ -967,8 +967,8 @@ int CtdlOutputMsg(long msg_num,             /* message number (local) to fetch */
                                else if (i == 'R')
                                        cprintf("To: %s%s", mptr, nl);
                                else if (i == 'T') {
-                                       generate_rfc822_datestamp(datestamp,
-                                                               atol(mptr) );
+                                       datestring(datestamp, atol(mptr),
+                                               DATESTRING_RFC822 );
                                        cprintf("Date: %s%s", datestamp, nl);
                                }
                        }
index a2fe417adb2341bac0f054355a8cfd5ec7d4826a..b0a28e200ffdcfa540e71897c882d3ec333a3cc6 100644 (file)
@@ -286,7 +286,7 @@ int main(int argc, char **argv)
         */
        fprintf(rmail, "To: %s\n", rbuf);
        time(&now);
-       generate_rfc822_datestamp(datestamp, now);
+       datestring(datestamp, now, DATESTRING_RFC822);
        fprintf(rmail, "Date: %s\n", datestamp);
        fprintf(rmail, "Message-Id: <%ld@%s>\n", (long) mid_buf, nbuf);
        fprintf(rmail, "X-Mailer: %s\n", CITADEL);
index 4c557a94b3c24a61ec073e225ab127ff40127e63..0e372056adedd3325f53878ef7561e4c2e930447 100644 (file)
@@ -636,7 +636,7 @@ void smtp_data(void) {
 
        cprintf("354 Transmit message now; terminate with '.' by itself\r\n");
        
-       generate_rfc822_datestamp(nowstamp, time(NULL));
+       datestring(nowstamp, time(NULL), DATESTRING_RFC822);
        body = mallok(4096);
 
        if (body != NULL) snprintf(body, 4096,