From cb16d095ee1f3f2a5e8022b7a4a7c4289eadd77c Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 17 Oct 2000 03:42:22 +0000 Subject: [PATCH] * IMAP date strings. More stupidity. --- citadel/genstamp.c | 54 +++++++++++++++++++++++++++++++++++--------- citadel/genstamp.h | 7 +++++- citadel/imap_fetch.c | 18 ++++++++++++++- citadel/msgbase.c | 4 ++-- citadel/netmailer.c | 2 +- citadel/serv_smtp.c | 2 +- 6 files changed, 70 insertions(+), 17 deletions(-) diff --git a/citadel/genstamp.c b/citadel/genstamp.c index 4c7cf0d00..1ca2752cd 100644 --- a/citadel/genstamp.c +++ b/citadel/genstamp.c @@ -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; + + } } diff --git a/citadel/genstamp.h b/citadel/genstamp.h index 8a654b2ef..ce8e0f9f6 100644 --- a/citadel/genstamp.h +++ b/citadel/genstamp.h @@ -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 +}; diff --git a/citadel/imap_fetch.c b/citadel/imap_fetch.c index 5b3c457ac..a85eba79f 100644 --- a/citadel/imap_fetch.c +++ b/citadel/imap_fetch.c @@ -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 */ diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 5dfb5f46f..2ef260711 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -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); } } diff --git a/citadel/netmailer.c b/citadel/netmailer.c index a2fe417ad..b0a28e200 100644 --- a/citadel/netmailer.c +++ b/citadel/netmailer.c @@ -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); diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index 4c557a94b..0e372056a 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -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, -- 2.30.2