From 10975dfebcaa8f877d58288011b24ba98e8a606b Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Thu, 15 Jan 2015 14:18:53 -0800 Subject: [PATCH] Send the IMAP \Draft flag when postponing a message. This patch adds a mx_open_new_message() flag, M_SET_DRAFT. It also adds a MESSAGE->flags.draft flag. mutt_write_fcc() passes the M_SET_DRAFT flag to mx_open_new_message(), which then sets MESSAGE->flags.draft. Then, imap_append_message() is able to see this flag and so adds the \Draft flag. The imap_append_message() function started to have a bit too many flags, so this version of the patch separates out the flag generating code into a simpler version. --- imap/message.c | 20 ++++++++++++++------ mailbox.h | 4 +++- mx.c | 1 + sendlib.c | 6 +++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/imap/message.c b/imap/message.c index 5cfbb1fe9..09e14633c 100644 --- a/imap/message.c +++ b/imap/message.c @@ -601,6 +601,7 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) char mbox[LONG_STRING]; char mailbox[LONG_STRING]; char internaldate[IMAP_DATELEN]; + char imap_flags[SHORT_STRING]; size_t len; progress_t progressbar; size_t sent; @@ -643,12 +644,19 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) imap_munge_mbox_name (mbox, sizeof (mbox), mailbox); 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" : "", + + imap_flags[0] = imap_flags[1] = 0; + if (msg->flags.read) + safe_strcat (imap_flags, sizeof (imap_flags), " \\Seen"); + if (msg->flags.replied) + safe_strcat (imap_flags, sizeof (imap_flags), " \\Answered"); + if (msg->flags.flagged) + safe_strcat (imap_flags, sizeof (imap_flags), " \\Flagged"); + if (msg->flags.draft) + safe_strcat (imap_flags, sizeof (imap_flags), " \\Draft"); + + snprintf (buf, sizeof (buf), "APPEND %s (%s) \"%s\" {%lu}", mbox, + imap_flags + 1, internaldate, (unsigned long) len); diff --git a/mailbox.h b/mailbox.h index 91e5dc71e..2b2c9a13d 100644 --- a/mailbox.h +++ b/mailbox.h @@ -29,7 +29,8 @@ */ /* mx_open_new_message() */ -#define M_ADD_FROM 1 /* add a From_ line */ +#define M_ADD_FROM (1<<0) /* add a From_ line */ +#define M_SET_DRAFT (1<<1) /* set the message draft flag */ /* return values from mx_check_mailbox() */ enum @@ -50,6 +51,7 @@ typedef struct unsigned read : 1; unsigned flagged : 1; unsigned replied : 1; + unsigned draft : 1; } flags; time_t received; /* the time at which this message was received */ } MESSAGE; diff --git a/mx.c b/mx.c index f599f6c77..4c5cb07de 100644 --- a/mx.c +++ b/mx.c @@ -1255,6 +1255,7 @@ MESSAGE *mx_open_new_message (CONTEXT *dest, HEADER *hdr, int flags) msg->flags.flagged = hdr->flagged; msg->flags.replied = hdr->replied; msg->flags.read = hdr->read; + msg->flags.draft = (flags & M_SET_DRAFT) ? 1 : 0; msg->received = hdr->received; } diff --git a/sendlib.c b/sendlib.c index f364f9f1e..f811ad21a 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2696,6 +2696,7 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, int r, need_buffy_cleanup = 0; struct stat st; char buf[SHORT_STRING]; + int onm_flags; if (post) set_noconv_flags (hdr->content, 1); @@ -2725,7 +2726,10 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, } hdr->read = !post; /* make sure to put it in the `cur' directory (maildir) */ - if ((msg = mx_open_new_message (&f, hdr, M_ADD_FROM)) == NULL) + onm_flags = M_ADD_FROM; + if (post) + onm_flags |= M_SET_DRAFT; + if ((msg = mx_open_new_message (&f, hdr, onm_flags)) == NULL) { mx_close_mailbox (&f, NULL); return (-1); -- 2.40.0