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 e90c6f0d7..ce57953b4 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); } } @@ -670,7 +671,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..b4da827d2 100644 --- a/src/db.cc +++ b/src/db.cc @@ -327,14 +327,36 @@ 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); + 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 ()); + } + + // 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 4cad1a5d7..915c18e3d 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);