~kiril/dotfiles

d0c0f47e040f362c4c85c7042a64a34d13a020f8 — Kiril Vladimiroff 1 year, 7 months ago 04f3644
systemd: replace offlineimap with mbsync
4 files changed, 6 insertions(+), 72 deletions(-)

D bin/offlineimap.py
D mail/offlineimaprc
R systemd/user/{offlineimap.service => mbsync.service}
R systemd/user/{offlineimap.timer => mbsync.timer}
D bin/offlineimap.py => bin/offlineimap.py +0 -38
@@ 1,38 0,0 @@
#!/usr/bin/env python
import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))  # noqa

import kdewallet5

PERSONAL_FOLDERS = {
    'archive': '[Gmail]/All Mail',
    'drafts': '[Gmail]/Drafts',
    'flagged': '[Gmail]/Starred',
    'sent': '[Gmail]/Sent Mail',
    'trash': '[Gmail]/Trash',
}
REVERSE_PERSONAL_FOLDERS = {v: k for k, v in PERSONAL_FOLDERS.items()}
HIDE_FOLDERS = {'[Gmail]/Trash', '[Gmail]/Important', '[Gmail]/Spam'}


def get_password(wallet, folder_name, key):
    with kdewallet5.Wallet(wallet, "offlineimap") as wallet:
        return wallet.read_password(folder_name, key)


def personal_local_nametrans(folder_name):
    return PERSONAL_FOLDERS.get(folder_name, folder_name)


def personal_remote_nametrans(folder_name):
    return REVERSE_PERSONAL_FOLDERS.get(folder_name, folder_name)


def folder_filter(folder_name):
    return folder_name not in HIDE_FOLDERS


if __name__ == '__main__':
    print(get_password(sys.argv[1], sys.argv[2], sys.argv[3]))

D mail/offlineimaprc => mail/offlineimaprc +0 -27
@@ 1,27 0,0 @@
[general]
ui = ttyui
accounts = Personal
pythonfile=$DOTFILES/bin/offlineimap.py
fsync = False

[Account Personal]
localrepository = Personal-Local
remoterepository = Personal-Remote

[Repository Personal-Local]
type = Maildir
localfolders = ~/mail/personal
nametrans = personal_local_nametrans


[Repository Personal-Remote]
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
maxconnections = 1
type = Gmail
remoteuser = kiril@vladimiroff.org
remotepasseval = get_password(wallet='kdewallet',
                              folder_name='Passwords',
                              key='gmail-personal')
realdelete = no
nametrans = personal_remote_nametrans
folderfilter = folder_filter

R systemd/user/offlineimap.service => systemd/user/mbsync.service +3 -4
@@ 1,13 1,12 @@
[Unit]
Description=Offlineimap Service
Description=mbsync Service
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
Environment=
TimeoutSec=120
ExecStart=/usr/bin/offlineimap -o
TimeoutSec=360
ExecStart=/usr/bin/mbsync -a

[Install]
WantedBy=mail.target

R systemd/user/offlineimap.timer => systemd/user/mbsync.timer +3 -3
@@ 1,10 1,10 @@
[Unit]
Description=Offlineimap Query Timer
Description=mbsync Query Timer

[Timer]
OnUnitInactiveSec=1min
OnUnitInactiveSec=5min
OnBootSec=1min
Unit=offlineimap.service
Unit=mbsync.service

[Install]
WantedBy=mail.target