changeset: 6688:e5d87ebe0f5b
user:      Damien Riegel <damien.rie...@gmail.com>
date:      Sat Jun 18 13:36:12 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/e5d87ebe0f5b

remove unused HEADER parameter in mh_commit_message

mh_commit_message is only called in one place with the header parameter
set to NULL. To make the commit function consistent with other
mailboxes, which only takes ctx and msg as parameters, remove this
unused parameter.

changeset: 6689:93d4169b0886
user:      Damien Riegel <damien.rie...@gmail.com>
date:      Sat Jun 18 13:36:18 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/93d4169b0886

prepend maildir_commit_message function name with an underscore

Basically, rename maildir_commit_message to _maildir_commit_message.
This commit is preparatory to make the maildir_commit_message symbol
available for further use.

Symbols starting with underscore should be avoided but this one is long
enough to prevent collision.

changeset: 6690:37140981e746
user:      Damien Riegel <damien.rie...@gmail.com>
date:      Sat Jun 18 13:36:19 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/37140981e746

add maildir_commit_message function

This commit adds a maildir_commit_message with a prototype consistent
with other kind of mailboxes, to simplify upcoming refactoring.

changeset: 6691:16bfe31ef8b3
user:      Damien Riegel <damien.rie...@gmail.com>
date:      Sat Jun 18 13:36:21 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/16bfe31ef8b3

add imap_commit_message function

Move IMAP operations that were done in mx_commit_message to a dedicated
imap_commit_message function.

changeset: 6692:4c6539a88f0a
user:      Damien Riegel <damien.rie...@gmail.com>
date:      Sat Jun 18 13:36:22 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/4c6539a88f0a

add mbox_commit_message function

Move mbox operations that were done in mx_commit_message to a dedicated
mbox_commit_message function.

changeset: 6693:28688fee52a5
user:      Damien Riegel <damien.rie...@gmail.com>
date:      Sat Jun 18 13:36:22 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/28688fee52a5

add mmdf_commit_message function

Move MMDF operations that were done in mx_commit_message to a dedicated
mmdf_commit_message function.

changeset: 6694:91af19866bbd
user:      Damien Riegel <damien.rie...@gmail.com>
date:      Sat Jun 18 13:36:25 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/91af19866bbd

add commit_msg to struct mx_ops

diffs (252 lines):

diff -r ce2e5caf4339 -r 91af19866bbd imap/imap.c
--- a/imap/imap.c       Sat Jun 18 12:41:45 2016 -0700
+++ b/imap/imap.c       Sat Jun 18 13:36:25 2016 -0700
@@ -2076,6 +2076,7 @@
   .close = imap_close_mailbox,
   .open_msg = imap_fetch_message,
   .close_msg = imap_close_message,
+  .commit_msg = imap_commit_message,
   .open_new_msg = imap_open_new_message,
   .check = imap_check_mailbox_reopen,
 };
diff -r ce2e5caf4339 -r 91af19866bbd imap/imap_private.h
--- a/imap/imap_private.h       Sat Jun 18 12:41:45 2016 -0700
+++ b/imap/imap_private.h       Sat Jun 18 13:36:25 2016 -0700
@@ -270,6 +270,7 @@
 
 int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno);
 int imap_close_message (CONTEXT *ctx, MESSAGE *msg);
+int imap_commit_message (CONTEXT *ctx, MESSAGE *msg);
 
 /* util.c */
 #ifdef USE_HCACHE
diff -r ce2e5caf4339 -r 91af19866bbd imap/message.c
--- a/imap/message.c    Sat Jun 18 12:41:45 2016 -0700
+++ b/imap/message.c    Sat Jun 18 13:36:25 2016 -0700
@@ -600,6 +600,16 @@
   return safe_fclose (&msg->fp);
 }
 
