X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=mx.c;h=190f527343ff0f19cb66c21fae8e1cf0680f058c;hp=e38f69622acc072f8f65f9ee11dab050bcf539f2;hb=a742b680bdba8cb47d2b81ab3397cdbec7ed5b69;hpb=0ac011f8eb41bab7808881ebf9802b4eb252fe3b diff --git a/mx.c b/mx.c index e38f696..190f527 100644 --- a/mx.c +++ b/mx.c @@ -12,11 +12,25 @@ # include "config.h" #endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include #include #include +#include + +#include #include @@ -29,14 +43,11 @@ #include "thread.h" #include "copy.h" #include "keymap.h" -#include "url.h" #include "sidebar.h" #include "compress.h" -#ifdef USE_IMAP -#include "imap/imap.h" -#include "imap/mx_imap.h" -#endif +#include +#include #include #include @@ -50,21 +61,9 @@ #include "dotlock.h" #endif -#include "mutt_crypt.h" +#include #include "lib/list.h" -#include "lib/debug.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include static list2_t* MailboxFormats = NULL; #define MX_COMMAND(idx,cmd) ((mx_t*) MailboxFormats->data[idx])->cmd @@ -167,9 +166,9 @@ static int mx_get_idx (const char* path) { /* Args: * excl if excl != 0, request an exclusive lock * dot if dot != 0, try to dotlock the file - * timeout should retry locking? + * time_out should retry locking? */ -int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout) +int mx_lock_file (const char *path, int fd, int excl, int dot, int time_out) { #if defined (USE_FCNTL) || defined (USE_FLOCK) int count; @@ -192,7 +191,6 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout) while (fcntl (fd, F_SETLK, &lck) == -1) { struct stat sb; - debug_print (1, ("fcntl errno %d.\n", errno)); if (errno != EAGAIN && errno != EACCES) { mutt_perror ("fcntl"); return (-1); @@ -206,8 +204,8 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout) /* only unlock file if it is unchanged */ if (prev_sb.st_size == sb.st_size - && ++count >= (timeout ? MAXLOCKATTEMPT : 0)) { - if (timeout) + && ++count >= (time_out ? MAXLOCKATTEMPT : 0)) { + if (time_out) mutt_error _("Timeout exceeded while attempting fcntl lock!"); return (-1); @@ -240,8 +238,8 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout) /* only unlock file if it is unchanged */ if (prev_sb.st_size == sb.st_size - && ++count >= (timeout ? MAXLOCKATTEMPT : 0)) { - if (timeout) + && ++count >= (time_out ? MAXLOCKATTEMPT : 0)) { + if (time_out) mutt_error _("Timeout exceeded while attempting flock lock!"); r = -1; @@ -257,7 +255,7 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout) #ifdef USE_DOTLOCK if (r == 0 && dot) - r = dotlock_file (path, fd, timeout); + r = dotlock_file (path, fd, time_out); #endif /* USE_DOTLOCK */ if (r == -1) { @@ -387,13 +385,9 @@ static int mx_open_mailbox_append (CONTEXT * ctx, int flags) ctx->append = 1; -#ifdef USE_IMAP - if (mx_get_magic (ctx->path) == M_IMAP) return imap_open_mailbox_append (ctx); -#endif - if (stat (ctx->path, &sb) == 0) { ctx->magic = mx_get_magic (ctx->path); @@ -598,7 +592,7 @@ void mx_fastclose_mailbox (CONTEXT * ctx) hash_destroy (&ctx->id_hash, NULL); mutt_clear_threads (ctx); for (i = 0; i < ctx->msgcount; i++) - mutt_free_header (&ctx->hdrs[i]); + header_delete(&ctx->hdrs[i]); p_delete(&ctx->hdrs); p_delete(&ctx->v2r); @@ -758,10 +752,8 @@ static int _mx_close_mailbox (CONTEXT * ctx, int *index_hint) } } -#ifdef USE_IMAP /* IMAP servers manage the OLD flag themselves */ if (ctx->magic != M_IMAP) -#endif if (option (OPTMARKOLD)) { for (i = 0; i < ctx->msgcount; i++) { if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->old) @@ -772,7 +764,6 @@ static int _mx_close_mailbox (CONTEXT * ctx, int *index_hint) if (move_messages) { mutt_message (_("Moving read messages to %s..."), mbox); -#ifdef USE_IMAP /* try to use server-side copy first */ i = 1; @@ -795,7 +786,6 @@ static int _mx_close_mailbox (CONTEXT * ctx, int *index_hint) return -1; } else /* use regular append-copy mode */ -#endif { if (mx_open_mailbox (mbox, M_APPEND, &f) == NULL) { ctx->closing = 0; @@ -836,7 +826,6 @@ static int _mx_close_mailbox (CONTEXT * ctx, int *index_hint) return -1; } -#ifdef USE_IMAP /* allow IMAP to preserve the deleted flag across sessions */ if (ctx->magic == M_IMAP) { if ((check = imap_sync_mailbox (ctx, purge, index_hint)) != 0) { @@ -845,7 +834,6 @@ static int _mx_close_mailbox (CONTEXT * ctx, int *index_hint) } } else -#endif { if (!purge) { for (i = 0; i < ctx->msgcount; i++) @@ -959,7 +947,7 @@ void mx_update_tables (CONTEXT * ctx, int committing) if (ctx->id_hash && ctx->hdrs[i]->env->message_id) hash_delete (ctx->id_hash, ctx->hdrs[i]->env->message_id, ctx->hdrs[i], NULL); - mutt_free_header (&ctx->hdrs[i]); + header_delete(&ctx->hdrs[i]); } } #undef this_body @@ -1017,10 +1005,8 @@ static int _mx_sync_mailbox (CONTEXT * ctx, int *index_hint) else if (purge == M_NO) { if (!ctx->changed) return 0; /* nothing to do! */ -#ifdef USE_IMAP /* let IMAP servers hold on to D flags */ if (ctx->magic != M_IMAP) -#endif { for (i = 0; i < ctx->msgcount; i++) ctx->hdrs[i]->deleted = 0; @@ -1041,19 +1027,15 @@ static int _mx_sync_mailbox (CONTEXT * ctx, int *index_hint) return -1; } -#ifdef USE_IMAP if (ctx->magic == M_IMAP) rc = imap_sync_mailbox (ctx, purge, index_hint); else -#endif rc = sync_mailbox (ctx, index_hint); if (rc == 0) { -#ifdef USE_IMAP if (ctx->magic == M_IMAP && !purge) mutt_message (_("Mailbox checkpointed.")); else -#endif mutt_message (_("%d kept, %d deleted."), msgcount - deleted, deleted); mutt_sleep (0); @@ -1074,10 +1056,8 @@ static int _mx_sync_mailbox (CONTEXT * ctx, int *index_hint) * at least with the new threading code. */ if (purge || (ctx->magic != M_MAILDIR && ctx->magic != M_MH)) { -#ifdef USE_IMAP /* IMAP does this automatically after handling EXPUNGE */ if (ctx->magic != M_IMAP) -#endif { mx_update_tables (ctx, 1); mutt_sort_headers (ctx, 1); /* rethread from scratch */ @@ -1105,7 +1085,6 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) address_t *p = NULL; if (!MX_IDX(dest->magic-1)) { - debug_print (1, ("function unimplemented for mailbox type %d.\n", dest->magic)); return (NULL); } @@ -1159,9 +1138,7 @@ int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) { return (MX_COMMAND(ctx->magic-1,mx_check_mailbox)(ctx, index_hint, lock)); } - debug_print (1, ("null or invalid context.\n")); return (-1); - } /* return a stream pointer for a message */ @@ -1190,20 +1167,17 @@ 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)); p_delete(&msg); } } break; -#ifdef USE_IMAP case M_IMAP: { if (imap_fetch_message (msg, ctx, msgno) != 0) p_delete(&msg); break; } -#endif /* USE_IMAP */ case M_POP: { @@ -1222,7 +1196,6 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) #endif /* USE_NNTP */ default: - debug_print (1, ("function not implemented for mailbox type %d.\n", ctx->magic)); p_delete(&msg); break; } @@ -1233,7 +1206,6 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) int mx_commit_message (MESSAGE * msg, CONTEXT * ctx) { if (!(msg->write && ctx->append)) { - debug_print (1, ("msg->write = %d, ctx->append = %d\n", msg->write, ctx->append)); return -1; } if (!ctx || !MX_IDX(ctx->magic-1) || !MX_COMMAND(ctx->magic-1,mx_commit_message)) @@ -1247,9 +1219,7 @@ int mx_close_message (MESSAGE ** msg) int r = 0; if ((*msg)->magic == M_MH || (*msg)->magic == M_MAILDIR -#ifdef USE_IMAP || (*msg)->magic == M_IMAP -#endif || (*msg)->magic == M_POP #ifdef USE_NNTP || (*msg)->magic == M_NNTP @@ -1261,7 +1231,6 @@ int mx_close_message (MESSAGE ** msg) (*msg)->fp = NULL; if ((*msg)->path) { - debug_print (1, ("unlinking %s\n", (*msg)->path)); unlink ((*msg)->path); p_delete(&(*msg)->path); } @@ -1386,32 +1355,16 @@ int mx_acl_check (CONTEXT* ctx, int flag) { } void mx_init (void) { -#ifdef DEBUG - int i = 0; -#endif list_push_back (&MailboxFormats, (void*) mbox_reg_mx ()); list_push_back (&MailboxFormats, (void*) mmdf_reg_mx ()); list_push_back (&MailboxFormats, (void*) mh_reg_mx ()); list_push_back (&MailboxFormats, (void*) maildir_reg_mx ()); -#ifdef USE_IMAP list_push_back (&MailboxFormats, (void*) imap_reg_mx ()); -#endif list_push_back (&MailboxFormats, (void*) pop_reg_mx ()); #ifdef USE_NNTP list_push_back (&MailboxFormats, (void*) nntp_reg_mx ()); #endif list_push_back (&MailboxFormats, (void*) compress_reg_mx ()); -#ifdef DEBUG - /* check module registration for completeness with debug versions */ -#define EXITWITHERR(m) do { fprintf(stderr, "error: incomplete mx module: %s is missing for type %i\n",m,i);exit(1); } while (0) - for (i = 0; i < MailboxFormats->length; i++) { - 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 */ } int mx_rebuild_cache (void) { @@ -1431,11 +1384,7 @@ int mx_rebuild_cache (void) { 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 - ) + if (magic != M_MAILDIR && magic != M_MH && magic != M_IMAP) continue; sidebar_set_current (b->path); sidebar_draw (CurrentMenu); @@ -1453,3 +1402,27 @@ int mx_rebuild_cache (void) { return (0); #endif } + +void mutt_parse_mime_message (CONTEXT * ctx, HEADER * cur) +{ + MESSAGE *msg; + int flags = 0; + + do { + if (cur->content->type != TYPEMESSAGE + && cur->content->type != TYPEMULTIPART) + break; /* nothing to do */ + + if (cur->content->parts) + break; /* The message was parsed earlier. */ + + if ((msg = mx_open_message (ctx, cur->msgno))) { + mutt_parse_part (msg->fp, cur->content); + + cur->security = crypt_query (cur->content); + + mx_close_message (&msg); + } + } while (0); + mutt_count_body_parts (cur, flags | M_PARTS_RECOUNT); +}