--- /dev/null
+changeset: 5949:b2b97c7a2ae6
+branch: HEAD
+user: Brendan Cully <brendan@kublai.com>
+date: Fri Jun 26 21:47:34 2009 -0700
+summary: Set internaldate of messages appended to IMAP mailboxes
+
+--- a/imap/imap_private.h
++++ b/imap/imap_private.h
+@@ -70,6 +70,9 @@
+ #define IMAP_CMD_PASS (1<<1)
+ #define IMAP_CMD_QUEUE (1<<2)
+
++/* length of "DD-MMM-YYYY HH:MM:SS +ZZzz" (null-terminated) */
++#define IMAP_DATELEN 27
++
+ enum
+ {
+ IMAP_FATAL = 1,
+@@ -281,6 +284,7 @@ char* imap_get_qualifier (char* buf);
+ int imap_mxcmp (const char* mx1, const char* mx2);
+ char* imap_next_word (char* s);
+ time_t imap_parse_date (char* s);
++void imap_make_date (char* buf, time_t timestamp);
+ void imap_qualify_path (char *dest, size_t len, IMAP_MBOX *mx, char* path);
+ void imap_quote_string (char* dest, size_t slen, const char* src);
+ void imap_unquote_string (char* s);
+--- a/imap/message.c
++++ b/imap/message.c
+@@ -600,6 +600,7 @@ int imap_append_message (CONTEXT *ctx, M
+ char buf[LONG_STRING];
+ char mbox[LONG_STRING];
+ char mailbox[LONG_STRING];
++ char internaldate[IMAP_DATELEN];
+ size_t len;
+ progress_t progressbar;
+ size_t sent;
+@@ -641,12 +642,14 @@ int imap_append_message (CONTEXT *ctx, M
+ M_PROGRESS_SIZE, NetInc, len);
+
+ imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
+- snprintf (buf, sizeof (buf), "APPEND %s (%s%s%s%s%s) {%lu}", mbox,
++ imap_make_date (internaldate, msg->received);
++ snprintf (buf, sizeof (buf), "APPEND %s (%s%s%s%s%s) \"%s\" {%lu}", mbox,
+ msg->flags.read ? "\\Seen" : "",
+ msg->flags.read && (msg->flags.replied || msg->flags.flagged) ? " " : "",
+ msg->flags.replied ? "\\Answered" : "",
+ msg->flags.replied && msg->flags.flagged ? " " : "",
+ msg->flags.flagged ? "\\Flagged" : "",
++ internaldate,
+ (unsigned long) len);
+
+ imap_cmd_start (idata, buf);
+--- a/imap/util.c
++++ b/imap/util.c
+@@ -577,6 +577,21 @@ time_t imap_parse_date (char *s)
+ return (mutt_mktime (&t, 0) + tz);
+ }
+
++/* format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz.
++ * Caller should provide a buffer of IMAP_DATELEN bytes */
++void imap_make_date (char *buf, time_t timestamp)
++{
++ struct tm* tm = localtime (×tamp);
++ time_t tz = mutt_local_tz (timestamp);
++
++ tz /= 60;
++
++ snprintf (buf, IMAP_DATELEN, "%02d-%s-%d %02d:%02d:%02d %+03d%02d",
++ tm->tm_mday, Months[tm->tm_mon], tm->tm_year + 1900,
++ tm->tm_hour, tm->tm_min, tm->tm_sec,
++ (int) tz / 60, (int) abs (tz) % 60);
++}
++
+ /* imap_qualify_path: make an absolute IMAP folder target, given IMAP_MBOX
+ * and relative path. */
+ void imap_qualify_path (char *dest, size_t len, IMAP_MBOX *mx, char* path)