From 921a445348f33aa07198d561e7880358be4ed289 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 14 Apr 2017 14:11:33 -0400 Subject: [PATCH] shell/mu: offlineimap => mbsync + refactor --- shell/mu/.mbsyncrc | 131 ++++++++++++++++++++++++++++++++++++++ shell/mu/.offlineimaprc | 16 +++-- shell/mu/lib.py | 32 ++++++++++ shell/mu/offlineimaprc.py | 24 ------- 4 files changed, 173 insertions(+), 30 deletions(-) create mode 100644 shell/mu/.mbsyncrc create mode 100755 shell/mu/lib.py delete mode 100644 shell/mu/offlineimaprc.py diff --git a/shell/mu/.mbsyncrc b/shell/mu/.mbsyncrc new file mode 100644 index 00000000..b4449fc0 --- /dev/null +++ b/shell/mu/.mbsyncrc @@ -0,0 +1,131 @@ +######################################## +# gmail.com +######################################## +IMAPAccount gmail +Host imap.gmail.com +User hlissner@gmail.com +PassCmd "pass email/gmail.com | head -n1" +Port 993 +AuthMechs LOGIN +SSLType IMAPS +CertificateFile /etc/ssl/certs/ca-certificates.crt +# CertificateFile /usr/local/etc/openssl/cert.pem # MacOS + +## +# Remote +IMAPStore gmail-remote +Account gmail + +# Local +MaildirStore gmail-local +Path ~/.mail/gmail.com/ +Inbox ~/.mail/gmail.com/Inbox + +## Connections +Channel gmail-all +Master :gmail-remote:"[Gmail]/All Mail" +Slave :gmail-local:"All Mail" +Create Both +Expunge Both +SyncState * + +Channel gmail-inbox +Master :gmail-remote:"INBOX" +Slave :gmail-local:"Inbox" +Create Both +Expunge Both +SyncState * + +Channel gmail-drafts +Master :gmail-remote:"[Gmail]/Drafts" +Slave :gmail-local:"Drafts" +Create Both +Expunge Both +SyncState * + +Channel gmail-sent +Master :gmail-remote:"[Gmail]/Sent Mail" +Slave :gmail-local:"Sent Mail" +Create Both +Expunge Both +SyncState * + +Channel gmail-trash +Master :gmail-remote:"[Gmail]/Trash" +Slave :gmail-local:"Trash" +Create Both +Expunge Both +SyncState * + +## Groups +Group gmail +Channel gmail-all +Channel gmail-inbox +Channel gmail-drafts +Channel gmail-sent +Channel gmail-trash + + +# ######################################## +# # lissner.net +# ######################################## +IMAPAccount lissner +Host imap.gmail.com +User henrik@lissner.net +PassCmd "pass email/lissner.net | head -n1" +Port 993 +AuthMechs LOGIN +SSLType IMAPS +CertificateFile /etc/ssl/certs/ca-certificates.crt +# CertificateFile /usr/local/etc/openssl/cert.pem # MacOS + +IMAPStore lissner-remote +Account lissner + +MaildirStore lissner-local +Path ~/.mail/lissner.net/ +Inbox ~/.mail/lissner.net/Inbox + +## Connections +Channel lissner-all +Master :lissner-remote:"[Gmail]/All Mail" +Slave :lissner-local:"All Mail" +Create Both +Expunge Both +SyncState * + +Channel lissner-inbox +Master :lissner-remote:"INBOX" +Slave :lissner-local:"Inbox" +Create Both +Expunge Both +SyncState * + +Channel lissner-drafts +Master :lissner-remote:"[Gmail]/Drafts" +Slave :lissner-local:"Drafts" +Create Both +Expunge Both +SyncState * + +Channel lissner-sent +Master :lissner-remote:"[Gmail]/Sent Mail" +Slave :lissner-local:"Sent Mail" +Create Both +Expunge Both +SyncState * + +Channel lissner-trash +Master :lissner-remote:"[Gmail]/Trash" +Slave :lissner-local:"Trash" +Create Both +Expunge Both +SyncState * + +# ## Groups +Group lissner +Channel lissner-all +Channel lissner-inbox +Channel lissner-drafts +Channel lissner-sent +Channel lissner-trash diff --git a/shell/mu/.offlineimaprc b/shell/mu/.offlineimaprc index 4a68e34b..23c27cd0 100644 --- a/shell/mu/.offlineimaprc +++ b/shell/mu/.offlineimaprc @@ -1,13 +1,16 @@ [general] accounts = Lissner,Gmail -pythonfile = ~/.dotfiles/shell/mu/offlineimaprc.py +maxsynaccounts = 2 +pythonfile = ~/.dotfiles/shell/mu/lib.py +fsync = False + +[DEFAULT] + [Account Gmail] localrepository = LocalGmail remoterepository = RepositoryGmail -autorefresh = 5 -quick = 10 -postsynchook = mu index --maildir ~/.mail/gmail.com +postsynchook = mu index --maildir ~/.mail status_backend = sqlite [Repository LocalGmail] @@ -20,6 +23,7 @@ type = Gmail remoteusereval = get_pass("gmail.com")["user"] remotepasseval = get_pass("gmail.com")["password"] folderfilter = folder_filter +realdelete=no ssl = true sslcacertfile = /usr/local/etc/openssl/cert.pem # This will only work for macOS sslcacertfile = /etc/ssl/certs/ca-certificates.crt @@ -29,8 +33,7 @@ nametrans = nametrans_reverse [Account Lissner] localrepository = LocalLissner remoterepository = RepositoryLissner -quick = 10 -postsynchook = mu index --maildir ~/.mail/lissner.net +postsynchook = mu index --maildir ~/.mail status_backend = sqlite [Repository LocalLissner] @@ -43,6 +46,7 @@ type = Gmail remoteusereval = get_pass("lissner.net")["user"] remotepasseval = get_pass("lissner.net")["password"] folderfilter = folder_filter +realdelete=no ssl = true sslcacertfile = /usr/local/etc/openssl/cert.pem # This will only work for macOS sslcacertfile = /etc/ssl/certs/ca-certificates.crt diff --git a/shell/mu/lib.py b/shell/mu/lib.py new file mode 100755 index 00000000..db8fcffb --- /dev/null +++ b/shell/mu/lib.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +from subprocess import check_output +from re import sub +import sys + +def get_pass(account): + data = check_output("/usr/bin/pass email/" + account, shell=True).splitlines() + password = data[0] + tmp = [x for x in data if x.startswith('address:')] + user = "" + if len(tmp) > 0: + user = tmp[0].split(":", 1)[1] + + return {"password": password, "user": user} + +def folder_filter(name): + return not (name in ['[Gmail]/Spam', + '[Gmail]/Important', + '[Gmail]/Starred', + '[Gmail]/All Mail'] or + name.startswith('[Airmail]')) + +def nametrans(name): + return sub('^INBOX/(Starred|Sent Mail|Drafts|Trash|All Mail|Spam)$', '[Gmail]/\\1', name) + +def nametrans_reverse(name): + return sub('^(\[Gmail\])', 'INBOX.', name) + + +if __name__ == '__main__': + print(get_pass(sys.argv[1].strip())['password']) diff --git a/shell/mu/offlineimaprc.py b/shell/mu/offlineimaprc.py deleted file mode 100644 index 000316ab..00000000 --- a/shell/mu/offlineimaprc.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python - -from subprocess import check_output -from re import sub - -def get_pass(account): - data = check_output("pass email/" + account, shell=True).splitlines() - password = data[0] - tmp = [x for x in data if x.startswith('address:')] - user = "" - if len(tmp) > 0: - user = tmp[0].split(":", 1)[1] - - return {"password": password, "user": user} - -def folder_filter(name): - return not (name in ['[Gmail]/Spam', '[Gmail]/Important'] or - name.startswith('[Airmail]')) - -def nametrans(name): - return sub('^(Starred|Sent Mail|Drafts|Trash|All Mail|Spam)$', '[Gmail]/\\1', name) - -def nametrans_reverse(name): - return sub('^(\[Gmail\]/)', '', name)