MailMover: Handle messages that have multiple copies #67
I've modified MailMover.move to deal with a couple of issues I had getting it to work with my Gmail-via-IMAP setup:
The first two issues are bugs I ran into as I tried to get MailMover to work with my mail setup, which contains multiple copies of most messages.
The third change is a side-effect of how I solved the first two issues. My version changes the way messages are moved. Multiple rules now can now be applied to a message in a given source maildir; each rule will copy the messge to a destination maildir, and then the original will be deleted when all copies have been made, i.e., after all rules have been applied. (I have also changed the documentation to reflect this.) For my setup, this is the behavior I want, but I don't know if it's how MailMover.move should work in general. Maybe the right thing to do instead would be to implement this behavior in a subclass? If so, this will require solving the first two issues in a different way.
P.S. This is my first GitHub pull request, so please let me know if I've done it wrong or you need more information!
Gmail in particular tends to put copies of a single message in multiple maildirs. notmuch groups these all into a single message (with a single Message-ID) with multiple associated files. This commit provides better support for moving mail files when multiple copies of a message exist, e.g., when a copy already exists in the destination maildir. This commit also supports copying a message to multiple destinations. A message that matches multiple queries will be copied to every destination associated with those queries, rather than just the first. Thus, it changes afew's movement behavior slightly. (This change was a side-effect of implementing support for messages that exist in multiple locations in the simplest way. Moving a message immediately from its source location without updating the notmuch db will cause an error when subsequent queries match the message but its associated file is no longer at the path notmuch thinks it is. To avoid this, we postpone deletions until all copies associated with all rules have occurred.)