X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=mx.c;h=2cdbe7eef44889e922e3013ba384a5aae3bd07fa;hp=5764a51d1edfb8fe8a231b24eefaab3cd2ac764d;hb=1abd265879dc5db7e9968a3b4ea7e2031e6b953e;hpb=ce220f6dc8789ed75468c63adce953fbdfed11a8 diff --git a/mx.c b/mx.c index 5764a51..2cdbe7e 100644 --- a/mx.c +++ b/mx.c @@ -21,6 +21,7 @@ #include "copy.h" #include "keymap.h" #include "url.h" +#include "sidebar.h" #ifdef USE_COMPRESSED #include "compress.h" @@ -55,6 +56,7 @@ #include "lib/intl.h" #include "lib/str.h" #include "lib/list.h" +#include "lib/debug.h" #include #include @@ -71,7 +73,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) +#define mutt_is_spool(s) (mutt_strcmp (Spoolfile, s) == 0) #ifdef USE_DOTLOCK /* parameters: @@ -200,7 +202,7 @@ 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; - dprint (1, (debugfile, "mx_lock_file(): fcntl errno %d.\n", errno)); + debug_print (1, ("fcntl errno %d.\n", errno)); if (errno != EAGAIN && errno != EACCES) { mutt_perror ("fcntl"); return (-1); @@ -340,7 +342,7 @@ void mx_unlink_empty (const char *path) int mx_get_magic (const char *path) { int i = 0; - if (safe_strlen (path) == 0) + if (mutt_strlen (path) == 0) return (-1); if ((i = mx_get_idx (path)) >= 0) return (MX_COMMAND(i,type)); @@ -972,6 +974,9 @@ void mx_update_tables (CONTEXT * ctx, int committing) } #undef this_body ctx->msgcount = j; + + /* update sidebar count */ + sidebar_set_buffystats (ctx); } @@ -1072,6 +1077,9 @@ 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. @@ -1105,8 +1113,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) ADDRESS *p = NULL; if (!MX_IDX(dest->magic-1)) { - dprint (1, (debugfile, "mx_open_new_message(): function " - "unimplemented for mailbox type %d.\n", dest->magic)); + debug_print (1, ("function unimplemented for mailbox type %d.\n", dest->magic)); return (NULL); } @@ -1149,10 +1156,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) } /* check for new mail */ -int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) -{ - int rc; - +int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) { #ifdef USE_COMPRESSED if (ctx->compressinfo) return mutt_check_mailbox_compressed (ctx); @@ -1161,53 +1165,13 @@ int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) if (ctx) { if (ctx->locked) lock = 0; - - switch (ctx->magic) { - case M_MBOX: - case M_MMDF: - - if (lock) { - mutt_block_signals (); - if (mbox_lock_mailbox (ctx, 0, 0) == -1) { - mutt_unblock_signals (); - return M_LOCKED; - } - } - - rc = mbox_check_mailbox (ctx, index_hint); - - if (lock) { - mutt_unblock_signals (); - mbox_unlock_mailbox (ctx); - } - - return rc; - - - case M_MH: - return (mh_check_mailbox (ctx, index_hint)); - case M_MAILDIR: - return (maildir_check_mailbox (ctx, index_hint)); - -#ifdef USE_IMAP - case M_IMAP: - return (imap_check_mailbox (ctx, index_hint, 0)); -#endif /* USE_IMAP */ - -#ifdef USE_POP - case M_POP: - return (pop_check_mailbox (ctx, index_hint)); -#endif /* USE_POP */ - -#ifdef USE_NNTP - case M_NNTP: - return (nntp_check_mailbox (ctx)); -#endif /* USE_NNTP */ - } + if (MX_IDX(ctx->magic-1) && MX_COMMAND(ctx->magic-1,mx_check_mailbox)) + return (MX_COMMAND(ctx->magic-1,mx_check_mailbox)(ctx, index_hint, lock)); } - dprint (1, (debugfile, "mx_check_mailbox: null or invalid context.\n")); + debug_print (1, ("null or invalid context.\n")); return (-1); + } /* return a stream pointer for a message */ @@ -1236,8 +1200,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) if (msg->fp == NULL) { mutt_perror (path); - dprint (1, (debugfile, "mx_open_message: fopen: %s: %s (errno %d).\n", - path, strerror (errno), errno)); + debug_print (1, ("fopen: %s: %s (errno %d).\n", path, strerror (errno), errno)); FREE (&msg); } } @@ -1271,10 +1234,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) #endif /* USE_NNTP */ default: - dprint (1, - (debugfile, - "mx_open_message(): function not implemented for mailbox type %d.\n", - ctx->magic)); + debug_print (1, ("function not implemented for mailbox type %d.\n", ctx->magic)); FREE (&msg); break; } @@ -1283,63 +1243,14 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) /* commit a message to a folder */ -int mx_commit_message (MESSAGE * msg, CONTEXT * ctx) -{ - int r = 0; - +int mx_commit_message (MESSAGE * msg, CONTEXT * ctx) { if (!(msg->write && ctx->append)) { - dprint (1, - (debugfile, - "mx_commit_message(): msg->write = %d, ctx->append = %d\n", - msg->write, ctx->append)); + debug_print (1, ("msg->write = %d, ctx->append = %d\n", msg->write, ctx->append)); return -1; } - - switch (msg->magic) { - case M_MMDF: - { - if (fputs (MMDF_SEP, msg->fp) == EOF) - r = -1; - break; - } - - case M_MBOX: - { - if (fputc ('\n', msg->fp) == EOF) - r = -1; - break; - } - -#ifdef USE_IMAP - case M_IMAP: - { - if ((r = safe_fclose (&msg->fp)) == 0) - r = imap_append_message (ctx, msg); - break; - } -#endif - - case M_MAILDIR: - { - r = maildir_commit_message (ctx, msg, NULL); - break; - } - - case M_MH: - { - r = mh_commit_message (ctx, msg, NULL); - break; - } - } - - if (r == 0 && (ctx->magic == M_MBOX || ctx->magic == M_MMDF) - && (fflush (msg->fp) == EOF || fsync (fileno (msg->fp)) == -1)) { - mutt_perror (_("Can't write message")); - - r = -1; - } - - return r; + if (!ctx || !MX_IDX(ctx->magic-1) || !MX_COMMAND(ctx->magic-1,mx_commit_message)) + return (-1); + return (MX_COMMAND(ctx->magic-1,mx_commit_message) (msg, ctx)); } /* close a pointer to a message */ @@ -1364,8 +1275,7 @@ int mx_close_message (MESSAGE ** msg) (*msg)->fp = NULL; if ((*msg)->path) { - dprint (1, (debugfile, "mx_close_message (): unlinking %s\n", - (*msg)->path)); + debug_print (1, ("unlinking %s\n", (*msg)->path)); unlink ((*msg)->path); FREE (&(*msg)->path); } @@ -1463,6 +1373,8 @@ void mx_update_context (CONTEXT * ctx, int new_messages) ctx->new++; } } + /* update sidebar count */ + sidebar_set_buffystats (ctx); } /*