Kevin J. McCarthy wrote: > Someone trying to use mutt with FastMail was having a problem where a > postponed message was not editable in the web ui. It turns out it was > because the message, when saved, did not include the IMAP \Draft flag.
Attached is a slightly revised version of this patch. The main difference with this version is a refactoring of the IMAP flag generation code. The previous patch added one flag too many to set using ternary operators. I'd appreciate any feedback or people willing to test the patch and report back. Thanks, -Kevin
# HG changeset patch # User Kevin McCarthy <[email protected]> # Date 1421360333 28800 # Thu Jan 15 14:18:53 2015 -0800 # Node ID b1b72da0e849739e829ea0a1ec565df585c5d7b5 # Parent d732298789f254b738701893c84446a02c181725 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. diff --git a/imap/message.c b/imap/message.c --- a/imap/message.c +++ b/imap/message.c @@ -596,16 +596,17 @@ int imap_append_message (CONTEXT *ctx, MESSAGE *msg) { IMAP_DATA* idata; FILE *fp; char buf[LONG_STRING]; 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; int c, last; IMAP_MBOX mx; int rc; idata = (IMAP_DATA*) ctx->data; @@ -638,22 +639,29 @@ } rewind (fp); mutt_progress_init (&progressbar, _("Uploading message..."), M_PROGRESS_SIZE, NetInc, len); 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); imap_cmd_start (idata, buf); do rc = imap_cmd_step (idata); while (rc == IMAP_CMD_CONTINUE); diff --git a/mailbox.h b/mailbox.h --- a/mailbox.h +++ b/mailbox.h @@ -24,17 +24,18 @@ #define M_APPEND (1<<1) /* open mailbox for appending messages */ #define M_READONLY (1<<2) /* open in read-only mode */ #define M_QUIET (1<<3) /* do not print any messages */ #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses * safe_fopen() for mbox-style folders. */ /* 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 { M_NEW_MAIL = 1, /* new mail received in mailbox */ M_LOCKED, /* couldn't lock the mailbox */ M_REOPENED, /* mailbox was reopened */ M_FLAGS /* nondestructive flags change (IMAP) */ @@ -45,16 +46,17 @@ FILE *fp; /* pointer to the message data */ char *path; /* path to temp file */ short magic; /* type of mailbox this message belongs to */ short write; /* nonzero if message is open for writing */ 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; CONTEXT *mx_open_mailbox (const char *, int, CONTEXT *); MESSAGE *mx_open_message (CONTEXT *, int); MESSAGE *mx_open_new_message (CONTEXT *, HEADER *, int); diff --git a/mx.c b/mx.c --- a/mx.c +++ b/mx.c @@ -1250,16 +1250,17 @@ msg->magic = dest->magic; msg->write = 1; if (hdr) { 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; } if(msg->received == 0) time(&msg->received); if (func (msg, dest, hdr) == 0) { diff --git a/sendlib.c b/sendlib.c --- a/sendlib.c +++ b/sendlib.c @@ -2691,16 +2691,17 @@ { CONTEXT f; MESSAGE *msg; char tempfile[_POSIX_PATH_MAX]; FILE *tempfp = NULL; int r, need_buffy_cleanup = 0; struct stat st; char buf[SHORT_STRING]; + int onm_flags; if (post) set_noconv_flags (hdr->content, 1); if (mx_open_mailbox (path, M_APPEND | M_QUIET, &f) == NULL) { dprint (1, (debugfile, "mutt_write_fcc(): unable to open mailbox %s in append-mode, aborting.\n", path)); @@ -2720,17 +2721,20 @@ return (-1); } /* remember new mail status before appending message */ need_buffy_cleanup = 1; stat (path, &st); } 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); } /* post == 1 => postpone message. Set mode = -1 in mutt_write_rfc822_header() * post == 0 => Normal mode. Set mode = 0 in mutt_write_rfc822_header() * */
signature.asc
Description: PGP signature
