X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=mbox.c;h=3832eee4756257e27024d0a5600087f10a547508;hp=d4d3a08c6b9c8b0617f9a9fb4c5b01269218c9d2;hb=6be673363a420d4f21e9ab1fbd5835ffba38a7ed;hpb=05a3bbbe420e4afc76e0eea24ce32f859405dc4a diff --git a/mbox.c b/mbox.c index d4d3a08..3832eee 100644 --- a/mbox.c +++ b/mbox.c @@ -9,24 +9,10 @@ /* This file contains code to parse ``mbox'' and ``mmdf'' style mailboxes */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include +#include + +#include +#include #include "mutt.h" #include "mx.h" @@ -75,7 +61,7 @@ int mbox_lock_mailbox (CONTEXT * ctx, int excl, int retry) return (r); } -void mbox_unlock_mailbox (CONTEXT * ctx) +static void mbox_unlock_mailbox (CONTEXT * ctx) { if (ctx->locked) { fflush (ctx->fp); @@ -130,7 +116,6 @@ static int mmdf_parse_mailbox (CONTEXT * ctx) if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL) { /* TODO: memory leak??? */ - debug_print (1, ("unexpected EOF\n")); break; } @@ -138,7 +123,6 @@ static int mmdf_parse_mailbox (CONTEXT * ctx) if (!is_from (buf, return_path, sizeof (return_path), &t)) { if (fseeko (ctx->fp, loc, SEEK_SET) != 0) { - debug_print (1, ("fseeko() failed\n")); mutt_error _("Mailbox is corrupt!"); return (-1); @@ -158,8 +142,7 @@ static int mmdf_parse_mailbox (CONTEXT * ctx) if (fseeko (ctx->fp, tmploc, SEEK_SET) != 0 || fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL || m_strcmp(MMDF_SEP, buf) != 0) { - if (fseeko (ctx->fp, loc, SEEK_SET) != 0) - debug_print (1, ("fseeko() failed\n")); + fseeko (ctx->fp, loc, SEEK_SET); hdr->content->length = -1; } } @@ -192,7 +175,6 @@ static int mmdf_parse_mailbox (CONTEXT * ctx) ctx->msgcount++; } else { - debug_print (1, ("corrupt mailbox!\n")); mutt_error _("Mailbox is corrupt!"); return (-1); @@ -286,12 +268,7 @@ static int mbox_parse_mailbox (CONTEXT * ctx) if (fseeko (ctx->fp, tmploc, SEEK_SET) != 0 || fgets (buf, sizeof (buf), ctx->fp) == NULL || m_strncmp("From ", buf, 5) != 0) { - debug_print (1, ("bad content-length in message %d (cl=%zd)\n", - curhdr->index, curhdr->content->length)); - debug_print (1, ("LINE: %s\n", buf)); - if (fseeko (ctx->fp, loc, SEEK_SET) != 0) { /* nope, return the previous position */ - debug_print (1, ("fseeko() failed\n")); - } + fseeko (ctx->fp, loc, SEEK_SET); /* nope, return the previous position */ curhdr->content->length = -1; } } @@ -310,8 +287,7 @@ static int mbox_parse_mailbox (CONTEXT * ctx) int cl = curhdr->content->length; /* count the number of lines in this message */ - if (fseeko (ctx->fp, loc, SEEK_SET) != 0) - debug_print (1, ("fseeko() failed\n")); + fseeko (ctx->fp, loc, SEEK_SET); while (cl-- > 0) { if (fgetc (ctx->fp) == '\n') curhdr->lines++; @@ -319,8 +295,7 @@ static int mbox_parse_mailbox (CONTEXT * ctx) } /* return to the offset of the next message separator */ - if (fseeko (ctx->fp, tmploc, SEEK_SET) != 0) - debug_print (1, ("fseeko() failed\n")); + fseeko(ctx->fp, tmploc, SEEK_SET); } } @@ -439,13 +414,11 @@ static int _mbox_check_mailbox (CONTEXT * ctx, int *index_hint) * see the message separator at *exactly* what used to be the end of the * folder. */ - if (fseeko (ctx->fp, ctx->size, SEEK_SET) != 0) - debug_print (1, ("fseeko() failed\n")); + fseeko (ctx->fp, ctx->size, SEEK_SET); if (fgets (buffer, sizeof (buffer), ctx->fp) != NULL) { if ((ctx->magic == M_MBOX && m_strncmp("From ", buffer, 5) == 0) || (ctx->magic == M_MMDF && m_strcmp(MMDF_SEP, buffer) == 0)) { - if (fseeko (ctx->fp, ctx->size, SEEK_SET) != 0) - debug_print (1, ("fseeko() failed\n")); + fseeko (ctx->fp, ctx->size, SEEK_SET); if (ctx->magic == M_MBOX) mbox_parse_mailbox (ctx); else @@ -465,14 +438,12 @@ static int _mbox_check_mailbox (CONTEXT * ctx, int *index_hint) } else modified = 1; - } - else { - debug_print (1, ("fgets returned NULL.\n")); + } else { modified = 1; } - } - else + } else { modified = 1; + } } if (modified) { @@ -519,7 +490,7 @@ static int mbox_check_mailbox (CONTEXT* ctx, int* index_hint, int lock) { * 0 success * -1 failure */ -static int _mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)), int *index_hint) +static int mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused)), int *index_hint) { char tempfile[_POSIX_PATH_MAX]; char buf[32]; @@ -601,7 +572,6 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused) mutt_error _("sync: mbox modified, but no modified messages! (report this bug)"); mutt_sleep (5); /* the mutt_error /will/ get cleared! */ - debug_print (1, ("no modified messages.\n")); unlink (tempfile); goto bail; } @@ -672,7 +642,7 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused) */ newOffset[i - first].body = ftello (fp) - ctx->hdrs[i]->content->length + offset; - mutt_free_body (&ctx->hdrs[i]->content->parts); + body_list_wipe(&ctx->hdrs[i]->content->parts); switch (ctx->magic) { case M_MMDF: @@ -696,7 +666,6 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused) if (fclose (fp) != 0) { fp = NULL; - debug_print (1, ("fclose() returned non-zero.\n")); unlink (tempfile); mutt_perror (tempfile); mutt_sleep (5); @@ -715,7 +684,6 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused) if ((fp = fopen (tempfile, "r")) == NULL) { mutt_unblock_signals (); mx_fastclose_mailbox (ctx); - debug_print (1, ("unable to reopen temp copy of mailbox!\n")); mutt_perror (tempfile); mutt_sleep (5); return (-1); @@ -726,16 +694,12 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused __attribute__ ((unused) fgets (buf, sizeof (buf), ctx->fp) == NULL || (ctx->magic == M_MBOX && m_strncmp("From ", buf, 5) != 0) || (ctx->magic == M_MMDF && m_strcmp(MMDF_SEP, buf) != 0)) { - debug_print (1, ("message not in expected position.\n")); - debug_print (1, ("LINE: %s\n", buf)); i = -1; } else { if (fseeko (ctx->fp, offset, SEEK_SET) != 0) { /* return to proper offset */ i = -1; - debug_print (1, ("fseeko() failed\n")); - } - else { + } else { /* copy the temp mailbox back into place starting at the first * change/deleted message */ @@ -842,19 +806,6 @@ bail: /* Come here in case of disaster */ return rc; } -static int mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) { -#ifdef BUFFY_SIZE - BUFFY* tmp = NULL; -#endif - int rc = _mbox_sync_mailbox (ctx, unused, index_hint); - -#ifdef BUFFY_SIZE - if ((tmp = buffy_find_mailbox (ctx->path)) && tmp->new == 0) - buffy_update_mailbox (tmp); -#endif - return (rc); -} - /* close a mailbox opened in write-mode */ int mbox_close_mailbox (CONTEXT * ctx) { @@ -931,7 +882,6 @@ static int mbox_reopen_mailbox (CONTEXT * ctx, int *index_hint) case M_MBOX: case M_MMDF: if (fseeko (ctx->fp, 0, SEEK_SET) != 0) { - debug_print (1, ("fseeko() failed\n")); rc = -1; } else { @@ -1060,16 +1010,15 @@ int mbox_is_magic (const char* path, struct stat* st) { return (M_MBOX); } else if ((f = fopen (path, "r")) != NULL) { -#ifndef BUFFY_SIZE struct utimbuf times; -#endif + fgets (tmp, sizeof (tmp), f); if (m_strncmp("From ", tmp, 5) == 0) magic = M_MBOX; else if (m_strcmp(MMDF_SEP, tmp) == 0) magic = M_MMDF; safe_fclose (&f); -#ifndef BUFFY_SIZE + /* need to restore the times here, the file was not really accessed, * only the type was accessed. This is important, because detection * of "new mail" depends on those times set correctly. @@ -1077,7 +1026,6 @@ int mbox_is_magic (const char* path, struct stat* st) { times.actime = st->st_atime; times.modtime = st->st_mtime; utime (path, ×); -#endif } else { mutt_perror (path); return (-1); /* fopen failed */ @@ -1107,28 +1055,32 @@ static int mmdf_commit_message (MESSAGE* msg, CONTEXT* ctx) { return (commit_message (msg, ctx, 0)); } -static mx_t* reg_mx (void) { - mx_t* fmt = p_new(mx_t, 1); - fmt->local = 1; - fmt->mx_check_empty = mbox_check_empty; - fmt->mx_is_magic = mbox_is_magic; - fmt->mx_access = access; - fmt->mx_open_mailbox = mbox_open_mailbox; - fmt->mx_open_new_message = mbox_open_new_message; - fmt->mx_sync_mailbox = mbox_sync_mailbox; - fmt->mx_check_mailbox = mbox_check_mailbox; - return (fmt); -} +mx_t const mbox_mx = { + M_MBOX, + 1, + mbox_is_magic, + mbox_check_empty, + access, + mbox_open_mailbox, + mbox_open_new_message, + NULL, + mbox_check_mailbox, + NULL, + mbox_sync_mailbox, + mbox_commit_message, +}; -mx_t* mbox_reg_mx (void) { - mx_t* fmt = reg_mx (); - fmt->type = M_MBOX; - fmt->mx_commit_message = mbox_commit_message; - return (fmt); -} -mx_t* mmdf_reg_mx (void) { - mx_t* fmt = reg_mx (); - fmt->type = M_MMDF; - fmt->mx_commit_message = mmdf_commit_message; - return (fmt); -} +mx_t const mmdf_mx = { + M_MMDF, + 1, + mbox_is_magic, + mbox_check_empty, + access, + mbox_open_mailbox, + mbox_open_new_message, + NULL, + mbox_check_mailbox, + NULL, + mbox_sync_mailbox, + mmdf_commit_message, +};