This program can pull email and labels (and changes to labels) from your GMail account and store them locally in a maildir with the labels synchronized with a notmuch database. The changes to tags in the notmuch database may be pushed back remotely to your GMail account.
Store messages in a Maildir into a couchdb database.
isync: free IMAP and MailDir mailbox synchronizer
Sync Mail Dir (smd) is a set of tools to synchronize a pair of mailboxes in Maildir format. It is Free Software, released under the terms of GPLv3, Copyright © 2008-2012 Enrico Tassi.
mbsync - synchronize IMAP4 and Maildir mailboxes