X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=mx.c;h=5764a51d1edfb8fe8a231b24eefaab3cd2ac764d;hp=c577356c918715e7cb5d388baa3e31829234c5dc;hb=53ceb3f257ec0af78a9129a8a565e8ca2bb03903;hpb=41a708d3e526f10bc3aba7c5eac80aaa0b7b6fcd diff --git a/mx.c b/mx.c index c577356..5764a51 100644 --- a/mx.c +++ b/mx.c @@ -65,12 +65,11 @@ #include #include #include -#ifndef BUFFY_SIZE #include -#endif static list2_t* MailboxFormats = NULL; #define MX_COMMAND(idx,cmd) ((mx_t*) MailboxFormats->data[idx])->cmd +#define MX_IDX(idx) (idx >= 0 && idx < MailboxFormats->length) #define mutt_is_spool(s) (safe_strcmp (Spoolfile, s) == 0) @@ -152,11 +151,24 @@ static int undotlock_file (const char *path, int fd) /* looks up index of type for path in MailboxFormats */ static int mx_get_idx (const char* path) { int i = 0, t = 0; + struct stat st; + /* first, test all non-local folders to avoid stat() call */ for (i = 0; i < MailboxFormats->length; i++) { - t = MX_COMMAND(i,mx_is_magic)(path); + if (!MX_COMMAND(i,local)) + t = MX_COMMAND(i,mx_is_magic)(path, NULL); if (t >= 1) - return (t-1); /* use type as index for array */ + return (t-1); + } + if (stat (path, &st) == 0) { + /* if stat() succeeded, keep testing until success and + * pass stat() info so that we only need to do it once */ + for (i = 0; i < MailboxFormats->length; i++) { + if (MX_COMMAND(i,local)) + t = MX_COMMAND(i,mx_is_magic)(path, &st); + if (t >= 1) + return (t-1); + } } return (-1); } @@ -335,6 +347,12 @@ int mx_get_magic (const char *path) { return (-1); } +int mx_is_local (int m) { + if (!MX_IDX(m)) + return (0); + return (MX_COMMAND(m,local)); +} + /* * set DefaultMagic to the given value */ @@ -509,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) { @@ -520,7 +540,8 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx) return ctx; } - ctx->magic = mx_get_magic (path); + if (!MX_IDX(ctx->magic-1)) + ctx->magic = mx_get_magic (path); #ifdef USE_COMPRESSED if (ctx->magic == M_COMPRESSED) @@ -581,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) @@ -617,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) @@ -822,7 +790,7 @@ int mx_close_mailbox (CONTEXT * ctx, int *index_hint) /* try to use server-side copy first */ i = 1; - if (ctx->magic == M_IMAP && mx_get_magic (mbox) == M_IMAP) { + if (ctx->magic == M_IMAP && imap_is_magic (mbox, NULL) == M_IMAP) { /* tag messages for moving, and clear old tags, if any */ for (i = 0; i < ctx->msgcount; i++) if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted @@ -1126,19 +1094,6 @@ int mx_sync_mailbox (CONTEXT * ctx, int *index_hint) return (rc); } -#ifdef USE_IMAP -int imap_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) -{ - char tmp[_POSIX_PATH_MAX]; - - mutt_mktemp (tmp); - if ((msg->fp = safe_fopen (tmp, "w")) == NULL) - return (-1); - msg->path = safe_strdup (tmp); - return 0; -} -#endif - /* args: * dest destintation mailbox * hdr message being copied (required for maildir support, because @@ -1147,30 +1102,11 @@ int imap_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) { MESSAGE *msg; - int (*func) (MESSAGE *, CONTEXT *, HEADER *); ADDRESS *p = NULL; - switch (dest->magic) { - case M_MMDF: - case M_MBOX: - func = mbox_open_new_message; - break; - case M_MAILDIR: - func = maildir_open_new_message; - break; - case M_MH: - func = mh_open_new_message; - break; -#ifdef USE_IMAP - case M_IMAP: - func = imap_open_new_message; - break; -#endif - default: - dprint (1, - (debugfile, - "mx_open_new_message(): function unimplemented for mailbox type %d.\n", - dest->magic)); + if (!MX_IDX(dest->magic-1)) { + dprint (1, (debugfile, "mx_open_new_message(): function " + "unimplemented for mailbox type %d.\n", dest->magic)); return (NULL); } @@ -1188,7 +1124,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) if (msg->received == 0) time (&msg->received); - if (func (msg, dest, hdr) == 0) { + if (MX_COMMAND(dest->magic-1,mx_open_new_message)(msg, dest, hdr) == 0) { if (dest->magic == M_MMDF) fputs (MMDF_SEP, msg->fp); @@ -1499,7 +1435,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); } } @@ -1507,11 +1443,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; @@ -1543,7 +1481,7 @@ int mx_check_empty (const char *path) } int mx_acl_check (CONTEXT* ctx, int flag) { - if (!ctx || ctx->magic <= 0 || ctx->magic > MailboxFormats->length) + if (!ctx || !MX_IDX(ctx->magic-1)) return (0); /* if no acl_check defined for module, assume permission is granted */ if (!MX_COMMAND(ctx->magic-1,mx_acl_check)) @@ -1578,6 +1516,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 */