maildir supports a 'P' flag which denotes the fact that a message has been 'passed' on (forwarded, bounced). notmuch syncs this to the 'passed' tag.
Per https://tools.ietf.org/html/rfc5788, IMAP has a user-defined flag (keyword) '$Forwarded' that is supported by many servers and clients these days. (Technically, one should check for '$Forwarded' in the server response.) Restructure mbsync's flag parser to accept keywords (flags starting with '$') but still bail out on unknown system flags (flags starting with '\'). Support '$Forwarded' as a first keyword since it maps to maildir's 'P' and needs to be sorted in between the system flags. Signed-off-by: Michael J Gruber <git...@grubix.eu> --- I haven't found a "contrib HOW-TO" but hope this is okay. I've checked that this works against a fairly standard IMAP server. The mbsync source code uses a hardcoded numbering of the flags/bits in several places - I hope I didn't miss any. Also, I'm not sure whether the change in numbering is a problem - but maildir flags need to be specified in alphabetical order, so 'P' has to go before 'R' and, therefore, shift the indices of 'R', 'S' and 'T'. I do hope that they are not recorded by bit number on disc somewhere (but only by flag character as per the maildir standard). src/drv_imap.c | 22 ++++++++++++---------- src/drv_maildir.c | 2 +- src/drv_proxy.c | 2 +- src/sync.c | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index 56d71cb..6b724e0 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -244,11 +244,12 @@ static int imap_deref( imap_store_t *ctx ); static void imap_invoke_bad_callback( imap_store_t *ctx ); static const char *Flags[] = { - "Draft", - "Flagged", - "Answered", - "Seen", - "Deleted", + "\\Draft", /* 'D' */ + "\\Flagged", /* 'F' */ + "$Forwarded", /* 'P' */ + "\\Answered", /* 'R' */ + "\\Seen", /* 'S' */ + "\\Deleted", /* 'T' */ }; static imap_cmd_t * @@ -986,18 +987,20 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED ) if (is_list( tmp )) { for (flags = tmp->child; flags; flags = flags->next) { if (is_atom( flags )) { - if (flags->val[0] == '\\') { /* ignore user-defined flags for now */ - if (!strcmp( "Recent", flags->val + 1)) { + if (flags->val[0] == '\\' || flags->val[0] == '$') { + if (!strcmp( "\\Recent", flags->val)) { status |= M_RECENT; goto flagok; } for (i = 0; i < as(Flags); i++) - if (!strcmp( Flags[i], flags->val + 1 )) { + if (!strcmp( Flags[i], flags->val)) { mask |= 1 << i; goto flagok; } - if (flags->val[1] == 'X' && flags->val[2] == '-') + if (flags->val[0] == '\\' && flags->val[1] == 'X' && flags->val[2] == '-') goto flagok; /* ignore system flag extensions */ + if (flags->val[0] == '$') + goto flagok; /* ignore unknown user-defined flags (keywords) */ error( "IMAP warning: unknown system flag %s\n", flags->val ); } flagok: ; @@ -2661,7 +2664,6 @@ imap_make_flags( int flags, char *buf ) for (i = d = 0; i < as(Flags); i++) if (flags & (1 << i)) { buf[d++] = ' '; - buf[d++] = '\\'; for (s = Flags[i]; *s; s++) buf[d++] = *s; } diff --git a/src/drv_maildir.c b/src/drv_maildir.c index c4dd6c7..c4bd165 100644 --- a/src/drv_maildir.c +++ b/src/drv_maildir.c @@ -108,7 +108,7 @@ debug( const char *msg, ... ) va_end( va ); } -static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' }; +static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' }; static uchar maildir_parse_flags( const char *info_prefix, const char *base ) diff --git a/src/drv_proxy.c b/src/drv_proxy.c index 5010f60..c295e07 100644 --- a/src/drv_proxy.c +++ b/src/drv_proxy.c @@ -55,7 +55,7 @@ debugn( const char *msg, ... ) va_end( va ); } -static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' }; +static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' }; static char * proxy_make_flags( int flags, char *buf ) diff --git a/src/sync.c b/src/sync.c index 8f2b4a2..1cf51bc 100644 --- a/src/sync.c +++ b/src/sync.c @@ -97,7 +97,7 @@ Fprintf( FILE *f, const char *msg, ... ) } -static const char Flags[] = { 'D', 'F', 'R', 'S', 'T' }; +static const char Flags[] = { 'D', 'F', 'P', 'R', 'S', 'T' }; static int parse_flags( const char *buf ) -- 2.16.1.397.g5f331b6805 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ isync-devel mailing list isync-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/isync-devel