X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=mx.c;h=94004833282f40ef66a9c1a18cd7a297a1e7acc1;hp=6cc2a3b258bb4b072bb1556286baec265cb923f1;hb=617e7d83d14e14e6a520a48e75437211b16c8834;hpb=ba5e3af4ea19e1d20c80941c077039871ec84258 diff --git a/mx.c b/mx.c index 6cc2a3b..9400483 100644 --- a/mx.c +++ b/mx.c @@ -12,12 +12,17 @@ # include "config.h" #endif +#include + #include "mutt.h" +#include "buffy.h" +#include "ascii.h" #include "mx.h" #include "mbox.h" #include "mh.h" #include "rfc2047.h" #include "sort.h" +#include "thread.h" #include "copy.h" #include "keymap.h" #include "url.h" @@ -42,17 +47,12 @@ #include "nntp/mx_nntp.h" #endif -#ifdef BUFFY_SIZE -#include "buffy.h" -#endif - #ifdef USE_DOTLOCK #include "dotlock.h" #endif #include "mutt_crypt.h" -#include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" #include "lib/list.h" @@ -199,6 +199,7 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout) count = 0; attempt = 0; + prev_sb.st_size = 0; while (fcntl (fd, F_SETLK, &lck) == -1) { struct stat sb; @@ -291,7 +292,7 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout) int mx_unlock_file (const char *path, int fd, int dot) { #ifdef USE_FCNTL - struct flock unlockit = { F_UNLCK, 0, 0, 0 }; + struct flock unlockit; memset (&unlockit, 0, sizeof (struct flock)); unlockit.l_type = F_UNLCK; @@ -487,7 +488,7 @@ static int mx_open_mailbox_append (CONTEXT * ctx, int flags) } return (-1); } - fseek (ctx->fp, 0, 2); + fseeko (ctx->fp, 0, 2); break; case M_MH: @@ -518,8 +519,8 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx) int rc; if (!ctx) - ctx = mem_malloc (sizeof (CONTEXT)); - memset (ctx, 0, sizeof (CONTEXT)); + ctx = p_new(CONTEXT, 1); + p_clear(ctx, 1); ctx->path = str_dup (path); ctx->msgnotreadyet = -1; @@ -536,7 +537,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx) if (mx_open_mailbox_append (ctx, flags) != 0) { mx_fastclose_mailbox (ctx); if (!pctx) - mem_free (&ctx); + p_delete(&ctx); return NULL; } return ctx; @@ -559,7 +560,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx) if (ctx->magic <= 0) { mx_fastclose_mailbox (ctx); if (!pctx) - mem_free (&ctx); + p_delete(&ctx); return (NULL); } @@ -589,7 +590,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT * pctx) else { mx_fastclose_mailbox (ctx); if (!pctx) - mem_free (&ctx); + p_delete(&ctx); } unset_option (OPTFORCEREFRESH); @@ -613,14 +614,14 @@ void mx_fastclose_mailbox (CONTEXT * ctx) mutt_clear_threads (ctx); for (i = 0; i < ctx->msgcount; i++) mutt_free_header (&ctx->hdrs[i]); - mem_free (&ctx->hdrs); - mem_free (&ctx->v2r); + p_delete(&ctx->hdrs); + p_delete(&ctx->v2r); #ifdef USE_COMPRESSED if (ctx->compressinfo) mutt_fast_close_compressed (ctx); #endif - mem_free (&ctx->path); - mem_free (&ctx->pattern); + p_delete(&ctx->path); + p_delete(&ctx->pattern); if (ctx->limit_pattern) mutt_pattern_free (&ctx->limit_pattern); safe_fclose (&ctx->fp); @@ -694,7 +695,7 @@ static int trash_append (CONTEXT * ctx) } /* save changes and close mailbox */ -int mx_close_mailbox (CONTEXT * ctx, int *index_hint) +static int _mx_close_mailbox (CONTEXT * ctx, int *index_hint) { int i, move_messages = 0, purge = 1, read_msgs = 0; int check; @@ -899,6 +900,14 @@ int mx_close_mailbox (CONTEXT * ctx, int *index_hint) return 0; } +int mx_close_mailbox (CONTEXT * ctx, int *index_hint) { + int ret = 0; + if (!ctx) + return (0); + ret = _mx_close_mailbox (ctx, index_hint); + sidebar_set_buffystats (ctx); + return (ret); +} /* update a Context structure's internal tables. */ @@ -986,7 +995,7 @@ void mx_update_tables (CONTEXT * ctx, int committing) * 0 success * -1 error */ -int mx_sync_mailbox (CONTEXT * ctx, int *index_hint) +static int _mx_sync_mailbox (CONTEXT * ctx, int *index_hint) { int rc, i; int purge = 1; @@ -1077,9 +1086,6 @@ int mx_sync_mailbox (CONTEXT * ctx, int *index_hint) return 0; } - /* update sidebar counts */ - sidebar_set_buffystats (ctx); - /* if we haven't deleted any messages, we don't need to resort */ /* ... except for certain folder formats which need "unsorted" * sort order in order to synchronize folders. @@ -1102,6 +1108,12 @@ int mx_sync_mailbox (CONTEXT * ctx, int *index_hint) return (rc); } +int mx_sync_mailbox (CONTEXT* ctx, int* index_hint) { + int ret = _mx_sync_mailbox (ctx, index_hint); + sidebar_set_buffystats (ctx); + return (ret); +} + /* args: * dest destintation mailbox * hdr message being copied (required for maildir support, because @@ -1117,7 +1129,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) return (NULL); } - msg = mem_calloc (1, sizeof (MESSAGE)); + msg = p_new(MESSAGE, 1); msg->magic = dest->magic; msg->write = 1; @@ -1150,7 +1162,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) } } else - mem_free (&msg); + p_delete(&msg); return msg; } @@ -1179,7 +1191,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) { MESSAGE *msg; - msg = mem_calloc (1, sizeof (MESSAGE)); + msg = p_new(MESSAGE, 1); switch (msg->magic = ctx->magic) { case M_MBOX: case M_MMDF: @@ -1201,7 +1213,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) if (msg->fp == NULL) { mutt_perror (path); debug_print (1, ("fopen: %s: %s (errno %d).\n", path, strerror (errno), errno)); - mem_free (&msg); + p_delete(&msg); } } break; @@ -1210,7 +1222,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) case M_IMAP: { if (imap_fetch_message (msg, ctx, msgno) != 0) - mem_free (&msg); + p_delete(&msg); break; } #endif /* USE_IMAP */ @@ -1219,7 +1231,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) case M_POP: { if (pop_fetch_message (msg, ctx, msgno) != 0) - mem_free (&msg); + p_delete(&msg); break; } #endif /* USE_POP */ @@ -1228,14 +1240,14 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) case M_NNTP: { if (nntp_fetch_message (msg, ctx, msgno) != 0) - mem_free (&msg); + p_delete(&msg); break; } #endif /* USE_NNTP */ default: debug_print (1, ("function not implemented for mailbox type %d.\n", ctx->magic)); - mem_free (&msg); + p_delete(&msg); break; } return (msg); @@ -1277,10 +1289,10 @@ int mx_close_message (MESSAGE ** msg) if ((*msg)->path) { debug_print (1, ("unlinking %s\n", (*msg)->path)); unlink ((*msg)->path); - mem_free (&(*msg)->path); + p_delete(&(*msg)->path); } - mem_free (msg); + p_delete(msg); return (r); } @@ -1297,12 +1309,12 @@ void mx_alloc_memory (CONTEXT * ctx) } if (ctx->hdrs) { - mem_realloc (&ctx->hdrs, sizeof (HEADER *) * (ctx->hdrmax += 25)); - mem_realloc (&ctx->v2r, sizeof (int) * ctx->hdrmax); + p_realloc(&ctx->hdrs, ctx->hdrmax += 25); + p_realloc(&ctx->v2r, ctx->hdrmax); } else { - ctx->hdrs = mem_calloc ((ctx->hdrmax += 25), sizeof (HEADER *)); - ctx->v2r = mem_calloc (ctx->hdrmax, sizeof (int)); + ctx->hdrs = p_new(HEADER *, (ctx->hdrmax += 25)); + ctx->v2r = p_new(int, ctx->hdrmax); } for (i = ctx->msgcount; i < ctx->hdrmax; i++) { ctx->hdrs[i] = NULL; @@ -1342,7 +1354,7 @@ void mx_update_context (CONTEXT * ctx, int new_messages) h2 = hash_find (ctx->id_hash, h->env->supersedes); - /* mem_free (&h->env->supersedes); should I ? */ + /* p_delete(&h->env->supersedes); should I ? */ if (h2) { h2->superseded = 1; if (!ctx->counting && option (OPTSCORE)) @@ -1433,3 +1445,43 @@ void mx_init (void) { #undef EXITWITHERR #endif /* DEBUG */ } + +int mx_rebuild_cache (void) { +#ifndef USE_HCACHE + mutt_error (_("Support for header caching was not build in.")); + return (1); +#else + int i = 0, magic = 0; + CONTEXT* ctx = NULL; + BUFFY* b = NULL; + + if (list_empty(Incoming)) { + mutt_error (_("No mailboxes defined.")); + return (1); + } + + for (i = 0; i < Incoming->length; i++) { + b = (BUFFY*) Incoming->data[i]; + magic = mx_get_magic (b->path); + if (magic != M_MAILDIR && magic != M_MH +#ifdef USE_IMAP + && magic != M_IMAP +#endif + ) + continue; + sidebar_set_current (b->path); + sidebar_draw (CurrentMenu); + if ((ctx = mx_open_mailbox (b->path, + M_READONLY | M_NOSORT | M_COUNT, + NULL)) != NULL) + mx_close_mailbox (ctx, 0); + } + mutt_clear_error (); + + if (Context && Context->path) + sidebar_set_current (Context->path); + sidebar_draw (CurrentMenu); + + return (0); +#endif +}