Rocco Rutte:
[apps/madmutt.git] / mx.c
diff --git a/mx.c b/mx.c
index 54548b0..7f92fb6 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -55,6 +55,7 @@
 #include "lib/intl.h"
 #include "lib/str.h"
 #include "lib/list.h"
+#include "lib/debug.h"
 
 #include <dirent.h>
 #include <fcntl.h>
@@ -200,7 +201,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);
@@ -1094,19 +1095,6 @@ int mx_sync_mailbox (CONTEXT * ctx, int *index_hint)
   return (rc);
 }
 
-#ifdef USE_IMAP
-int imap_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr)
-{
-  char tmp[_POSIX_PATH_MAX];
-
-  mutt_mktemp (tmp);
-  if ((msg->fp = safe_fopen (tmp, "w")) == NULL)
-    return (-1);
-  msg->path = safe_strdup (tmp);
-  return 0;
-}
-#endif
-
 /* args:
  *     dest    destintation mailbox
  *     hdr     message being copied (required for maildir support, because
@@ -1115,30 +1103,10 @@ int imap_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr)
 MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags)
 {
   MESSAGE *msg;
-  int (*func) (MESSAGE *, CONTEXT *, HEADER *);
   ADDRESS *p = NULL;
 
-  switch (dest->magic) {
-  case M_MMDF:
-  case M_MBOX:
-    func = mbox_open_new_message;
-    break;
-  case M_MAILDIR:
-    func = maildir_open_new_message;
-    break;
-  case M_MH:
-    func = mh_open_new_message;
-    break;
-#ifdef USE_IMAP
-  case M_IMAP:
-    func = imap_open_new_message;
-    break;
-#endif
-  default:
-    dprint (1,
-            (debugfile,
-             "mx_open_new_message(): function unimplemented for mailbox type %d.\n",
-             dest->magic));
+  if (!MX_IDX(dest->magic-1)) {
+    debug_print (1, ("function unimplemented for mailbox type %d.\n", dest->magic));
     return (NULL);
   }
 
@@ -1156,7 +1124,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags)
   if (msg->received == 0)
     time (&msg->received);
 
-  if (func (msg, dest, hdr) == 0) {
+  if (MX_COMMAND(dest->magic-1,mx_open_new_message)(msg, dest, hdr) == 0) {
     if (dest->magic == M_MMDF)
       fputs (MMDF_SEP, msg->fp);
 
@@ -1238,7 +1206,7 @@ int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock)
     }
   }
 
-  dprint (1, (debugfile, "mx_check_mailbox: null or invalid context.\n"));
+  debug_print (1, ("null or invalid context.\n"));
   return (-1);
 }
 
@@ -1268,8 +1236,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);
       }
     }
@@ -1303,10 +1270,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;
   }
@@ -1320,10 +1284,7 @@ int mx_commit_message (MESSAGE * msg, CONTEXT * ctx)
   int r = 0;
 
   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;
   }
 
@@ -1396,8 +1357,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);
   }