#endif
#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"
#include "nntp/mx_nntp.h"
#endif
-#ifdef BUFFY_SIZE
-#include "buffy.h"
-#endif
-
#ifdef USE_DOTLOCK
#include "dotlock.h"
#endif
#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) (mutt_strcmp (Spoolfile, s) == 0)
+#define mutt_is_spool(s) (str_cmp (Spoolfile, s) == 0)
#ifdef USE_DOTLOCK
/* parameters:
count = 0;
attempt = 0;
+ prev_sb.st_size = 0;
while (fcntl (fd, F_SETLK, &lck) == -1) {
struct stat sb;
int mx_get_magic (const char *path) {
int i = 0;
- if (mutt_strlen (path) == 0)
+ if (str_len (path) == 0)
return (-1);
if ((i = mx_get_idx (path)) >= 0)
return (MX_COMMAND(i,type));
}
return (-1);
}
- fseek (ctx->fp, 0, 2);
+ fseeko (ctx->fp, 0, 2);
break;
case M_MH:
int rc;
if (!ctx)
- ctx = safe_malloc (sizeof (CONTEXT));
+ ctx = mem_malloc (sizeof (CONTEXT));
memset (ctx, 0, sizeof (CONTEXT));
- ctx->path = safe_strdup (path);
+ ctx->path = str_dup (path);
ctx->msgnotreadyet = -1;
ctx->collapsed = 0;
if (mx_open_mailbox_append (ctx, flags) != 0) {
mx_fastclose_mailbox (ctx);
if (!pctx)
- FREE (&ctx);
+ mem_free (&ctx);
return NULL;
}
return ctx;
if (ctx->magic <= 0) {
mx_fastclose_mailbox (ctx);
if (!pctx)
- FREE (&ctx);
+ mem_free (&ctx);
return (NULL);
}
else {
mx_fastclose_mailbox (ctx);
if (!pctx)
- FREE (&ctx);
+ mem_free (&ctx);
}
unset_option (OPTFORCEREFRESH);
mutt_clear_threads (ctx);
for (i = 0; i < ctx->msgcount; i++)
mutt_free_header (&ctx->hdrs[i]);
- FREE (&ctx->hdrs);
- FREE (&ctx->v2r);
+ mem_free (&ctx->hdrs);
+ mem_free (&ctx->v2r);
#ifdef USE_COMPRESSED
if (ctx->compressinfo)
mutt_fast_close_compressed (ctx);
#endif
- FREE (&ctx->path);
- FREE (&ctx->pattern);
+ mem_free (&ctx->path);
+ mem_free (&ctx->pattern);
if (ctx->limit_pattern)
mutt_pattern_free (&ctx->limit_pattern);
safe_fclose (&ctx->fp);
}
/* 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;
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. */
* 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;
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.
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
return (NULL);
}
- msg = safe_calloc (1, sizeof (MESSAGE));
+ msg = mem_calloc (1, sizeof (MESSAGE));
msg->magic = dest->magic;
msg->write = 1;
}
}
else
- FREE (&msg);
+ mem_free (&msg);
return msg;
}
if (ctx) {
if (ctx->locked)
lock = 0;
- if (MX_COMMAND(ctx->magic-1,mx_check_mailbox))
+ 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));
}
{
MESSAGE *msg;
- msg = safe_calloc (1, sizeof (MESSAGE));
+ msg = mem_calloc (1, sizeof (MESSAGE));
switch (msg->magic = ctx->magic) {
case M_MBOX:
case M_MMDF:
if (msg->fp == NULL) {
mutt_perror (path);
debug_print (1, ("fopen: %s: %s (errno %d).\n", path, strerror (errno), errno));
- FREE (&msg);
+ mem_free (&msg);
}
}
break;
case M_IMAP:
{
if (imap_fetch_message (msg, ctx, msgno) != 0)
- FREE (&msg);
+ mem_free (&msg);
break;
}
#endif /* USE_IMAP */
case M_POP:
{
if (pop_fetch_message (msg, ctx, msgno) != 0)
- FREE (&msg);
+ mem_free (&msg);
break;
}
#endif /* USE_POP */
case M_NNTP:
{
if (nntp_fetch_message (msg, ctx, msgno) != 0)
- FREE (&msg);
+ mem_free (&msg);
break;
}
#endif /* USE_NNTP */
default:
debug_print (1, ("function not implemented for mailbox type %d.\n", ctx->magic));
- FREE (&msg);
+ mem_free (&msg);
break;
}
return (msg);
/* 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)) {
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 */
if ((*msg)->path) {
debug_print (1, ("unlinking %s\n", (*msg)->path));
unlink ((*msg)->path);
- FREE (&(*msg)->path);
+ mem_free (&(*msg)->path);
}
- FREE (msg);
+ mem_free (msg);
return (r);
}
}
if (ctx->hdrs) {
- safe_realloc (&ctx->hdrs, sizeof (HEADER *) * (ctx->hdrmax += 25));
- safe_realloc (&ctx->v2r, sizeof (int) * ctx->hdrmax);
+ mem_realloc (&ctx->hdrs, sizeof (HEADER *) * (ctx->hdrmax += 25));
+ mem_realloc (&ctx->v2r, sizeof (int) * ctx->hdrmax);
}
else {
- ctx->hdrs = safe_calloc ((ctx->hdrmax += 25), sizeof (HEADER *));
- ctx->v2r = safe_calloc (ctx->hdrmax, sizeof (int));
+ ctx->hdrs = mem_calloc ((ctx->hdrmax += 25), sizeof (HEADER *));
+ ctx->v2r = mem_calloc (ctx->hdrmax, sizeof (int));
}
for (i = ctx->msgcount; i < ctx->hdrmax; i++) {
ctx->hdrs[i] = NULL;
h2 = hash_find (ctx->id_hash, h->env->supersedes);
- /* FREE (&h->env->supersedes); should I ? */
+ /* mem_free (&h->env->supersedes); should I ? */
if (h2) {
h2->superseded = 1;
if (!ctx->counting && option (OPTSCORE))
#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
+}