From 9a1805afc94b21d8766e6e67ef57f92aaf966e84 Mon Sep 17 00:00:00 2001 From: pdmef Date: Wed, 27 Apr 2005 19:24:34 +0000 Subject: [PATCH] Rocco Rutte - modularize mx_fastclos_mailbox + mx_sync_mailbox - move buffy protos to buffy.h + proper rename - stop scoring while mx_open_mailbox for sidebar counting (should speed a lot if used with scoring and mbox) git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@276 e385b8ad-14ed-0310-8656-cc95a2468c6d --- browser.c | 12 ++++---- buffy.c | 34 ++++++++++----------- buffy.h | 24 +++++++++------ commands.c | 2 +- compose.c | 3 +- curs_main.c | 14 ++++----- enter.c | 3 +- imap/mx_imap.c | 2 ++ init.h | 4 +-- main.c | 4 +-- mbox.c | 38 +++++++++++++++++------- mbox.h | 10 ++----- mh.c | 12 +++++--- mh.h | 7 ++--- mutt.h | 1 + mx.c | 80 ++++++++++---------------------------------------- mx.h | 10 +++++-- nntp/mx_nntp.c | 2 ++ nntp/nntp.c | 4 +-- nntp/nntp.h | 2 +- pager.c | 3 +- pop/mx_pop.c | 2 ++ pop/pop.c | 2 +- pop/pop.h | 2 +- protos.h | 5 ---- sidebar.c | 2 +- sidebar.h | 2 +- status.c | 5 ++-- 28 files changed, 136 insertions(+), 155 deletions(-) diff --git a/browser.c b/browser.c index 7f839c9..7c860de 100644 --- a/browser.c +++ b/browser.c @@ -478,7 +478,7 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, NNTP_DATA *data; NNTP_SERVER *news = CurrentNewsSrv; -/* mutt_buffy_check (0); */ +/* buffy_check (0); */ init_state (state, menu); for (tmp = news->list; tmp; tmp = tmp->next) { @@ -520,7 +520,7 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, return (-1); } - mutt_buffy_check (0); + buffy_check (0); if ((dp = opendir (d)) == NULL) { mutt_perror (d); @@ -569,7 +569,7 @@ static int examine_mailboxes (MUTTMENU * menu, struct browser_state *state) NNTP_DATA *data; NNTP_SERVER *news = CurrentNewsSrv; -/* mutt_buffy_check (0); */ +/* buffy_check (0); */ init_state (state, menu); for (tmp = news->list; tmp; tmp = tmp->next) { @@ -590,7 +590,7 @@ static int examine_mailboxes (MUTTMENU * menu, struct browser_state *state) if (!Incoming) return (-1); - mutt_buffy_check (0); + buffy_check (0); init_state (state, menu); @@ -687,7 +687,7 @@ static void init_menu (struct browser_state *state, MUTTMENU * menu, else #endif if (buffy) - snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0)); + snprintf (title, titlelen, _("Mailboxes [%d]"), buffy_check (0)); else { strfcpy (path, LastDir, sizeof (path)); mutt_pretty_mailbox (path); @@ -1306,7 +1306,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, break; case OP_BUFFY_LIST: - mutt_buffy_list (); + buffy_list (); break; case OP_BROWSER_NEW_FILE: diff --git a/buffy.c b/buffy.c index 24663cb..9824b6b 100644 --- a/buffy.c +++ b/buffy.c @@ -51,7 +51,7 @@ static short BuffyNotify = 0; /* # of unnotified new boxes */ /* Find the last message in the file. * upon success return 0. If no message found - return -1 */ -int fseek_last_message (FILE * f) +static int fseek_last_message (FILE * f) { long int pos; char buffer[BUFSIZ + 9]; /* 7 for "\n\nFrom " */ @@ -94,7 +94,7 @@ int fseek_last_message (FILE * f) } /* Return 1 if the last message is new */ -int test_last_status_new (FILE * f) +static int test_last_status_new (FILE * f) { HEADER *hdr; ENVELOPE *tmp_envelope; @@ -114,7 +114,7 @@ int test_last_status_new (FILE * f) return result; } -int test_new_folder (const char *path) +static int test_new_folder (const char *path) { FILE *f; int rc = 0; @@ -133,7 +133,7 @@ int test_new_folder (const char *path) return rc; } -BUFFY *mutt_find_mailbox (const char *path) +BUFFY *buffy_find_mailbox (const char *path) { struct stat sb; struct stat tmp_sb; @@ -152,7 +152,7 @@ BUFFY *mutt_find_mailbox (const char *path) return (NULL); } -void mutt_update_mailbox (BUFFY * b) +void buffy_update_mailbox (BUFFY * b) { struct stat sb; @@ -184,7 +184,7 @@ int buffy_lookup (const char* path) { return (-1); } -int mutt_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, +int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, BUFFER * err) { BUFFY* tmp; @@ -261,7 +261,7 @@ int mutt_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, * 1 force all checks + update sidebar * 2 force all checks + _don't_ update sidebar */ -int mutt_buffy_check (int force) +int buffy_check (int force) { BUFFY *tmp; struct stat sb; @@ -353,7 +353,7 @@ int mutt_buffy_check (int force) /* sidebar visible */ BuffyCount++; if ((ctx = - mx_open_mailbox (tmp->path, M_READONLY | M_QUIET | M_NOSORT, + mx_open_mailbox (tmp->path, M_READONLY | M_QUIET | M_NOSORT | M_COUNT, NULL)) != NULL) { tmp->msgcount = ctx->msgcount; tmp->new = ctx->new; @@ -495,7 +495,7 @@ int mutt_buffy_check (int force) return (BuffyCount); } -int mutt_buffy_list (void) +int buffy_list (void) { BUFFY *tmp; char path[_POSIX_PATH_MAX]; @@ -506,7 +506,7 @@ int mutt_buffy_list (void) int i = 0; if (option (OPTFORCEBUFFYCHECK)) - mutt_buffy_check (1); + buffy_check (1); pos = 0; first = 1; @@ -554,10 +554,10 @@ int mutt_buffy_list (void) return (0); } -int mutt_buffy_notify (void) +int buffy_notify (void) { - if (mutt_buffy_check (0) && BuffyNotify) { - return (mutt_buffy_list ()); + if (buffy_check (0) && BuffyNotify) { + return (buffy_list ()); } return (0); } @@ -568,7 +568,7 @@ int mutt_buffy_notify (void) * given a folder name, this routine gives the next incoming folder with new * new mail. */ -void mutt_buffy (char *s, size_t slen) +void buffy_next (char *s, size_t slen) { int i = 0, c = 0; @@ -576,7 +576,7 @@ void mutt_buffy (char *s, size_t slen) return; mutt_expand_path (s, _POSIX_PATH_MAX); - if (mutt_buffy_check (0) == 0) { + if (buffy_check (0) == 0) { *s = '\0'; return; } @@ -590,9 +590,9 @@ void mutt_buffy (char *s, size_t slen) } if (c == i) { *s = '\0'; - /* something went wrong since we're here when mutt_buffy_check + /* something went wrong since we're here when buffy_check * reported new mail */ - mutt_buffy_check (0); + buffy_check (0); } else { strfcpy (s, ((BUFFY*) Incoming->data[c])->path, slen); mutt_pretty_mailbox (s); diff --git a/buffy.h b/buffy.h index 469ac46..857f594 100644 --- a/buffy.h +++ b/buffy.h @@ -30,21 +30,27 @@ typedef struct buffy_t { short newly_created; /* mbox or mmdf just popped into existence */ } BUFFY; +/* folders with incomming mail (via mailboxes command) */ WHERE list2_t* Incoming; WHERE short BuffyTimeout INITVAL (3); +extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */ -/* - * looks up a path in Incoming list - * there needs to be an extra function since we have everything but - * object of type BUFFY when we want to a do a lookup ;-( - */ +/* looks up a path in Incoming list (returns index) */ int buffy_lookup (const char*); - -extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */ +/* handles mailboxes commands */ +int buffy_parse_mailboxes (BUFFER*, BUFFER*, unsigned long, BUFFER*); +/* from given path, gets next mailbox in Incoming with new mail */ +void buffy_next (char*, size_t); +/* checks mailboxes for new mail (returns number) */ +int buffy_check (int); +/* lists mailboxes with new mail */ +int buffy_list (void); +/* wrapper around buffy_list() */ +int buffy_notify (void); #ifdef BUFFY_SIZE -BUFFY *mutt_find_mailbox (const char *path); -void mutt_update_mailbox (BUFFY * b); +BUFFY *buffy_find_mailbox (const char *path); +void buffy_update_mailbox (BUFFY * b); #endif #endif /* !_BUFFY_H */ diff --git a/commands.c b/commands.c index b50f9d5..a5255d5 100644 --- a/commands.c +++ b/commands.c @@ -779,7 +779,7 @@ int mutt_save_message (HEADER * h, int delete, #ifdef BUFFY_SIZE tmp = mutt_find_mailbox (buf); if (tmp && tmp->new <= 0) - mutt_update_mailbox (tmp); + buffy_update_mailbox (tmp); #else /* fix up the times so buffy won't get confused */ if (st.st_mtime > st.st_atime) { diff --git a/compose.c b/compose.c index e8598db..960f124 100644 --- a/compose.c +++ b/compose.c @@ -26,6 +26,7 @@ #include "sort.h" #include "charset.h" #include "mx.h" +#include "buffy.h" #include "compose.h" #ifdef MIXMASTER @@ -562,7 +563,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ ComposeHelp); if (option (OPTMBOXPANE)) - mutt_buffy_check (1); + buffy_check (1); while (loop) { #ifdef USE_NNTP unset_option (OPTNEWS); /* for any case */ diff --git a/curs_main.c b/curs_main.c index 2365958..8cf1dff 100644 --- a/curs_main.c +++ b/curs_main.c @@ -444,7 +444,7 @@ int mutt_index_menu (void) IndexHelp); if (!attach_msg) { - mutt_buffy_check (1); /* force the buffy check after we enter the folder */ + buffy_check (1); /* force the buffy check after we enter the folder */ /* record folder we open to place sidebar indicator properly */ if (Context && Context->path) sidebar_set_current (Context->path); @@ -529,12 +529,12 @@ int mutt_index_menu (void) if (!attach_msg) { /* check for new mail in the incoming folders */ oldcount = newcount; - if ((newcount = mutt_buffy_check (0)) != oldcount) { + if ((newcount = buffy_check (0)) != oldcount) { menu->redraw |= REDRAW_STATUS; menu->redraw |= REDRAW_SIDEBAR; } if (do_buffy_notify) { - if (mutt_buffy_notify () && option (OPTBEEPNEW)) + if (buffy_notify () && option (OPTBEEPNEW)) beep (); } else @@ -1203,7 +1203,7 @@ int mutt_index_menu (void) { if (Context && Context->path) strncpy (buf, Context->path, sizeof (buf)); - mutt_buffy (buf, sizeof (buf)); + buffy_next (buf, sizeof (buf)); } if (op == OP_SIDEBAR_OPEN) { @@ -1272,7 +1272,7 @@ int mutt_index_menu (void) menu->current = 0; #ifdef USE_NNTP - /* mutt_buffy_check() must be done with mail-reader mode! */ + /* buffy_check() must be done with mail-reader mode! */ menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN, (Context && (Context->magic == @@ -1280,7 +1280,7 @@ int mutt_index_menu (void) IndexHelp); #endif mutt_clear_error (); - mutt_buffy_check (1); /* force the buffy check after we have changed + buffy_check (1); /* force the buffy check after we have changed the folder */ menu->redraw = REDRAW_FULL; set_option (OPTSEARCHINVALID); @@ -2277,7 +2277,7 @@ int mutt_index_menu (void) break; case OP_BUFFY_LIST: - mutt_buffy_list (); + buffy_list (); menu->redraw = REDRAW_FULL; break; diff --git a/enter.c b/enter.c index 1f5d6c3..3084644 100644 --- a/enter.c +++ b/enter.c @@ -17,6 +17,7 @@ #include "mutt_curses.h" #include "keymap.h" #include "history.h" +#include "buffy.h" #include "lib/mem.h" @@ -439,7 +440,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, if (flags & M_EFILE) { first = 1; /* clear input if user types a real key later */ my_wcstombs (buf, buflen, state->wbuf, state->curpos); - mutt_buffy (buf, buflen); + buffy_next (buf, buflen); state->curpos = state->lastchar = my_mbstowcs (&state->wbuf, &state->wbuflen, 0, buf); break; diff --git a/imap/mx_imap.c b/imap/mx_imap.c index f0aee59..2d3797b 100644 --- a/imap/mx_imap.c +++ b/imap/mx_imap.c @@ -44,5 +44,7 @@ mx_t* imap_reg_mx (void) { fmt->mx_access = imap_access; fmt->mx_open_mailbox = imap_open_mailbox; fmt->mx_acl_check = acl_check_imap; + fmt->mx_fastclose_mailbox = imap_close_mailbox; + fmt->mx_sync_mailbox = imap_sync_mailbox; return (fmt); } diff --git a/init.h b/init.h index 1676acd..fc547b7 100644 --- a/init.h +++ b/init.h @@ -3835,8 +3835,8 @@ struct command_t Commands[] = { {"ignore", parse_ignore, 0}, {"lists", parse_lists, 0}, {"macro", mutt_parse_macro, 0}, - {"mailboxes", mutt_parse_mailboxes, M_MAILBOXES}, - {"unmailboxes", mutt_parse_mailboxes, M_UNMAILBOXES}, + {"mailboxes", buffy_parse_mailboxes, M_MAILBOXES}, + {"unmailboxes", buffy_parse_mailboxes, M_UNMAILBOXES}, {"message-hook", mutt_parse_hook, M_MESSAGEHOOK}, {"mbox-hook", mutt_parse_hook, M_MBOXHOOK}, {"mime_lookup", parse_list, UL &MimeLookupList}, diff --git a/main.c b/main.c index b8c2016..a2805f8 100644 --- a/main.c +++ b/main.c @@ -883,13 +883,13 @@ int main (int argc, char **argv) } else { if (flags & M_BUFFY) { - if (!mutt_buffy_check (0)) { + if (!buffy_check (0)) { mutt_endwin _("No mailbox with new mail."); exit (1); } folder[0] = 0; - mutt_buffy (folder, sizeof (folder)); + buffy_next (folder, sizeof (folder)); } else if (flags & M_SELECT) { #ifdef USE_NNTP diff --git a/mbox.c b/mbox.c index bafb7f3..b906bfe 100644 --- a/mbox.c +++ b/mbox.c @@ -15,6 +15,7 @@ #include "mutt.h" #include "mx.h" +#include "buffy.h" #include "mbox.h" #include "sort.h" #include "copy.h" @@ -52,6 +53,9 @@ int mbox_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) return 0; } +/* prototypes */ +static int mbox_reopen_mailbox (CONTEXT*, int*); + /* parameters: * ctx - context to lock * excl - exclusive lock? @@ -81,7 +85,7 @@ void mbox_unlock_mailbox (CONTEXT * ctx) } } -int mmdf_parse_mailbox (CONTEXT * ctx) +static int mmdf_parse_mailbox (CONTEXT * ctx) { char buf[HUGE_STRING]; char return_path[LONG_STRING]; @@ -219,7 +223,7 @@ int mmdf_parse_mailbox (CONTEXT * ctx) * NOTE: it is assumed that the mailbox being read has been locked before * this routine gets called. Strange things could happen if it's not! */ -int mbox_parse_mailbox (CONTEXT * ctx) +static int mbox_parse_mailbox (CONTEXT * ctx) { struct stat sb; char buf[HUGE_STRING], return_path[STRING]; @@ -388,7 +392,7 @@ int mbox_parse_mailbox (CONTEXT * ctx) #undef PREV /* open a mbox or mmdf style mailbox */ -int mbox_open_mailbox (CONTEXT * ctx) +static int mbox_open_mailbox (CONTEXT * ctx) { int rc; @@ -631,7 +635,7 @@ int mbox_check_mailbox (CONTEXT * ctx, int *index_hint) * 0 success * -1 failure */ -int mbox_sync_mailbox (CONTEXT * ctx, int *index_hint) +static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) { char tempfile[_POSIX_PATH_MAX]; char buf[32]; @@ -713,7 +717,7 @@ int mbox_sync_mailbox (CONTEXT * ctx, int *index_hint) mutt_error _("sync: mbox modified, but no modified messages! (report this bug)"); mutt_sleep (5); /* the mutt_error /will/ get cleared! */ - dprint (1, (debugfile, "mbox_sync_mailbox(): no modified messages.\n")); + dprint (1, (debugfile, "_mbox_sync_mailbox(): no modified messages.\n")); unlink (tempfile); goto bail; } @@ -809,7 +813,7 @@ int mbox_sync_mailbox (CONTEXT * ctx, int *index_hint) if (fclose (fp) != 0) { fp = NULL; dprint (1, - (debugfile, "mbox_sync_mailbox: fclose() returned non-zero.\n")); + (debugfile, "_mbox_sync_mailbox: fclose() returned non-zero.\n")); unlink (tempfile); mutt_perror (tempfile); mutt_sleep (5); @@ -830,7 +834,7 @@ int mbox_sync_mailbox (CONTEXT * ctx, int *index_hint) mx_fastclose_mailbox (ctx); dprint (1, (debugfile, - "mbox_sync_mailbox: unable to reopen temp copy of mailbox!\n")); + "_mbox_sync_mailbox: unable to reopen temp copy of mailbox!\n")); mutt_perror (tempfile); mutt_sleep (5); return (-1); @@ -843,14 +847,14 @@ int mbox_sync_mailbox (CONTEXT * ctx, int *index_hint) (ctx->magic == M_MMDF && safe_strcmp (MMDF_SEP, buf) != 0)) { dprint (1, (debugfile, - "mbox_sync_mailbox: message not in expected position.")); + "_mbox_sync_mailbox: message not in expected position.")); dprint (1, (debugfile, "\tLINE: %s\n", buf)); i = -1; } else { if (fseek (ctx->fp, offset, SEEK_SET) != 0) { /* return to proper offset */ i = -1; - dprint (1, (debugfile, "mbox_sync_mailbox: fseek() failed\n")); + dprint (1, (debugfile, "_mbox_sync_mailbox: fseek() failed\n")); } else { /* copy the temp mailbox back into place starting at the first @@ -964,6 +968,19 @@ bail: /* Come here in case of disaster */ return rc; } +static int mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) { +#ifdef BUFFY_SIZE + BUFFY* tmp = NULL; +#endif + int rc = _mbox_sync_mailbox (ctx, unused, index_hint); + +#ifdef BUFFY_SIZE + if ((tmp = buffy_find_mailbox (ctx->path)) && tmp->new == 0) + buffy_update_mailbox (tmp); +#endif + return (rc); +} + /* close a mailbox opened in write-mode */ int mbox_close_mailbox (CONTEXT * ctx) { @@ -979,7 +996,7 @@ int mbox_close_mailbox (CONTEXT * ctx) return 0; } -int mbox_reopen_mailbox (CONTEXT * ctx, int *index_hint) +static int mbox_reopen_mailbox (CONTEXT * ctx, int *index_hint) { int (*cmp_headers) (const HEADER *, const HEADER *) = NULL; HEADER **old_hdrs; @@ -1208,6 +1225,7 @@ static mx_t* reg_mx (void) { fmt->mx_is_magic = mbox_is_magic; fmt->mx_access = access; fmt->mx_open_mailbox = mbox_open_mailbox; + fmt->mx_sync_mailbox = mbox_sync_mailbox; return (fmt); } diff --git a/mbox.h b/mbox.h index 22adc66..8ea345a 100644 --- a/mbox.h +++ b/mbox.h @@ -19,23 +19,17 @@ #include "mx.h" +/* TODO all of these must disappear to achieve good information hiding */ + #define MMDF_SEP "\001\001\001\001\n" -int mbox_sync_mailbox (CONTEXT *, int *); -int mbox_open_mailbox (CONTEXT *); int mbox_check_mailbox (CONTEXT *, int *); int mbox_close_mailbox (CONTEXT *); int mbox_lock_mailbox (CONTEXT *, int, int); -int mbox_parse_mailbox (CONTEXT *); -int mmdf_parse_mailbox (CONTEXT *); void mbox_unlock_mailbox (CONTEXT *); int mbox_check_empty (const char *); -/* this is still here for compressed folders support... */ int mbox_is_magic (const char*, struct stat*); - int mbox_strict_cmp_headers (const HEADER *, const HEADER *); -int mbox_reopen_mailbox (CONTEXT *, int *); - int mbox_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr); mx_t* mbox_reg_mx (void); diff --git a/mh.c b/mh.c index 5f3f369..17b1033 100644 --- a/mh.c +++ b/mh.c @@ -68,6 +68,9 @@ struct mh_sequences { #define MH_SEQ_REPLIED (1 << 1) #define MH_SEQ_FLAGGED (1 << 2) +/* prototypes */ +static int maildir_check_empty (const char*); + static void mhs_alloc (struct mh_sequences *mhs, int i) { int j; @@ -947,12 +950,12 @@ static int _mh_read_dir (CONTEXT * ctx, const char *subdir) return 0; } -int mh_read_dir (CONTEXT* ctx) { +static int mh_read_dir (CONTEXT* ctx) { return (_mh_read_dir (ctx, NULL)); } /* read a maildir style mailbox */ -int maildir_read_dir (CONTEXT * ctx) +static int maildir_read_dir (CONTEXT * ctx) { /* maildir looks sort of like MH, except that there are two subdirectories * of the main folder path from which to read messages @@ -1378,7 +1381,7 @@ static int maildir_sync_message (CONTEXT * ctx, int msgno) return (0); } -int mh_sync_mailbox (CONTEXT * ctx, int *index_hint) +static int mh_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) { char path[_POSIX_PATH_MAX], tmp[_POSIX_PATH_MAX]; int i, j; @@ -1871,7 +1874,7 @@ FILE *maildir_open_find_message (const char *folder, const char *msg) * 0 if there are messages in the mailbox * -1 on error */ -int maildir_check_empty (const char *path) +static int maildir_check_empty (const char *path) { DIR *dp; struct dirent *de; @@ -1980,6 +1983,7 @@ static mx_t* reg_mx (void) { mx_t* fmt = safe_calloc (1, sizeof (mx_t)); fmt->local = 1; fmt->mx_access = access; + fmt->mx_sync_mailbox = mh_sync_mailbox; return (fmt); } diff --git a/mh.h b/mh.h index cdc51d0..e395254 100644 --- a/mh.h +++ b/mh.h @@ -19,17 +19,14 @@ #include "mx.h" -int mh_read_dir (CONTEXT *); -int mh_sync_mailbox (CONTEXT *, int *); +/* TODO all of these must disappear to achieve good information hiding */ + int mh_check_mailbox (CONTEXT *, int *); int mh_buffy (const char *); -int mh_check_empty (const char *); int mh_commit_message (CONTEXT *, MESSAGE *, HEADER *); int mh_open_new_message (MESSAGE *, CONTEXT *, HEADER *); -int maildir_read_dir (CONTEXT *); int maildir_check_mailbox (CONTEXT *, int *); -int maildir_check_empty (const char *); int maildir_commit_message (CONTEXT *, MESSAGE *, HEADER *); int maildir_open_new_message (MESSAGE *, CONTEXT *, HEADER *); FILE *maildir_open_find_message (const char *, const char *); diff --git a/mutt.h b/mutt.h index ec32499..39b1508 100644 --- a/mutt.h +++ b/mutt.h @@ -885,6 +885,7 @@ typedef struct { unsigned int quiet:1; /* inhibit status messages? */ unsigned int collapsed:1; /* are all threads collapsed? */ unsigned int closing:1; /* mailbox is being closed */ + unsigned int counting:1; /* do we just want to cound? */ } CONTEXT; typedef struct attachptr { diff --git a/mx.c b/mx.c index 51fc1b3..54548b0 100644 --- a/mx.c +++ b/mx.c @@ -65,9 +65,7 @@ #include #include #include -#ifndef BUFFY_SIZE #include -#endif static list2_t* MailboxFormats = NULL; #define MX_COMMAND(idx,cmd) ((mx_t*) MailboxFormats->data[idx])->cmd @@ -529,6 +527,8 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx) ctx->quiet = 1; if (flags & M_READONLY) ctx->readonly = 1; + if (flags & M_COUNT) + ctx->counting = 1; if (flags & (M_APPEND | M_NEWFOLDER)) { if (mx_open_mailbox_append (ctx, flags) != 0) { @@ -602,18 +602,8 @@ void mx_fastclose_mailbox (CONTEXT * ctx) if (!ctx) return; -#ifdef USE_IMAP - if (ctx->magic == M_IMAP) - imap_close_mailbox (ctx); -#endif /* USE_IMAP */ -#ifdef USE_POP - if (ctx->magic == M_POP) - pop_close_mailbox (ctx); -#endif /* USE_POP */ -#ifdef USE_NNTP - if (ctx->magic == M_NNTP) - nntp_fastclose_mailbox (ctx); -#endif /* USE_NNTP */ + if (MX_IDX(ctx->magic-1) && MX_COMMAND(ctx->magic-1,mx_fastclose_mailbox)) + MX_COMMAND(ctx->magic-1,mx_fastclose_mailbox(ctx)); if (ctx->subj_hash) hash_destroy (&ctx->subj_hash, NULL); if (ctx->id_hash) @@ -638,57 +628,14 @@ void mx_fastclose_mailbox (CONTEXT * ctx) /* save changes to disk */ static int sync_mailbox (CONTEXT * ctx, int *index_hint) { -#ifdef BUFFY_SIZE - BUFFY *tmp = NULL; -#endif int rc = -1; if (!ctx->quiet) mutt_message (_("Writing %s..."), ctx->path); - switch (ctx->magic) { - case M_MBOX: - case M_MMDF: - rc = mbox_sync_mailbox (ctx, index_hint); -#ifdef BUFFY_SIZE - tmp = mutt_find_mailbox (ctx->path); -#endif - break; - - case M_MH: - case M_MAILDIR: - rc = mh_sync_mailbox (ctx, index_hint); - break; - -#ifdef USE_IMAP - case M_IMAP: - /* extra argument means EXPUNGE */ - rc = imap_sync_mailbox (ctx, 1, index_hint); - break; -#endif /* USE_IMAP */ - -#ifdef USE_POP - case M_POP: - rc = pop_sync_mailbox (ctx, index_hint); - break; -#endif /* USE_POP */ - -#ifdef USE_NNTP - case M_NNTP: - rc = nntp_sync_mailbox (ctx); - break; -#endif /* USE_NNTP */ - } - -#if 0 - if (!ctx->quiet && !ctx->shutup && rc == -1) - mutt_error (_("Could not synchronize mailbox %s!"), ctx->path); -#endif - -#ifdef BUFFY_SIZE - if (tmp && tmp->new == 0) - mutt_update_mailbox (tmp); -#endif + if (MX_IDX(ctx->magic-1)) + /* the 1 is only of interest for IMAP and means EXPUNGE */ + rc = MX_COMMAND(ctx->magic-1,mx_sync_mailbox(ctx,1,index_hint)); #ifdef USE_COMPRESSED if (rc == 0 && ctx->compressinfo) @@ -1520,7 +1467,7 @@ void mx_update_context (CONTEXT * ctx, int new_messages) /* FREE (&h->env->supersedes); should I ? */ if (h2) { h2->superseded = 1; - if (option (OPTSCORE)) + if (!ctx->counting && option (OPTSCORE)) mutt_score_message (ctx, h2, 1); } } @@ -1528,11 +1475,13 @@ void mx_update_context (CONTEXT * ctx, int new_messages) /* add this message to the hash tables */ if (ctx->id_hash && h->env->message_id) hash_insert (ctx->id_hash, h->env->message_id, h, 0); - if (ctx->subj_hash && h->env->real_subj) - hash_insert (ctx->subj_hash, h->env->real_subj, h, 1); + if (!ctx->counting) { + if (ctx->subj_hash && h->env->real_subj) + hash_insert (ctx->subj_hash, h->env->real_subj, h, 1); - if (option (OPTSCORE)) - mutt_score_message (ctx, h, 0); + if (option (OPTSCORE)) + mutt_score_message (ctx, h, 0); + } if (h->changed) ctx->changed = 1; @@ -1599,6 +1548,7 @@ void mx_init (void) { if (MX_COMMAND(i,type) < 1) EXITWITHERR("type"); if (!MX_COMMAND(i,mx_is_magic)) EXITWITHERR("mx_is_magic"); if (!MX_COMMAND(i,mx_open_mailbox)) EXITWITHERR("mx_open_mailbox"); +/* if (!MX_COMMAND(i,mx_sync_mailbox)) EXITWITHERR("mx_sync_mailbox");*/ } #undef EXITWITHERR #endif /* DEBUG */ diff --git a/mx.h b/mx.h index f2a4e59..57de519 100644 --- a/mx.h +++ b/mx.h @@ -18,6 +18,7 @@ #define _MX_H #include +#include /* * supported mailbox formats @@ -80,6 +81,10 @@ typedef struct { /* check ACL flags; if not implemented, always assume granted * permissions */ int (*mx_acl_check) (CONTEXT*, int); + /* fast closing */ + void (*mx_fastclose_mailbox) (CONTEXT*); + /* write out changes */ + int (*mx_sync_mailbox) (CONTEXT*, int, int*); } mx_t; /* called from main: init all folder types */ @@ -91,8 +96,9 @@ void mx_init (void); #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. - */ + * safe_fopen() for mbox-style folders. */ +#define M_COUNT (1<<5) /* just do counting? needed to do speed optimizations + for sidebar */ /* mx_open_new_message() */ #define M_ADD_FROM 1 /* add a From_ line */ diff --git a/nntp/mx_nntp.c b/nntp/mx_nntp.c index 9de796f..8d918e6 100644 --- a/nntp/mx_nntp.c +++ b/nntp/mx_nntp.c @@ -47,5 +47,7 @@ mx_t* nntp_reg_mx (void) { fmt->mx_is_magic = nntp_is_magic; fmt->mx_open_mailbox = nntp_open_mailbox; fmt->mx_acl_check = acl_check_nntp; + fmt->mx_fastclose_mailbox = nntp_fastclose_mailbox; + fmt->mx_sync_mailbox = nntp_sync_mailbox; return (fmt); } diff --git a/nntp/nntp.c b/nntp/nntp.c index 9640ba2..311a0fc 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -1094,7 +1094,7 @@ void nntp_delete_data (void *p) FREE (p); } -int nntp_sync_mailbox (CONTEXT * ctx) +int nntp_sync_mailbox (CONTEXT * ctx, int unused1, int* unused2) { NNTP_DATA *data = ctx->data; @@ -1141,7 +1141,7 @@ int nntp_close_mailbox (CONTEXT * ctx) return -1; } } - nntp_sync_mailbox (ctx); + nntp_sync_mailbox (ctx, 0, NULL); if (ctx->data && ((NNTP_DATA *) ctx->data)->nserv) { NNTP_SERVER *news; diff --git a/nntp/nntp.h b/nntp/nntp.h index 35335cd..03087a3 100644 --- a/nntp/nntp.h +++ b/nntp/nntp.h @@ -103,7 +103,7 @@ NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER *, char *); void nntp_clear_cacheindex (NNTP_SERVER *); int mutt_newsrc_update (NNTP_SERVER *); int nntp_open_mailbox (CONTEXT *); -int nntp_sync_mailbox (CONTEXT *); +int nntp_sync_mailbox (CONTEXT *, int, int*); int nntp_check_mailbox (CONTEXT *); int nntp_close_mailbox (CONTEXT *); void nntp_fastclose_mailbox (CONTEXT *); diff --git a/pager.c b/pager.c index a78f522..8c01daa 100644 --- a/pager.c +++ b/pager.c @@ -25,6 +25,7 @@ #include "attach.h" #include "mbyte.h" #include "sidebar.h" +#include "buffy.h" #include "mx.h" @@ -2498,7 +2499,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra) break; case OP_BUFFY_LIST: - mutt_buffy_list (); + buffy_list (); redraw |= REDRAW_SIDEBAR; break; diff --git a/pop/mx_pop.c b/pop/mx_pop.c index 2f51756..2de03d7 100644 --- a/pop/mx_pop.c +++ b/pop/mx_pop.c @@ -46,5 +46,7 @@ mx_t* pop_reg_mx (void) { fmt->mx_is_magic = pop_is_magic; fmt->mx_open_mailbox = pop_open_mailbox; fmt->mx_acl_check = acl_check_pop; + fmt->mx_fastclose_mailbox = pop_close_mailbox; + fmt->mx_sync_mailbox = pop_sync_mailbox; return (fmt); } diff --git a/pop/pop.c b/pop/pop.c index c67cd7e..d737521 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -424,7 +424,7 @@ int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) } /* update POP mailbox - delete messages from server */ -pop_query_status pop_sync_mailbox (CONTEXT * ctx, int *index_hint) +pop_query_status pop_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) { int i; pop_query_status ret; diff --git a/pop/pop.h b/pop/pop.h index 48c01f1..624b5c0 100644 --- a/pop/pop.h +++ b/pop/pop.h @@ -104,7 +104,7 @@ void pop_error (POP_DATA *, char *); /* pop.c */ int pop_check_mailbox (CONTEXT *, int *); int pop_open_mailbox (CONTEXT *); -pop_query_status pop_sync_mailbox (CONTEXT *, int *); +pop_query_status pop_sync_mailbox (CONTEXT *, int, int *); int pop_fetch_message (MESSAGE *, CONTEXT *, int); void pop_close_mailbox (CONTEXT *); void pop_fetch_mail (void); diff --git a/protos.h b/protos.h index a8ac997..b8c08cc 100644 --- a/protos.h +++ b/protos.h @@ -166,8 +166,6 @@ void mutt_block_signals_system (void); void mutt_body_handler (BODY *, STATE *); int mutt_bounce_message (FILE * fp, HEADER *, ADDRESS *); void mutt_break_thread (HEADER *); -void mutt_buffy (char *, size_t); -int mutt_buffy_list (void); void mutt_canonical_charset (char *, size_t, const char *); void mutt_check_rescore (CONTEXT *); void mutt_clear_error (void); @@ -265,8 +263,6 @@ int mutt_addwch (wchar_t); int mutt_alias_complete (char *, size_t); int mutt_alloc_color (int fg, int bg); int mutt_any_key_to_continue (const char *); -int mutt_buffy_check (int); -int mutt_buffy_notify (void); int mutt_builtin_editor (const char *, HEADER *, HEADER *); int mutt_can_decode (BODY *); int mutt_change_flag (HEADER *, int); @@ -333,7 +329,6 @@ int mutt_parse_color (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_uncolor (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_hook (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_macro (BUFFER *, BUFFER *, unsigned long, BUFFER *); -int mutt_parse_mailboxes (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_mono (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_unmono (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_push (BUFFER *, BUFFER *, unsigned long, BUFFER *); diff --git a/sidebar.c b/sidebar.c index b3ec111..d551421 100644 --- a/sidebar.c +++ b/sidebar.c @@ -264,7 +264,7 @@ int sidebar_draw (int menu) else if (!prev_show_value && option (OPTMBOXPANE)) { SidebarWidth = saveSidebarWidth; /* after toggle: force recounting of all mail */ - mutt_buffy_check (2); + buffy_check (2); } prev_show_value = option (OPTMBOXPANE); } diff --git a/sidebar.h b/sidebar.h index be2ee41..005092c 100644 --- a/sidebar.h +++ b/sidebar.h @@ -16,7 +16,7 @@ void sidebar_scroll (int, int); void sidebar_set_buffystats (CONTEXT *); const char* sidebar_get_current (void); void sidebar_set_current (const char*); -/* returns one if mutt_buffy_check should thorougly count */ +/* returns one if buff_check should thorougly count */ int sidebar_need_count (void); #endif /* _SIDEBAR_H */ diff --git a/status.c b/status.c index a470ae3..64b6017 100644 --- a/status.c +++ b/status.c @@ -17,6 +17,7 @@ #include "sort.h" #include "mapping.h" #include "mx.h" +#include "buffy.h" #include "lib/mem.h" #include "lib/intl.h" @@ -68,9 +69,9 @@ static const char *status_format_str (char *buf, size_t buflen, char op, case 'b': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sd", prefix); - snprintf (buf, buflen, fmt, mutt_buffy_check (0)); + snprintf (buf, buflen, fmt, buffy_check (0)); } - else if (!mutt_buffy_check (0)) + else if (!buffy_check (0)) optional = 0; break; -- 2.20.1