#include <stdlib.h>
#include <string.h>
#include <ctype.h>
-#ifndef BUFFY_SIZE
#include <utime.h>
-#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)
/* 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);
}
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
*/
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) {
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)
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)
/* 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)
/* 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
/* 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);
}
}
/* 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;
}
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))
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 */