From 556aee757ccf0e84e6398f19f5211a49149c0508 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Thu, 4 Nov 1999 07:48:35 +0000 Subject: [PATCH] IMAP postpone changes from Byrial Jensen. --- buffy.c | 9 +++++---- globals.h | 1 - postpone.c | 53 +++++++++++++++++++++++++++++++++++++++++------------ protos.h | 3 ++- send.c | 6 +++--- status.c | 2 +- 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/buffy.c b/buffy.c index 15cfb9e1..39a3e2d4 100644 --- a/buffy.c +++ b/buffy.c @@ -240,11 +240,12 @@ int mutt_buffy_check (int force) else last_imap_check = now; } -#endif - /* update postponed count on force */ - if (force && Postponed) - mutt_num_postponed (); + /* update postponed count as well, on force */ + if (force) + mutt_update_num_postponed (); + +#endif /* fastest return if there are no mailboxes */ if (!Incoming) diff --git a/globals.h b/globals.h index 1de45f52..36ed6350 100644 --- a/globals.h +++ b/globals.h @@ -126,7 +126,6 @@ WHERE short HistSize; WHERE short PagerContext; WHERE short PagerIndexLines; WHERE short PopPort; -WHERE short PostCount INITVAL(0); WHERE short ReadInc; WHERE short SendmailWait; WHERE short Timeout; diff --git a/postpone.c b/postpone.c index a5aebf62..c159322d 100644 --- a/postpone.c +++ b/postpone.c @@ -48,35 +48,59 @@ static struct mapping_t PostponeHelp[] = { #endif /* _PGPPATH */ - -static time_t LastModify = 0; +static short PostCount = 0; static CONTEXT *PostContext = NULL; +static short UpdateNumPostponed = 0; -int mutt_num_postponed (void) +/* Return the number of postponed messages. + * if force is 0, use a cached value if it is costly to get a fresh + * count (IMAP) - else check. + */ +int mutt_num_postponed (int force) { struct stat st; CONTEXT ctx; + static time_t LastModify = 0; + static char *OldPostponed = NULL; + + if (UpdateNumPostponed) + { + UpdateNumPostponed = 0; + force = 1; + } + + if (Postponed != OldPostponed) + { + OldPostponed = Postponed; + LastModify = 0; + force = 1; + } + + if (!Postponed) + return 0; + #ifdef USE_IMAP /* LastModify is useless for IMAP */ - if (Postponed && mx_is_imap (Postponed)) + if (mx_is_imap (Postponed)) { - PostCount = imap_mailbox_check (Postponed, 0); - PostCount = (PostCount < 0) ? 0 : PostCount; - dprint(2, (debugfile, - "mutt_num_postponed: %d postponed IMAP messages found.\n", PostCount)); - + if (force) + { + PostCount = imap_mailbox_check (Postponed, 0); + PostCount = (PostCount < 0) ? 0 : PostCount; + dprint(2, (debugfile, + "mutt_num_postponed: %d postponed IMAP messages found.\n", PostCount)); + } return PostCount; } #endif - if (!Postponed || stat (Postponed, &st) == -1) + if (stat (Postponed, &st) == -1) { PostCount = 0; LastModify = 0; return (0); - } - + } if (S_ISDIR (st.st_mode)) { @@ -109,6 +133,11 @@ int mutt_num_postponed (void) return (PostCount); } +void mutt_update_num_postponed (void) +{ + UpdateNumPostponed = 1; +} + static void post_entry (char *s, size_t slen, MUTTMENU *menu, int entry) { CONTEXT *ctx = (CONTEXT *) menu->data; diff --git a/protos.h b/protos.h index e865bc8c..c1dd427c 100644 --- a/protos.h +++ b/protos.h @@ -238,7 +238,7 @@ int mutt_is_text_type (int, char *); int mutt_is_valid_mailbox (const char *); int mutt_multi_choice (char *prompt, char *letters); int mutt_needs_mailcap (BODY *); -int mutt_num_postponed (void); +int mutt_num_postponed (int); int mutt_parse_bind (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_exec (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_color (BUFFER *, BUFFER *, unsigned long, BUFFER *); @@ -263,6 +263,7 @@ int mutt_search_command (int, int); int mutt_compose_menu (HEADER *, char *, size_t, HEADER *); int mutt_thread_set_flag (HEADER *, int, int, int); int mutt_user_is_recipient (HEADER *); +void mutt_update_num_postponed (void); int mutt_view_attachment (FILE*, BODY *, int); int mutt_wait_filter (pid_t); int mutt_which_case (const char *); diff --git a/send.c b/send.c index 2a0b6bb3..afa4c74d 100644 --- a/send.c +++ b/send.c @@ -903,7 +903,8 @@ ci_send_message (int flags, /* send mode */ char *signmic = NULL; #endif - if (!flags && !msg && quadoption (OPT_RECALL) != M_NO && mutt_num_postponed ()) + if (!flags && !msg && quadoption (OPT_RECALL) != M_NO && + mutt_num_postponed (1)) { /* If the user is composing a new message, check to see if there * are any postponed messages first. @@ -1204,9 +1205,8 @@ main_loop: msg->content = mutt_remove_multipart (msg->content); goto main_loop; } + mutt_update_num_postponed (); mutt_message _("Message postponed."); - PostCount++; - mutt_num_postponed (); goto cleanup; } } diff --git a/status.c b/status.c index a53703de..44fb1e54 100644 --- a/status.c +++ b/status.c @@ -176,7 +176,7 @@ status_format_str (char *buf, size_t buflen, char op, const char *src, break; case 'p': - count = PostCount; + count = mutt_num_postponed (0); if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sd", prefix); -- 2.40.0