* 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;
+
+ }
}
*
*/
-void generate_rfc822_datestamp(char *buf, time_t xtime);
+void datestring(char *buf, time_t xtime, int which_format);
+
+enum {
+ DATESTRING_RFC822,
+ DATESTRING_IMAP
+};
#include "serv_imap.h"
#include "imap_tools.h"
#include "imap_fetch.h"
+#include "genstamp.h"
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
/* 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 */
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);
}
}
*/
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);
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,