From: Karel Zak Date: Sun, 23 Sep 2012 07:31:54 +0000 (+0200) Subject: add $record support X-Git-Tag: neomutt-20160317~5^2~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=73ae4d2b67bcdf841879bc5a52729c86e70ce70f;p=neomutt add $record support Signed-off-by: Karel Zak --- diff --git a/README.notmuch b/README.notmuch index f2e30f552..701fbb912 100644 --- a/README.notmuch +++ b/README.notmuch @@ -140,6 +140,22 @@ notmuch support for mutt the sidebar. It's possible to toggle between virtual and normal folders by sidebar-toggle command. + nm_record = + + Add messages stored to the mutt record (see $record in the mutt docs) + also to notmuch DB. If you reply to an email then the new email inherits + tags from the original email. + + nm_record_tags = + + Tags that should be removed or added to the to the messages stored in the mutt record. + + example: + + set record = "~/sent-mails" + set nm_record = yes + set nm_record_tags = "-inbox,archive,me" + nm_open_timeout = This option specifies timeout for Notmuch database. Default is 5 seconds. @@ -214,6 +230,10 @@ notmuch support for mutt * .muttrc example: + set record="~/Mail/Maildir/sent-mail" + set nm_record = yes + set nm_record_tags ="-inbox me archive" + set nm_default_uri="notmuch:///home/kzak/Mail/Maildir" set virtual_spoolfile = yes diff --git a/compose.c b/compose.c index 0bd17b633..f84389061 100644 --- a/compose.c +++ b/compose.c @@ -1226,7 +1226,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ if (msg->content->next) msg->content = mutt_make_multipart (msg->content); - if (mutt_write_fcc (fname, msg, NULL, 0, NULL) < 0) + if (mutt_write_fcc (fname, msg, NULL, 0, NULL, NULL) < 0) msg->content = mutt_remove_multipart (msg->content); else mutt_message _("Message written."); diff --git a/globals.h b/globals.h index e8b2e40a4..36d489209 100644 --- a/globals.h +++ b/globals.h @@ -286,6 +286,7 @@ WHERE char *NotmuchHiddenTags; WHERE char *VirtFolderFormat; WHERE int NotmuchDBLimit; WHERE char *NotmuchQueryType; +WHERE char *NotmuchRecordTags; #endif diff --git a/init.h b/init.h index 057654d1b..8df5bfbea 100644 --- a/init.h +++ b/init.h @@ -1685,6 +1685,16 @@ struct option_t MuttVars[] = { ** .pp ** This variable specifies the default query type (threads or messages) used in notmuch queries. */ + { "nm_record", DT_BOOL, R_NONE, OPTNOTMUCHRECORD, 0 }, + /* + ** .pp + ** This variable specifies if the mutt record should indexed by notmuch. + */ + { "nm_record_tags", DT_STR, R_NONE, UL &NotmuchRecordTags, 0 }, + /* + ** .pp + ** This variable specifies the default tags applied to messages stored to the mutt record. + */ #endif { "pager", DT_PATH, R_NONE, UL &Pager, UL "builtin" }, /* diff --git a/mutt.h b/mutt.h index b3457da7d..efbc55fc7 100644 --- a/mutt.h +++ b/mutt.h @@ -542,6 +542,7 @@ enum #ifdef USE_NOTMUCH OPTVIRTSPOOLFILE, + OPTNOTMUCHRECORD, #endif OPTMAX diff --git a/mutt_notmuch.c b/mutt_notmuch.c index 6eb14c7b0..2c3e72bcc 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -1541,6 +1541,52 @@ done: new_flags ? M_FLAGS : 0; } +int nm_record_message(CONTEXT *ctx, char *path, HEADER *h) +{ + notmuch_database_t *db; + notmuch_status_t st; + notmuch_message_t *msg; + int rc = -1; + struct nm_ctxdata *data = get_ctxdata(ctx); + + if (!path || !data || access(path, F_OK) != 0) + return 0; + db = get_db(data, TRUE); + if (!db) + return -1; + + dprint(1, (debugfile, "nm: record message: %s\n", path)); + st = notmuch_database_begin_atomic(db); + if (st) + return -1; + + st = notmuch_database_add_message(db, path, &msg); + + if (st != NOTMUCH_STATUS_SUCCESS && + st != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { + dprint(1, (debugfile, "nm: failed to add '%s' [st=%d]\n", path, (int) st)); + goto done; + } + + if (st == NOTMUCH_STATUS_SUCCESS && msg) { + notmuch_message_maildir_flags_to_tags(msg); + if (h) + update_tags(msg, nm_header_get_tags(h)); + if (NotmuchRecordTags) + update_tags(msg, NotmuchRecordTags); + } + + rc = 0; +done: + if (msg) + notmuch_message_destroy(msg); + notmuch_database_end_atomic(db); + + if (!is_longrun(data)) + release_db(data); + return rc; +} + /* * Fill a list with all notmuch tags. * @@ -1556,7 +1602,7 @@ int nm_get_all_tags(CONTEXT *ctx, char **tag_list, int *tag_count) if (!data) return -1; - if (!(db = get_db(data, TRUE)) || + if (!(db = get_db(data, FALSE)) || !(tags = notmuch_database_get_all_tags(db))) goto done; diff --git a/mutt_notmuch.h b/mutt_notmuch.h index bc769eca0..7ea77f394 100644 --- a/mutt_notmuch.h +++ b/mutt_notmuch.h @@ -20,6 +20,8 @@ void nm_longrun_done(CONTEXT *cxt); char *nm_get_description(CONTEXT *ctx); +int nm_record_message(CONTEXT *ctx, char *path, HEADER *h); + void nm_debug_check(CONTEXT *ctx); int nm_get_all_tags(CONTEXT *ctx, char **tag_list, int *tag_count); diff --git a/protos.h b/protos.h index b0745c05d..92fd052f1 100644 --- a/protos.h +++ b/protos.h @@ -375,7 +375,7 @@ int mutt_user_is_recipient (HEADER *); void mutt_update_num_postponed (void); int mutt_wait_filter (pid_t); int mutt_which_case (const char *); -int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, char *); +int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, char *, char **); int mutt_write_mime_body (BODY *, FILE *); int mutt_write_mime_header (BODY *, FILE *); int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, int flags); diff --git a/send.c b/send.c index d4e2a7974..6bec03697 100644 --- a/send.c +++ b/send.c @@ -48,6 +48,9 @@ #include "remailer.h" #endif +#ifdef USE_NOTMUCH +#include "mutt_notmuch.h" +#endif static void append_signature (FILE *f) { @@ -1156,6 +1159,7 @@ ci_send_message (int flags, /* send mode */ char *smime_default_key = NULL; char *tag = NULL, *err = NULL; char *ctype; + char *finalpath = NULL; int rv = -1; @@ -1628,7 +1632,9 @@ main_loop: mutt_prepare_envelope (msg->env, 0); mutt_env_to_idna (msg->env, NULL, NULL); /* Handle bad IDNAs the next time. */ - if (!Postponed || mutt_write_fcc (NONULL (Postponed), msg, (cur && (flags & SENDREPLY)) ? cur->env->message_id : NULL, 1, fcc) < 0) + if (!Postponed || mutt_write_fcc (NONULL (Postponed), msg, + (cur && (flags & SENDREPLY)) ? + cur->env->message_id : NULL, 1, fcc, NULL) < 0) { msg->content = mutt_remove_multipart (msg->content); decode_descriptions (msg->content); @@ -1810,7 +1816,7 @@ full_fcc: * message was first postponed. */ msg->received = time (NULL); - if (mutt_write_fcc (fcc, msg, NULL, 0, NULL) == -1) + if (mutt_write_fcc (fcc, msg, NULL, 0, NULL, &finalpath) == -1) { /* * Error writing FCC, we should abort sending. @@ -1871,6 +1877,7 @@ full_fcc: msg->content = mutt_remove_multipart (msg->content); decode_descriptions (msg->content); mutt_unprepare_envelope (msg->env); + FREE(&finalpath); goto main_loop; } else @@ -1879,8 +1886,13 @@ full_fcc: goto cleanup; } } - else if (!option (OPTNOCURSES) && ! (flags & SENDMAILX)) + else if (!option (OPTNOCURSES) && ! (flags & SENDMAILX)) { mutt_message (i == 0 ? _("Mail sent.") : _("Sending in background.")); +#ifdef USE_NOTMUCH + if (option(OPTNOTMUCHRECORD)) + nm_record_message(ctx, finalpath, cur); +#endif + } if (WithCrypto && (msg->security & ENCRYPT)) FREE (&pgpkeylist); @@ -1924,7 +1936,7 @@ cleanup: safe_fclose (&tempfp); mutt_free_header (&msg); - + FREE(&finalpath); return rv; } diff --git a/sendlib.c b/sendlib.c index 446f6146d..4f7dfa8da 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2684,7 +2684,8 @@ static void set_noconv_flags (BODY *b, short flag) } } -int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, char *fcc) +int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, + int post, char *fcc, char **finalpath) { CONTEXT f; MESSAGE *msg; @@ -2873,6 +2874,8 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, if (mx_commit_message (msg, &f) != 0) r = -1; + else if (finalpath) + *finalpath = safe_strdup(msg->commited_path); mx_close_message (&msg); mx_close_mailbox (&f, NULL);