After syncing my local maildir inboxes with offlineimap and performing spam filtering and sorting using fdm+bogofilter, I tag the messages in the mail store using notmuch.
Up until recently, I used the following shell code to tag and re-tag messages depending on certain criteria:
notmuch new
tr -s '\t' ' ' <<'END_BATCH' | notmuch tag --batch
-inbox +sent -- folder:/Sent/
-inbox +archive -- folder:/Archive/
-inbox +junk -- folder:/Junk/
+unsorted -- folder:/INBOX.Unsorted/
-unsorted -- not folder:/INBOX.Unsorted/
-unread -- tag:archive
+unread -- tag:unsorted
END_BATCH
This removes the inbox tag from any message in a Sent, Archive or Junk folder, while retagging the messages with the appropriate tags for those three folders. It then tags or untags messages depending on whether they are in an INBOX.Unsorted folder (where I put messages that bogofilter couldn't classify). Lastly, I ensure that archived messages are not tagged as unread and that unsorted messages are tagged as unread.
This worked well.
Since I receive mail on five different accounts, I then also wanted to add tags like account-somename, account-othername etc. to messages, depending on the folder name:
notmuch new
tr -s '\t' ' ' <<'END_BATCH' | notmuch tag --batch
-inbox +sent -- folder:/Sent/
-inbox +archive -- folder:/Archive/
-inbox +junk -- folder:/Junk/
+unsorted -- folder:/INBOX.Unsorted/
-unsorted -- not folder:/INBOX.Unsorted/
-unread -- tag:archive
+unread -- tag:unsorted
+account-acc1 -- folder:/acc1/
+account-acc2 -- folder:/acc2/
+account-acc3 -- folder:/acc3/
+account-acc4 -- folder:/acc4/
+account-acc5 -- folder:/acc5/
END_BATCH
The tagging seems to be performed as expected, but a side-effect is that new messages are marked as old (moved from the maildir's new directory to the cur directory). This in turn means mutt won't detect the new messages in the inboxes (unless I set maildir_check_cur in the mutt configuration, which I don't think is a nice solution).
I don't know why or what I could do to stop this from happening.
My notmuch configuration:
[database]
path=/home/myself/Mail/inboxes
[user]
name=myname
[email protected]
[email protected]
[new]
tags=inbox;unread
[search]
[maildir]
syncronize_flags=true
[index]
header.List=List-Id