I finally got around to working on it and over the last two days have gotten two-way gmail syncing with labels working.

The list of caveats is much longer than the list of details:

1) only tested with 100 messages, which is hard coded
2) doesn't update UIDs of messages on disk, though it mostly avoids situations where that would be an issue
3) Can only do a full, scan every file sync, but it assumes that message content is immutable so only adds new messages
4) Doesn't support syncing new/deleted messages from notmuch -> gmail (not sure this is worth the trouble)
5) Quoting issues, i'm sure.


The basic approach is to get the difference between a the last sync and the current notmuch state, sync the diff of labels to gmail, than we request UID, X-GM-MSGID, Message-ID, and X-GM-LABELS from gmail for every message, if it lacks a message-id we build a notmuch-sha1- one, hopefully that approach won't change, we then write new messages to disk by using the filename GMID=...,UID=.... to store that information, and then sync the labels (with a mapping for special labels like sent, etc), then we look for messages that have changed in gmail but not changed locally, and sync their labels.

I'm sure it won't work for you, but you might try it. :)

source is at http://alexbl.net/~alexbl/imapsync.py

p.s. I also ran into an issue with the notmuch python bindings where I had to wrap every c_void_p in POINTER() or it would segfault for any method that tried to use a pointer. Also the sed command that tries to build notmuch.sym doesn't work on freebsd, i changed it to work, but i'm pretty sure it won't work on linux anymore. :) I wonder if using ctags might actually work for that.

alex