Extending notmuch tags from messages to the whole thread

I am using notmuch and alot to read email at home.

As a fallback mechanism, I have written a small script that moves emails with certain tags into specific folders, such that parts of the tags can be seen from any email client accessing the mail folder.

Unfortunately, alot seems to tag individual messages instead of complete threads. This means that all the mails that I receive are correctly sorted, but the mails I sent are kept in the sent folder forever.

Luckily, it is easy to propagate tags from individual messages to the complete thread using:

for i in $(notmuch search --output=threads tag:<some_tag>); do; notmuch tag +<some_tag> -- $i; done

This is using zsh, but bash should work the same. I am sharing this here in case somebody might find this useful.