Fix (automatic) syncing of email

- Load the necessary environment variables from ‘gnome-keyring-daemon’ when
  loading fish.
- Don’t sync the Archive directory from ryuslash.org, it’s too big and mbsync
  seems to get really confused about it.
- Disable old email accounts from syncing with mbsync.
- Fix the ‘get-mail-password’ and ‘set-mail-password’ scripts.
  - Use ‘secretstorage’ instead of ‘keyring’, this appears to be newer and
    easier to use.
This commit is contained in:
Tom Willemse 2019-08-14 23:45:13 -07:00
parent 587bcae5e6
commit 946b7425de
4 changed files with 76 additions and 74 deletions

View file

@ -9,3 +9,7 @@ set -x EDITOR emacsclient
set -x DOTNET_CLI_TELEMETRY_OPTOUT true set -x DOTNET_CLI_TELEMETRY_OPTOUT true
kitty + complete setup fish | source kitty + complete setup fish | source
if test -n "$DESKTOP_SESSION"
set (gnome-keyring-daemon --start | string split "=")
end

View file

@ -18,7 +18,7 @@ Channel ryuslash
Master :ryuslash-remote: Master :ryuslash-remote:
Slave :ryuslash-local: Slave :ryuslash-local:
# Don't synchronize lda-dupes, it causes trouble. # Don't synchronize lda-dupes, it causes trouble.
Patterns * !dovecot/lda-dupes Patterns * !Archive !dovecot/lda-dupes
Create Both Create Both
SyncState * SyncState *
@ -62,62 +62,62 @@ Group gmail
Channel gmail-inbox Channel gmail-inbox
Channel gmail-sent Channel gmail-sent
## Picturefix: # ## Picturefix:
IMAPAccount picturefix # IMAPAccount picturefix
Host imap.gmail.com # Host imap.gmail.com
User tom@picturefix.nl # User tom@picturefix.nl
PassCmd "~/usr/bin/get-mail-password picturefix" # PassCmd "~/usr/bin/get-mail-password picturefix"
SSLType IMAPS # SSLType IMAPS
CertificateFile /etc/ssl/certs/ca-certificates.crt # CertificateFile /etc/ssl/certs/ca-certificates.crt
IMAPStore picturefix-remote # IMAPStore picturefix-remote
Account picturefix # Account picturefix
MaildirStore picturefix-local # MaildirStore picturefix-local
Path ~/documents/mail/picturefix # Path ~/documents/mail/picturefix
Inbox ~/documents/mail/picturefix/inbox # Inbox ~/documents/mail/picturefix/inbox
SubFolders Legacy # SubFolders Legacy
# Synchronize only the gmail INBOX mailbox. # # Synchronize only the gmail INBOX mailbox.
Channel picturefix-inbox # Channel picturefix-inbox
Master :picturefix-remote: # Master :picturefix-remote:
Slave :picturefix-local: # Slave :picturefix-local:
Patterns INBOX # Patterns INBOX
Create Both # Create Both
SyncState * # SyncState *
# Synchronize only the sent mailbox. # # Synchronize only the sent mailbox.
Channel picturefix-sent # Channel picturefix-sent
Master :picturefix-remote:"[Gmail]/Verzonden berichten" # Master :picturefix-remote:"[Gmail]/Verzonden berichten"
Slave :picturefix-local:sent # Slave :picturefix-local:sent
Create Both # Create Both
SyncState * # SyncState *
# Group the picturefix channels together so that synching with the # # Group the picturefix channels together so that synching with the
# command-line is easier. # # command-line is easier.
Group picturefix # Group picturefix
Channel picturefix-inbox # Channel picturefix-inbox
Channel picturefix-sent # Channel picturefix-sent
## Ninthfloor: # ## Ninthfloor:
IMAPAccount ninthfloor # IMAPAccount ninthfloor
Host mail.ninthfloor.org # Host mail.ninthfloor.org
User ryuslash # User ryuslash
PassCmd "~/usr/bin/get-mail-password ninthfloor" # PassCmd "~/usr/bin/get-mail-password ninthfloor"
SSLType STARTTLS # SSLType STARTTLS
CertificateFile /etc/ssl/certs/ca-certificates.crt # CertificateFile /etc/ssl/certs/ca-certificates.crt
IMAPStore ninthfloor-remote # IMAPStore ninthfloor-remote
Account ninthfloor # Account ninthfloor
MaildirStore ninthfloor-local # MaildirStore ninthfloor-local
Path ~/documents/mail/ninthfloor/ # Path ~/documents/mail/ninthfloor/
Inbox ~/documents/mail/ninthfloor/inbox # Inbox ~/documents/mail/ninthfloor/inbox
SubFolders Legacy # SubFolders Legacy
Channel ninthfloor # Channel ninthfloor
Master :ninthfloor-remote: # Master :ninthfloor-remote:
Slave :ninthfloor-local: # Slave :ninthfloor-local:
Patterns * # Patterns *
Create Both # Create Both
SyncState * # SyncState *

View file

@ -1,15 +1,12 @@
#!/usr/bin/python3 #!/usr/bin/python3
import gi
gi.require_version('GnomeKeyring', '1.0')
import logging
logger = logging.getLogger('keyring')
logger.addHandler(logging.StreamHandler())
import keyring
import sys import sys
import secretstorage
print(keyring.get_password('offlineimap', sys.argv[1])) connection = secretstorage.dbus_init()
collection = secretstorage.get_collection_by_alias(connection, "login")
for foo in collection.search_items(
{"application": "mbsync", "account": sys.argv[1]}
):
print(foo.get_secret().decode())

View file

@ -1,16 +1,17 @@
#!/usr/bin/python3 #!/usr/bin/python3
import gi
gi.require_version('GnomeKeyring', '1.0')
import logging
logger = logging.getLogger('keyring')
logger.addHandler(logging.StreamHandler())
import keyring
import sys import sys
import getpass from getpass import getpass
import secretstorage
keyring.set_password('offlineimap', sys.argv[1], getpass.getpass()) connection = secretstorage.dbus_init()
collection = secretstorage.get_collection_by_alias(connection, "login")
attributes = {"application": "mbsync", "account": sys.argv[1]}
collection.create_item(
"Password for '{}' on '{}'".format(
attributes["account"], attributes["application"]
),
attributes,
getpass().encode(),
)