From cddbc42a3e15256b3dcea962a496e9398282d3a9 Mon Sep 17 00:00:00 2001 From: Lars Kotthoff Date: Sat, 20 Oct 2018 13:48:35 -0600 Subject: [PATCH 1/2] allow to tag sent messages with same tags as message being replied to --- src/actions/onmessage.cc | 5 +++-- src/actions/onmessage.hh | 3 ++- src/compose_message.cc | 5 +++-- src/db.cc | 29 +++++++++++++++++++++++++++-- src/db.hh | 2 +- src/modes/reply_message.cc | 2 +- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/actions/onmessage.cc b/src/actions/onmessage.cc index 1bcb8f959..57c6d5a1a 100644 --- a/src/actions/onmessage.cc +++ b/src/actions/onmessage.cc @@ -62,13 +62,14 @@ namespace Astroid { astroid->actions->emit_message_updated (db, mid); } - AddSentMessage::AddSentMessage (ustring _f, std::vector _additional_sent_tags) { + AddSentMessage::AddSentMessage (ustring _f, std::vector _additional_sent_tags, ustring _parent_mid) { fname = _f; additional_sent_tags = _additional_sent_tags; + parent_mid = _parent_mid; } bool AddSentMessage::doit (Db * db) { - mid = db->add_sent_message (fname, additional_sent_tags); + mid = db->add_sent_message (fname, additional_sent_tags, parent_mid); return true; } diff --git a/src/actions/onmessage.hh b/src/actions/onmessage.hh index 221ba7612..cc31effe3 100644 --- a/src/actions/onmessage.hh +++ b/src/actions/onmessage.hh @@ -41,7 +41,7 @@ namespace Astroid { class AddSentMessage : public Action { public: - AddSentMessage (ustring fname, std::vector additional_sent_tags); + AddSentMessage (ustring fname, std::vector additional_sent_tags, ustring parent_mid); virtual bool doit (Db *) override; virtual bool undo (Db *) override; @@ -52,6 +52,7 @@ namespace Astroid { ustring fname; ustring mid; std::vector additional_sent_tags; + ustring parent_mid; }; } diff --git a/src/compose_message.cc b/src/compose_message.cc index b6a1a2596..a7ca70c6a 100644 --- a/src/compose_message.cc +++ b/src/compose_message.cc @@ -99,8 +99,9 @@ namespace Astroid { g_mime_object_get_header_list (GMIME_OBJECT(message)), "In-Reply-To"); } else { + ustring tmp = "<" + inreplyto + ">"; g_mime_object_set_header (GMIME_OBJECT(message), "In-Reply-To", - inreplyto.c_str(), NULL); + tmp.c_str(), NULL); } } @@ -671,7 +672,7 @@ namespace Astroid { /* add to notmuch with sent tag (on main GUI thread) */ if (!dryrun && message_sent_result && account->save_sent) { astroid->actions->doit (refptr ( - new AddSentMessage (save_to.c_str (), account->additional_sent_tags))); + new AddSentMessage (save_to.c_str (), account->additional_sent_tags, inreplyto))); LOG (info) << "cm: sent message added to db."; } diff --git a/src/db.cc b/src/db.cc index b29e6a99f..fdfceed94 100644 --- a/src/db.cc +++ b/src/db.cc @@ -327,14 +327,39 @@ namespace Astroid { return _mid; } - ustring Db::add_sent_message (ustring fname, vector additional_sent_tags) { + ustring Db::add_sent_message (ustring fname, vector additional_sent_tags, ustring parent_mid) { LOG (info) << "db: adding sent message: " << fname; additional_sent_tags.insert (additional_sent_tags.end (), sent_tags.begin (), sent_tags.end ()); + + if (!parent_mid.empty () && + find(additional_sent_tags.begin(), additional_sent_tags.end(), "*") != additional_sent_tags.end()) { + notmuch_message_t * parent_msg; + notmuch_database_find_message (nm_db, parent_mid.c_str (), &parent_msg); + vector parent_tags; + for (notmuch_tags_t * tags = notmuch_message_get_tags (parent_msg); notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) { + parent_tags.push_back (notmuch_tags_get (tags)); + } + + additional_sent_tags.insert (additional_sent_tags.end (), parent_tags.begin (), parent_tags.end ()); + } + + // filter tags prefixed with '-' + vector filtered_tags; + copy_if (additional_sent_tags.begin(), additional_sent_tags.end(), back_inserter(filtered_tags), [] (ustring s) { return s[0] == '-'; } ); + additional_sent_tags.erase( + remove_if(additional_sent_tags.begin(), additional_sent_tags.end(), + [&filtered_tags] (ustring s) { + return s == "*" || + find(filtered_tags.begin(), filtered_tags.end(), s) != filtered_tags.end() || + find(filtered_tags.begin(), filtered_tags.end(), '-' + s) != filtered_tags.end(); + }), + additional_sent_tags.end()); + + sort (additional_sent_tags.begin (), additional_sent_tags.end ()); additional_sent_tags.erase (unique (additional_sent_tags.begin (), additional_sent_tags.end ()), additional_sent_tags.end ()); - return add_message_with_tags (fname, additional_sent_tags); } diff --git a/src/db.hh b/src/db.hh index fc4e11bfd..7a79217e4 100644 --- a/src/db.hh +++ b/src/db.hh @@ -144,7 +144,7 @@ namespace Astroid { static std::vector draft_tags; static std::vector excluded_tags; - ustring add_sent_message (ustring, std::vector); + ustring add_sent_message (ustring, std::vector, ustring); ustring add_draft_message (ustring); ustring add_message_with_tags (ustring fname, std::vector tags); bool remove_message (ustring); diff --git a/src/modes/reply_message.cc b/src/modes/reply_message.cc index c3b673d2b..4bfe96ef5 100644 --- a/src/modes/reply_message.cc +++ b/src/modes/reply_message.cc @@ -72,7 +72,7 @@ namespace Astroid { body = ustring(quoted.str()); references = msg->references + " <" + msg->mid + ">"; - inreplyto = "<" + msg->mid + ">"; + inreplyto = msg->mid; /* reply mode combobox */ reply_revealer->set_reveal_child (true); From c0681fc734621ce2352998e27c6cbad437d2155b Mon Sep 17 00:00:00 2001 From: Lars Kotthoff Date: Sun, 21 Oct 2018 19:37:13 -0600 Subject: [PATCH 2/2] use NotmuchMessage --- src/db.cc | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/db.cc b/src/db.cc index fdfceed94..b4da827d2 100644 --- a/src/db.cc +++ b/src/db.cc @@ -335,11 +335,8 @@ namespace Astroid { find(additional_sent_tags.begin(), additional_sent_tags.end(), "*") != additional_sent_tags.end()) { notmuch_message_t * parent_msg; notmuch_database_find_message (nm_db, parent_mid.c_str (), &parent_msg); - vector parent_tags; - for (notmuch_tags_t * tags = notmuch_message_get_tags (parent_msg); notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) { - parent_tags.push_back (notmuch_tags_get (tags)); - } - + NotmuchMessage parent_msg_nm = NotmuchMessage(parent_msg); + vector parent_tags = parent_msg_nm.tags; additional_sent_tags.insert (additional_sent_tags.end (), parent_tags.begin (), parent_tags.end ()); }