Moving messages redux

Edward Z. Yang ezyang at MIT.EDU
Wed Aug 22 06:43:21 BST 2012

There is a little bit more trickiness involved in actually performing
the move without needing to read out the local folder / remote folder
message list into memory (which is pretty expensive):

Parameters: every move event gives us: oldfolder, newfolder, oldfilename and
newfilename. (Note newfolder/filename is present in Maildir, uid of oldfilename
is present in IMAP)

- Pop move event off move queue
- Lookup old and new folder objects both local and IMAP
  (or create them from scratch; this is pretty cheap)
- Parse oldfilename into uid
- Parse newfilename into flags
- Initialize the messagelist entry for this uid (so that
  cache lookups for *just this message* work)

In IMAP land (this is new function)
- Check if uid exists in old folder on server
- Initiate IMAP COPY from old folder to new folder on server,
  retrieving the new assigned ID
- Delete old ID

In Maildir land (implemented the old way)
- Rename the maildir copy according to new ID reported from server.

Note that we don't need to update IMAP flags, since
we're not updating LocalStatus the message will get
looked at again.

An alternative strategy is to update LocalStatus and save traversing all the
new messages (must read out all of local status and update it).  Flags must be

If any step fails, we can just bail out and do it the slowpath.


P.S. You don't even need to use inotify; if your mail client cooperates
and records folder move information, OfflineIMAP can just read that out.

Excerpts from Edward Z. Yang's message of Tue Aug 21 22:34:56 -0400 2012:
> Hello all,
> A while back there was a conversation [1] about how OfflineIMAP might
> be able to detect moved messages and use the COPY command in order to
> avoid having to reupload the message from scratch.  The conclusion was
> it was too hard.
> Now, I am in a situation of wanting to move 150k messages from one
> folder to another (Maildir side), and sync this to the server, and
> the reupload behavior will be a *big drag* (especially since I don't
> even have space on the server for all of my Maildir messages, and
> don't *want* all of them to sync).  But no worries: I have a plan:
> Inotify.
> I'm planning on implementing my local folder moves to use rename(2), and
> have OfflineIMAP looking for IN_MOVED_FROM/IN_MOVED_TO events.  If it
> sees one, it conducts the move by issuing a COPY command and then
> deleting the original.
> Sound like a good plan? Bad idea? Anyone else interested in this
> functionality?  I think this might integrate well with an inotify edition
> of OfflineIMAP, which does all push synchronization based off of inotify
> events.  (Also, do I want UID COPY or COPY?)
> Cheers,
> Edward
> [1]

More information about the OfflineIMAP-project mailing list