Clean buffy.c and init.c
[apps/madmutt.git] / mbox.c
diff --git a/mbox.c b/mbox.c
index d4d3a08..442a406 100644 (file)
--- 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 <lib-lib/lib-lib.h>
 
-#include <sys/stat.h>
-#include <dirent.h>
-#include <string.h>
-#include <utime.h>
-#include <sys/file.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/macros.h>
-#include <lib-lib/file.h>
-#include <lib-lib/debug.h>
+#include <lib-ui/curses.h>
+#include <lib-sys/mutt_signal.h>
 
 #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) {
@@ -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
        */
@@ -931,7 +895,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 {