X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=mx.c;h=51fc1b300e9e54417399269bdae32be11b59af7a;hp=2a9e17bbdce75ae99a0449cee5609ad698abec8b;hb=b2a6a9673e124c222f921650a6f0025b64ab2145;hpb=7ea0c50703a93a8fb4f0dd05fc4e023cfc9ffd36 diff --git a/mx.c b/mx.c index 2a9e17b..51fc1b3 100644 --- a/mx.c +++ b/mx.c @@ -71,6 +71,7 @@ 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 +153,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 +349,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 */ @@ -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) @@ -550,8 +571,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx) if (!ctx->quiet) mutt_message (_("Reading %s..."), ctx->path); - if ((rc = mx_get_idx (ctx->path)) >= 0) - rc = MX_COMMAND(rc,mx_open_mailbox)(ctx); + rc = MX_COMMAND(ctx->magic-1,mx_open_mailbox)(ctx); if (rc == 0) { if ((flags & M_NOSORT) == 0) { @@ -823,7 +843,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 @@ -1543,6 +1563,15 @@ int mx_check_empty (const char *path) return (-1); } +int mx_acl_check (CONTEXT* ctx, int flag) { + 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)) + return (1); + return (MX_COMMAND(ctx->magic-1,mx_acl_check)(ctx,flag)); +} + void mx_init (void) { #ifdef DEBUG int i = 0;