Synchronize gmail labels

Hi,

This big pull-request adds functionality to store gmail labels in a special email header X-Keywords, and sync them just like IMAP flags.

I sent patches to the offlineimap mailing list almost a year ago, here is the thread:

http://comments.gmane.org/gmane.mail.imap.offlineimap.general/5943

Last january X Ryl contacted me about merging this. He asked me to make the labels stuff available also for the plaintext backend, and well, I didn't find the time to do it, so nothing happened. Now here it is.

This pull request contains the original labels stuff, plus several bugfixes thanks to some people who have started using it, and reported problems, plus support for the plaintext backend.

I'm hoping this could be merged, as it is a very useful feature for us label-enthusiast gmail users, and now it has had some reasonable testing.

A summary of what is contained in this pull request:

  1. When a message goes out of gmail server, adds a header X-Keywords with a comma separated list of labels.

  3. Updates the LocalStatus (both, sqlite and plaintext) to include columns for labels and local mtimes. For non-gmail repositories these columns are ignored.

     Also functionality is implemented to migrate between backends and upgrade format in both, plaintext and sqlite (the last batch of commits)

  4. When labels change on the gmail side, syncs them the same way as flags get synced (comparing with LocalStatus etc)

  5. Adds a GmailMaildir folder type, which keeps track of individual message modification times (the POSIX mtime), and uses it to spot messages which have been modified locally. Then, only for those modified messages (typically very few), reads the labels and syncs them back to gmail, the same way as flags.

  6. Adds an option to filter out certain headers when uploading messages to gmail. One may want to remove X-Keywords before sending a message back to gmail.

  7. Adds an option to ignore certain labels, like \Draft, for which flags serve the same purpose. Gmail internally keeps the D flag in sync with the \Draft label, or the F flag with the \Starred label.

Feel free to contact me for additional fixes, required before merging.