From 83656db765909aba38129acaee2d1aceeb311610 Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Mon, 19 Dec 2005 17:15:12 +0000 Subject: [PATCH] Real support for the Old flag on IMAP. --- imap/auth_sasl.c | 2 +- imap/browse.c | 2 +- imap/imap.c | 27 ++++++++++++++++++++++++++- imap/imap_private.h | 1 + imap/message.c | 31 ++++++------------------------- imap/util.c | 2 +- mx.c | 4 ---- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index 6e0557c50..f3d203892 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-3 Brendan Cully + * Copyright (C) 2000-5 Brendan Cully * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/imap/browse.c b/imap/browse.c index 5e8b38200..ab17be503 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -1,6 +1,6 @@ /* * Copyright (C) 1996-9 Brandon Long - * Copyright (C) 1999-2002 Brendan Cully + * Copyright (C) 1999-2005 Brendan Cully * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/imap/imap.c b/imap/imap.c index fe2d7c118..98e56147a 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -846,10 +846,32 @@ static void imap_set_flag (IMAP_DATA* idata, int aclbit, int flag, const char *str, char *flags, size_t flsize) { if (mutt_bit_isset (idata->rights, aclbit)) - if (flag) + if (flag && imap_has_flag (idata->flags, str)) safe_strcat (flags, flsize, str); } +/* imap_has_flag: do a caseless comparison of the flag against a flag list, +* return 1 if found or flag list has '\*', 0 otherwise */ +int imap_has_flag (LIST* flag_list, const char* flag) +{ + if (!flag_list) + return 0; + + flag_list = flag_list->next; + while (flag_list) + { + if (!ascii_strncasecmp (flag_list->data, flag, strlen (flag_list->data))) + return 1; + + if (!ascii_strncmp (flag_list->data, "\\*", strlen (flag_list->data))) + return 1; + + flag_list = flag_list->next; + } + + return 0; +} + /* imap_make_msg_set: make an IMAP4rev1 UID message set out of a set of * headers, given a flag enum to filter on. * Params: idata: IMAP_DATA containing context containing header set @@ -949,6 +971,8 @@ int imap_sync_message (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd, imap_set_flag (idata, IMAP_ACL_SEEN, hdr->read, "\\Seen ", flags, sizeof (flags)); + imap_set_flag (idata, IMAP_ACL_WRITE, hdr->old, + "Old ", flags, sizeof (flags)); imap_set_flag (idata, IMAP_ACL_WRITE, hdr->flagged, "\\Flagged ", flags, sizeof (flags)); imap_set_flag (idata, IMAP_ACL_WRITE, hdr->replied, @@ -967,6 +991,7 @@ int imap_sync_message (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd, if (!*flags) { imap_set_flag (idata, IMAP_ACL_SEEN, 1, "\\Seen ", flags, sizeof (flags)); + imap_set_flag (idata, IMAP_ACL_WRITE, 1, "Old ", flags, sizeof (flags)); imap_set_flag (idata, IMAP_ACL_WRITE, 1, "\\Flagged ", flags, sizeof (flags)); imap_set_flag (idata, IMAP_ACL_WRITE, 1, "\\Answered ", flags, sizeof (flags)); imap_set_flag (idata, IMAP_ACL_DELETE, 1, "\\Deleted ", flags, sizeof (flags)); diff --git a/imap/imap_private.h b/imap/imap_private.h index 07be80968..35b6521c5 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -244,6 +244,7 @@ void imap_expunge_mailbox (IMAP_DATA* idata); void imap_logout (IMAP_DATA* idata); int imap_sync_message (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd, int *err_continue); +int imap_has_flag (LIST* flag_list, const char* flag); /* auth.c */ int imap_authenticate (IMAP_DATA* idata); diff --git a/imap/message.c b/imap/message.c index f0323bf09..40c35c71c 100644 --- a/imap/message.c +++ b/imap/message.c @@ -39,7 +39,6 @@ static void flush_buffer(char* buf, size_t* len, CONNECTION* conn); static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf, FILE* fp); -static int msg_has_flag (LIST* flag_list, const char* flag); static int msg_parse_fetch (IMAP_HEADER* h, char* s); static char* msg_parse_flags (IMAP_HEADER* h, char* s); @@ -815,7 +814,7 @@ void imap_add_keywords (char* s, HEADER* h, LIST* mailbox_flags, size_t slen) while (keywords) { - if (msg_has_flag (mailbox_flags, keywords->data)) + if (imap_has_flag (mailbox_flags, keywords->data)) { safe_strcat (s, slen, keywords->data); safe_strcat (s, slen, " "); @@ -987,26 +986,6 @@ static int msg_fetch_header_fetch (CONTEXT* ctx, IMAP_HEADER* h, char* buf, FILE } #endif /* USE_HCACHE */ - -/* msg_has_flag: do a caseless comparison of the flag against a flag list, - * return 1 if found or flag list has '\*', 0 otherwise */ -static int msg_has_flag (LIST* flag_list, const char* flag) -{ - if (!flag_list) - return 0; - - flag_list = flag_list->next; - while (flag_list) - { - if (!ascii_strncasecmp (flag_list->data, flag, strlen (flag_list->data))) - return 1; - - flag_list = flag_list->next; - } - - return 0; -} - /* msg_parse_fetch: handle headers returned from header fetch */ static int msg_parse_fetch (IMAP_HEADER *h, char *s) { @@ -1131,6 +1110,11 @@ static char* msg_parse_flags (IMAP_HEADER* h, char* s) s += 7; recent = 1; } + else if (ascii_strncasecmp ("old", s, 3) == 0) + { + s += 3; + h->old = 1; + } else { /* store custom flags as well */ @@ -1153,9 +1137,6 @@ static char* msg_parse_flags (IMAP_HEADER* h, char* s) /* wrap up, or note bad flags response */ if (*s == ')') { - /* if a message is neither seen nor recent, it is OLD. */ - if (option (OPTMARKOLD) && !recent && !(h->read)) - h->old = 1; s++; } else diff --git a/imap/util.c b/imap/util.c index 1814ac327..da42d2f4d 100644 --- a/imap/util.c +++ b/imap/util.c @@ -1,7 +1,7 @@ /* * Copyright (C) 1996-8 Michael R. Elkins * Copyright (C) 1996-9 Brandon Long - * Copyright (C) 1999-2002 Brendan Cully + * Copyright (C) 1999-2005 Brendan Cully * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/mx.c b/mx.c index 473c927dd..bb7566e02 100644 --- a/mx.c +++ b/mx.c @@ -900,10 +900,6 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint) } } -#ifdef USE_IMAP - /* IMAP servers manage the OLD flag themselves */ - if (ctx->magic != M_IMAP) -#endif if (option (OPTMARKOLD)) { for (i = 0; i < ctx->msgcount; i++) -- 2.40.0