+int imap_commit_message (CONTEXT *ctx, MESSAGE *msg)
+{
+  int r = safe_fclose (&msg->fp);
+
+  if (r)
+    return r;
+
+  return imap_append_message (ctx, msg);
+}
+
 int imap_append_message (CONTEXT *ctx, MESSAGE *msg)
 {
   IMAP_DATA* idata;
diff -r ce2e5caf4339 -r 91af19866bbd mbox.c
--- a/mbox.c    Sat Jun 18 12:41:45 2016 -0700
+++ b/mbox.c    Sat Jun 18 13:36:25 2016 -0700
@@ -461,6 +461,26 @@
   return 0;
 }
 
+static int mbox_commit_message (CONTEXT *ctx, MESSAGE *msg)
+{
+  int r = fputc ('\n', msg->fp);
+
+  if (r == EOF)
+    return -1;
+
+  return 0;
+}
+
+static int mmdf_commit_message (CONTEXT *ctx, MESSAGE *msg)
+{
+  int r = fputs (MMDF_SEP, msg->fp);
+
+  if (r == EOF)
+    return -1;
+
+  return 0;
+}
+
 static int mbox_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr)
 {
   msg->fp = dest->fp;
@@ -1290,6 +1310,7 @@
   .close = mbox_close_mailbox,
   .open_msg = mbox_open_message,
   .close_msg = mbox_close_message,
+  .commit_msg = mbox_commit_message,
   .open_new_msg = mbox_open_new_message,
   .check = mbox_check_mailbox,
 };
@@ -1299,6 +1320,7 @@
   .close = mbox_close_mailbox,
   .open_msg = mbox_open_message,
   .close_msg = mbox_close_message,
+  .commit_msg = mmdf_commit_message,
   .open_new_msg = mbox_open_new_message,
   .check = mbox_check_mailbox,
 };
diff -r ce2e5caf4339 -r 91af19866bbd mh.c
--- a/mh.c      Sat Jun 18 12:41:45 2016 -0700
+++ b/mh.c      Sat Jun 18 13:36:25 2016 -0700
@@ -1469,7 +1469,7 @@
  * 
  */
 
-int maildir_commit_message (CONTEXT * ctx, MESSAGE * msg, HEADER * hdr)
+static int _maildir_commit_message (CONTEXT * ctx, MESSAGE * msg, HEADER * hdr)
 {
   char subdir[4];
   char suffix[16];
@@ -1501,7 +1501,7 @@
              NONULL (Hostname), suffix);
     snprintf (full, _POSIX_PATH_MAX, "%s/%s", ctx->path, path);
 
