teythoon/afew — pull request #67 by wyleyr (2014-01-01 21:28:24+00:00)
Title: MailMover: Handle messages that have multiple copies

I've modified MailMover.move to deal with a couple of issues I had getting it to work with my Gmail-via-IMAP setup:

1. Fixed: catch and ignore error when a copy of the message already exists at the destination (e.g., moving a message from INBOX to Archive)
1. Fixed: when multiple copies of a message exist, move only deletes exactly the copy that resides in the maildir to which a move rule applies (this did not work before...the move would delete whatever copy of the message was returned by message.get_filename(), which was not necessarily in the maildir to which the rule applies)
1. Added: ability to apply multiple rules to a message, i.e., move it to multiple folders (desirable, since folders represent Gmail labels in my 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!