#include "imap.h"
#endif
+#ifdef USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
+
#include "buffy.h"
#include <errno.h>
}
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);
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;
}
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);
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);
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)