-    dprint (2, (debugfile, "maildir_commit_message (): renaming %s to %s.\n",
+    dprint (2, (debugfile, "_maildir_commit_message (): renaming %s to %s.\n",
                msg->path, full));
 
     if (safe_rename (msg->path, full) == 0)
@@ -1524,7 +1524,7 @@
        ut.modtime = msg->received;
        if (utime (full, &ut))
        {
-         mutt_perror (_("maildir_commit_message(): unable to set time on 
file"));
+         mutt_perror (_("_maildir_commit_message(): unable to set time on 
file"));
          return -1;
        }
       }
@@ -1539,6 +1539,11 @@
   }
 }
 
+static int maildir_commit_message (CONTEXT * ctx, MESSAGE * msg)
+{
+  return _maildir_commit_message (ctx, msg, NULL);
+}
+
 /* 
  * commit a message to an MH folder.
  * 
@@ -1620,9 +1625,9 @@
   return 0;
 }
 
-int mh_commit_message (CONTEXT * ctx, MESSAGE * msg, HEADER * hdr)
+static int mh_commit_message (CONTEXT * ctx, MESSAGE * msg)
 {
-  return _mh_commit_message (ctx, msg, hdr, 1);
+  return _mh_commit_message (ctx, msg, NULL, 1);
 }
 
 
@@ -1657,7 +1662,7 @@
     strfcpy (partpath, h->path, _POSIX_PATH_MAX);
 
     if (ctx->magic == MUTT_MAILDIR)
-      rc = maildir_commit_message (ctx, dest, h);
+      rc = _maildir_commit_message (ctx, dest, h);
     else
       rc = _mh_commit_message (ctx, dest, h, 0);
 
@@ -2451,6 +2456,7 @@
   .close = mh_close_mailbox,
   .open_msg = maildir_open_message,
   .close_msg = mh_close_message,
+  .commit_msg = maildir_commit_message,
   .open_new_msg = maildir_open_new_message,
   .check = maildir_check_mailbox,
 };
@@ -2460,6 +2466,7 @@
   .close = mh_close_mailbox,
   .open_msg = mh_open_message,
   .close_msg = mh_close_message,
+  .commit_msg = mh_commit_message,
   .open_new_msg = mh_open_new_message,
   .check = mh_check_mailbox,
 };
diff -r ce2e5caf4339 -r 91af19866bbd mutt.h
--- a/mutt.h    Sat Jun 18 12:41:45 2016 -0700
+++ b/mutt.h    Sat Jun 18 13:36:25 2016 -0700
@@ -896,6 +896,7 @@
   int (*check) (struct _context *ctx, int *index_hint);
   int (*open_msg) (struct _context *, struct _message *, int msgno);
   int (*close_msg) (struct _context *, struct _message *);
+  int (*commit_msg) (struct _context *, struct _message *);
   int (*open_new_msg) (struct _message *, struct _context *, HEADER *);
 };
 
diff -r ce2e5caf4339 -r 91af19866bbd mx.c
--- a/mx.c      Sat Jun 18 12:41:45 2016 -0700
+++ b/mx.c      Sat Jun 18 13:36:25 2016 -0700
@@ -1329,8 +1329,12 @@
 
 int mx_commit_message (MESSAGE *msg, CONTEXT *ctx)
 {
+  struct mx_ops *ops = mx_get_ops (ctx->magic);
   int r = 0;
 
+  if (!ops || !ops->commit_msg)
+    return -1;
+
   if (!(msg->write && ctx->append))
   {
     dprint (1, (debugfile, "mx_commit_message(): msg->write = %d, ctx->append 
= %d\n",
@@ -1338,43 +1342,7 @@
     return -1;
   }
 
-  switch (ctx->magic)
-  {
-    case MUTT_MMDF:
-    {
-      if (fputs (MMDF_SEP, msg->fp) == EOF)
-       r = -1;
-      break;
-    }
-    
-    case MUTT_MBOX:
-    {
-      if (fputc ('\n', msg->fp) == EOF)
-       r = -1;
-      break;
-    }
-
-#ifdef USE_IMAP
-    case MUTT_IMAP:
-    {
-      if ((r = safe_fclose (&msg->fp)) == 0)
-       r = imap_append_message (ctx, msg);
-      break;
-    }
-#endif
-    
-    case MUTT_MAILDIR:
-    {
-      r = maildir_commit_message (ctx, msg, NULL);
-      break;
-    }
-    
-    case MUTT_MH:
-    {
-      r = mh_commit_message (ctx, msg, NULL);
-      break;
-    }
-  }
+  r = ops->commit_msg (ctx, msg);
   
   if (r == 0 && (ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF)
       && (fflush (msg->fp) == EOF || fsync (fileno (msg->fp)) == -1))
diff -r ce2e5caf4339 -r 91af19866bbd mx.h
--- a/mx.h      Sat Jun 18 12:41:45 2016 -0700
+++ b/mx.h      Sat Jun 18 13:36:25 2016 -0700
@@ -57,9 +57,6 @@
 
 int maildir_check_empty (const char *);
 
-int maildir_commit_message (CONTEXT *, MESSAGE *, HEADER *);
-int mh_commit_message (CONTEXT *, MESSAGE *, HEADER *);
-
 FILE *maildir_open_find_message (const char *, const char *);
 
 int mbox_strict_cmp_headers (const HEADER *, const HEADER *);

Reply via email to