]> granicus.if.org Git - neomutt/commitdiff
update DB on save-command
authorKarel Zak <kzak@redhat.com>
Mon, 14 Oct 2013 18:34:57 +0000 (11:34 -0700)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 15:30:07 +0000 (16:30 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
commands.c
copy.c
mutt_notmuch.c

index 027df56b19d7549329aafe0422ef63ca0cb7781f..3bb46496b6a721bab6eebed3366068e6c107cc7b 100644 (file)
 #include "imap.h"
 #endif
 
+#ifdef USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
+
 #include "buffy.h"
 
 #include <errno.h>
@@ -848,19 +852,30 @@ int mutt_save_message (HEADER *h, int delete,
     }
     else
     {
+      int rc = 0;
+
+#ifdef USE_NOTMUCH
+      if (Context->magic == M_NOTMUCH)
+        nm_longrun_init(Context, TRUE);
+#endif
       for (i = 0; i < Context->vcount; i++)
       {
        if (Context->hdrs[Context->v2r[i]]->tagged)
        {
          mutt_message_hook (Context, Context->hdrs[Context->v2r[i]], M_MESSAGEHOOK);
-         if (_mutt_save_message(Context->hdrs[Context->v2r[i]],
-                            &ctx, delete, decode, decrypt) != 0)
-          {
-            mx_close_mailbox (&ctx, NULL);
-            return -1;
-          }
+         if ((rc = _mutt_save_message(Context->hdrs[Context->v2r[i]],
+                            &ctx, delete, decode, decrypt) != 0))
+           break;
        }
       }
+#ifdef USE_NOTMUCH
+      if (Context->magic == M_NOTMUCH)
+        nm_longrun_done(Context);
+#endif
+      if (rc != 0) {
+       mx_close_mailbox (&ctx, NULL);
+       return -1;
+      }
     }
 
     need_buffy_cleanup = (ctx.magic == M_MBOX || ctx.magic == M_MMDF);
diff --git a/copy.c b/copy.c
index cf490ffebe860fd25dadf5a41438be561a96cfa4..1da189e5bbbe1b71106d88f04c12330abaff8085 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -741,8 +741,12 @@ _mutt_append_message (CONTEXT *dest, FILE *fpin, CONTEXT *src, HEADER *hdr,
   if (mx_commit_message (msg, dest) != 0)
     r = -1;
 
-  mx_close_message (&msg);
+#ifdef USE_NOTMUCH
+  if (hdr && msg->commited_path && dest->magic == M_MAILDIR && src->magic == M_NOTMUCH)
+         nm_update_filename(src, NULL, msg->commited_path, hdr);
+#endif
 
+  mx_close_message (&msg);
   return r;
 }
 
index 5e6e5a367c9c118d39eaa6938176cdd87803c804..5be51ebb3a708665a735d1b0286fbbbc2409aa89 100644 (file)
@@ -1349,9 +1349,11 @@ static int remove_filename(notmuch_database_t *db, const char *path)
        st = notmuch_database_remove_message(db, path);
        switch (st) {
        case NOTMUCH_STATUS_SUCCESS:
+               dprint(2, (debugfile, "nm: remove success, call unlink\n"));
                unlink(path);
                break;
        case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
+               dprint(2, (debugfile, "nm: remove succes (duplicate), call unlink\n"));
                unlink(path);
                for (ls = notmuch_message_get_filenames(msg);
                     ls && notmuch_filenames_valid(ls);
@@ -1420,6 +1422,8 @@ static int rename_filename(notmuch_database_t *db,
                        if (strcmp(new, path) == 0)
                                continue;
 
+                       dprint(2, (debugfile, "nm: rename: syncing duplicate: %s\n", path));
+
                        if (rename_maildir_filename(path, newpath, sizeof(newpath), h) == 0) {
                                dprint(2, (debugfile, "nm: rename dup %s -> %s\n", path, newpath));
                                notmuch_database_remove_message(db, path);
@@ -1449,12 +1453,24 @@ done:
 
 int nm_update_filename(CONTEXT *ctx, const char *old, const char *new, HEADER *h)
 {
+       char buf[PATH_MAX];
+       int rc;
        struct nm_ctxdata *data = get_ctxdata(ctx);
 
-       if (!data || !new || !old)
+       if (!data || !new)
                return -1;
 
-       return rename_filename(get_db(data, TRUE), old, new, h);
+       if (!old && h && h->data) {
+               nm_header_get_fullpath(h, buf, sizeof(buf));
+               old = buf;
+       }
+
+       rc = rename_filename(get_db(data, TRUE), old, new, h);
+
+       if (!is_longrun(data))
+               release_db(data);
+       ctx->mtime = time(NULL);
+       return rc;
 }
 
 int nm_sync(CONTEXT *ctx, int *index_hint)