Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to tag sent messages with same tags as message being replied to #581

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/actions/onmessage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ namespace Astroid {
astroid->actions->emit_message_updated (db, mid);
}

AddSentMessage::AddSentMessage (ustring _f, std::vector<ustring> _additional_sent_tags) {
AddSentMessage::AddSentMessage (ustring _f, std::vector<ustring> _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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/actions/onmessage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Astroid {

class AddSentMessage : public Action {
public:
AddSentMessage (ustring fname, std::vector<ustring> additional_sent_tags);
AddSentMessage (ustring fname, std::vector<ustring> additional_sent_tags, ustring parent_mid);

virtual bool doit (Db *) override;
virtual bool undo (Db *) override;
Expand All @@ -52,6 +52,7 @@ namespace Astroid {
ustring fname;
ustring mid;
std::vector<ustring> additional_sent_tags;
ustring parent_mid;
};

}
5 changes: 3 additions & 2 deletions src/compose_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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<Action> (
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.";
}

Expand Down
29 changes: 27 additions & 2 deletions src/db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,39 @@ namespace Astroid {
return _mid;
}

ustring Db::add_sent_message (ustring fname, vector<ustring> additional_sent_tags) {
ustring Db::add_sent_message (ustring fname, vector<ustring> 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to use on_message here, takes care of cleaning up the parent_msg. Might also be better to instantiate a NotmuchMessage on parent_msg, there is already a get_tags function which is more robust. NotmuchMessage should be cheap objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll have a look at that.

notmuch_database_find_message (nm_db, parent_mid.c_str (), &parent_msg);
vector<ustring> 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<ustring> 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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/db.hh
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace Astroid {
static std::vector<ustring> draft_tags;
static std::vector<ustring> excluded_tags;

ustring add_sent_message (ustring, std::vector<ustring>);
ustring add_sent_message (ustring, std::vector<ustring>, ustring);
ustring add_draft_message (ustring);
ustring add_message_with_tags (ustring fname, std::vector<ustring> tags);
bool remove_message (ustring);
Expand Down
2 changes: 1 addition & 1 deletion src/modes/reply_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down