This setup has worked well for me since I started using offlineimap and gmail a long time ago.
** Offlineimap
Sync these with offlineimap:
folderfilter = lambda foldername: foldername in [
'INBOX',
'[Gmail]/All Mail',
'[Gmail]/Trash',
'[Gmail]/Sent Mail',
'[Gmail]/Trash',
# add any other labels you use
]
** mu settings
Put a .noindex in Sent Mail, Trash, and Drafts to avoid duplicates.
** mu4e settings
In mu4e add a default bcc header for yourself, so you have a copy. Note that gmail automatically removes duplicates in case you send email through their IMAP server. The BCC allows you to use a different SMTP server and you will still have everything in your gmail account.
(add-hook 'mu4e-compose-mode-hook
(defun my-add-bcc ()
"Add a Bcc: header."
(save-excursion
(message-add-header "Bcc:
m...@example.com\n"))
(setq
mu4e-maildir "~/.mail" ;; top-level Maildir
mu4e-sent-folder "/[Gmail].Sent Mail"
mu4e-drafts-folder "/[Gmail].Drafts" ;; unfinished messages
mu4e-trash-folder "/[Gmail].Trash") ;; trashed messages
Don't save sent messages. Gmail takes care of that.
(setq mu4e-sent-messages-behavior 'delete)
** Gmail settings
Put a rule in gmail, so your BCC email doesn't show up as new:
From:
m...@example.com do: skip inbox, mark as read
** Done.
You inbox will behave like any other inbox. New mail and other stuff you haven't deleted in there, will be in there. Just delete mails in your inbox, because they will be in All Mail anyways. If you want to really delete a message you need to move it to the trash with (mu4e-headers-mark-for-trash) and sync with offlineimap. Gmail will then automatically delete messages in the Trash folder beyond a certain age.
The only downside is that, when you trash messages, you need to sync them to gmail. But that's acceptable as long as you have a reasonable uplink and do it in the background.