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

MailMover: Handle messages that have multiple copies #67

Merged
merged 3 commits into from
Jan 3, 2014

Conversation

wyleyr
Copy link
Contributor

@wyleyr wyleyr commented Jan 1, 2014

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)
  2. 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)
  3. 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!

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.)
teythoon pushed a commit that referenced this pull request Jan 3, 2014
MailMover: Handle messages that have multiple copies
@teythoon teythoon merged commit 7317eb0 into afewmail:master Jan 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants