From 6ad5f1cfda26c41fb1b7d06030c1918c06a3aad2 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 27 Dec 2021 19:06:29 -0500 Subject: switch from offlineimap to mbsync --- .gitignore | 1 + Makefile | 2 +- Makefile.hornet | 11 ++++++--- bin/hornet/update-mail | 11 --------- bin/mbsyncloop | 42 ++++++++++++++++++++++++++++++++++ config/offlineimap/config | 34 --------------------------- config/offlineimap/pass.py | 5 ---- mbsyncrc | 27 ++++++++++++++++++++++ mutt/choose-muttrc-type | 2 +- mutt/local | 16 +++++++++++++ mutt/offlineimap | 16 ------------- notmuch-config | 3 ++- services/available/mbsyncloop/log/run | 4 ++++ services/available/mbsyncloop/run | 3 +++ services/available/offlineimap/log/run | 4 ---- services/available/offlineimap/run | 3 --- 16 files changed, 105 insertions(+), 79 deletions(-) delete mode 100755 bin/hornet/update-mail create mode 100755 bin/mbsyncloop delete mode 100644 config/offlineimap/config delete mode 100644 config/offlineimap/pass.py create mode 100644 mbsyncrc create mode 100644 mutt/local delete mode 100644 mutt/offlineimap create mode 100755 services/available/mbsyncloop/log/run create mode 100755 services/available/mbsyncloop/run delete mode 100755 services/available/offlineimap/log/run delete mode 100755 services/available/offlineimap/run diff --git a/.gitignore b/.gitignore index b699bb4..2440f41 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ /hammerspoon/hs /local/share/fortune/*.dat /less +/mbsyncloop /mpdscribble/mpdscribble.conf /vim/spell/*.spl diff --git a/Makefile b/Makefile index 6dea15b..eaa3a72 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ INSTALL := \ .mutt/imap \ .mutt/mailcap \ .mutt/muttrc \ - .mutt/offlineimap \ + .mutt/local \ .nethackrc \ .profile \ .replyrc \ diff --git a/Makefile.hornet b/Makefile.hornet index 49917bd..b79144d 100644 --- a/Makefile.hornet +++ b/Makefile.hornet @@ -7,9 +7,9 @@ INSTALL := \ .config/i3/terminal-workspace.json \ .config/i3status/config \ .config/msmtp/config \ - .config/offlineimap/config \ - .config/offlineimap/pass.py \ .config/perspektiv/config.toml \ + .mbsyncrc \ + .mbsyncloop \ .mpdscribble \ .notmuch-config \ .ssh/authorized_keys \ @@ -25,6 +25,7 @@ EMPTYDIRS := \ $(patsubst services/available/%,.log/%,$(wildcard services/available/*)) \ Maildir \ .cache/mpd \ + .cache/notmuch \ .config/mpd/playlists INSTALL_CUSTOM := \ @@ -34,7 +35,8 @@ INSTALL_CUSTOM := \ BUILD := \ config/alacritty/alacritty.yml \ - mpdscribble/mpdscribble.conf + mpdscribble/mpdscribble.conf \ + mbsyncloop install :: @chmod 600 config/msmtp/config @@ -66,6 +68,9 @@ config/darksky : config/darksky/api : config/darksky rbw get darksky.net api > $@ +mbsyncloop: mbsyncrc + @sed 's/^PassCmd.*/PassCmd "head -n1 \/run\/user\/1000\/mbsyncloop"/' mbsyncrc > mbsyncloop + mpdscribble/mpdscribble.conf : mpdscribble/mpdscribble.conf.tmpl pass="$$(rbw get last.fm doyster)" &&\ perl -E'while () { if (/^password =/) { say "password = $$ARGV[0]" } else { print } }' "$$pass" < $< > $@ diff --git a/bin/hornet/update-mail b/bin/hornet/update-mail deleted file mode 100755 index 8149a8d..0000000 --- a/bin/hornet/update-mail +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -set -eu -set -o pipefail - -stat=$(svstat "$HOME/.services/enabled/offlineimap") -if echo "$stat" | grep -q "offlineimap: down"; then - echo "no offlineimap process running" >&2 - exit 1 -fi -pid=$(echo "$stat" | sed 's/.*offlineimap: up (pid \([[:digit:]]\+\)).*/\1/') -kill -USR1 "$pid" diff --git a/bin/mbsyncloop b/bin/mbsyncloop new file mode 100755 index 0000000..3136c51 --- /dev/null +++ b/bin/mbsyncloop @@ -0,0 +1,42 @@ +#!/usr/bin/env perl +use 5.016; +use strict; +use warnings; + +use POSIX 'mkfifo'; + +my ($pw_pipe, $pid); + +sub cleanup { + unlink($pw_pipe) if $pw_pipe; + kill KILL => $pid if $pid; +} + +$SIG{INT} = $SIG{TERM} = sub { cleanup; exit }; +END { cleanup } + +$pw_pipe = "/run/user/$>/mbsyncloop"; +mkfifo($pw_pipe, 0700) or die "couldn't create $pw_pipe"; + +my $pw = `rbw get mail.tozt.net doy\@tozt.net`; + +$pid = fork; +die unless defined $pid; +if (!$pid) { + $SIG{PIPE} = sub {}; + while (1) { + open my $fh, '>', $pw_pipe or die "couldn't open $pw_pipe"; + $fh->print("$pw\n"); + close $fh; + } + exit; +} + +my $i = 0; +while (1) { + my $channel = $i % 15 ? "priority" : "all"; + system("mbsync -c ~/.mbsyncloop $channel") and last; + system("notmuch new") and last; + sleep 60; + $i++; +} diff --git a/config/offlineimap/config b/config/offlineimap/config deleted file mode 100644 index fd9110a..0000000 --- a/config/offlineimap/config +++ /dev/null @@ -1,34 +0,0 @@ -[general] -accounts = main -maxsyncaccounts = 3 -status_backend = sqlite -pythonfile = ~/.config/offlineimap/pass.py -ui = basic -socktimeout = 120 - -[Account main] -localrepository = main-local -remoterepository = main-remote -autorefresh = 5 -quick = 10 -postsynchook = notmuch new - -[Repository main-local] -type = Maildir -localfolders = ~/Maildir - -[Repository main-remote] -type = IMAP -ssl = yes -sslcacertfile = /etc/ssl/certs/ca-certificates.crt -remotehost = mail.tozt.net -remoteuser = doy@tozt.net -remotepasseval = get_password("mail.tozt.net", "doy@tozt.net") -maxconnections = 5 -keepalive = 60 -holdconnectionopen = yes -idlefolders = ['INBOX'] -folderfilter = lambda foldername: not re.search('^old(\.|$)', foldername) -subscribedonly = no - -# vim:ft=dosini: diff --git a/config/offlineimap/pass.py b/config/offlineimap/pass.py deleted file mode 100644 index 6a7fba3..0000000 --- a/config/offlineimap/pass.py +++ /dev/null @@ -1,5 +0,0 @@ -from subprocess import Popen, PIPE - -def get_password(name, user): - (out, err) = Popen(["rbw", "get", name, user], stdout=PIPE).communicate() - return out.strip() diff --git a/mbsyncrc b/mbsyncrc new file mode 100644 index 0000000..40080fb --- /dev/null +++ b/mbsyncrc @@ -0,0 +1,27 @@ +Expunge None +Create Both + +MaildirStore local +Path ~/Maildir/ +Inbox ~/Maildir/INBOX +Trash Trash +Flatten . + +IMAPStore mail +Host mail.tozt.net +User doy@tozt.net +PassCmd "rbw get mail.tozt.net doy@tozt.net" +SSLType IMAPS +SSLVersions TLSv1.2 TLSv1.3 + +Channel all +Far :mail: +Near :local: +Sync PullNew Push +Patterns * !.notmuch + +Channel priority +Far :mail: +Near :local: +Sync PullNew Push +Patterns INBOX personal diff --git a/mutt/choose-muttrc-type b/mutt/choose-muttrc-type index 21db151..363a64c 100755 --- a/mutt/choose-muttrc-type +++ b/mutt/choose-muttrc-type @@ -4,7 +4,7 @@ set -o pipefail case "$(hostname)" in hornet) - echo 'source ~/.mutt/offlineimap' + echo 'source ~/.mutt/local' ;; *) echo 'source ~/.mutt/imap' diff --git a/mutt/local b/mutt/local new file mode 100644 index 0000000..0d6205f --- /dev/null +++ b/mutt/local @@ -0,0 +1,16 @@ +set mbox_type=Maildir +set folder="~/Maildir" +set spoolfile="~/Maildir/INBOX" +mailboxes `\ + for folder in ~/Maildir/*; do\ + basename=$(basename "$folder");\ + if [ "x${basename:0:4}" != "xold."\ + -a "x$basename" != "xspam"\ + -a "x$basename" != "xnotmuch" ]; then\ + echo -n "\"=$basename\" ";\ + fi\ + done` +macro index R "unset wait_keymbsync all && notmuch newset wait_key" "fetch mail with mbsync" +set timeout=3 + +# vim: ft=neomuttrc diff --git a/mutt/offlineimap b/mutt/offlineimap deleted file mode 100644 index e22fe53..0000000 --- a/mutt/offlineimap +++ /dev/null @@ -1,16 +0,0 @@ -set mbox_type=Maildir -set folder="~/Maildir" -set spoolfile="~/Maildir/INBOX" -mailboxes `\ - for folder in ~/Maildir/*; do\ - basename=$(basename "$folder");\ - if [ "x${basename:0:4}" != "xold."\ - -a "x$basename" != "xspam"\ - -a "x$basename" != "xnotmuch" ]; then\ - echo -n "\"=$basename\" ";\ - fi\ - done` -macro index R "unset wait_keyupdate-mailset wait_key" "fetch mail with offlineimap" -set timeout=3 - -# vim: ft=neomuttrc diff --git a/notmuch-config b/notmuch-config index 9b4117a..675036c 100644 --- a/notmuch-config +++ b/notmuch-config @@ -1,5 +1,6 @@ [database] -path=/home/doy/Maildir +path=/home/doy/.cache/notmuch +mail_root=/home/doy/Maildir [user] name=Jesse Luehrs diff --git a/services/available/mbsyncloop/log/run b/services/available/mbsyncloop/log/run new file mode 100755 index 0000000..5930eda --- /dev/null +++ b/services/available/mbsyncloop/log/run @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu + +exec multilog t s16777215 "$HOME/.log/mbsyncloop" diff --git a/services/available/mbsyncloop/run b/services/available/mbsyncloop/run new file mode 100755 index 0000000..ac7e636 --- /dev/null +++ b/services/available/mbsyncloop/run @@ -0,0 +1,3 @@ +#!/bin/sh + +exec mbsyncloop 2>&1 diff --git a/services/available/offlineimap/log/run b/services/available/offlineimap/log/run deleted file mode 100755 index 9883599..0000000 --- a/services/available/offlineimap/log/run +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -eu - -exec multilog t s16777215 "$HOME/.log/offlineimap" diff --git a/services/available/offlineimap/run b/services/available/offlineimap/run deleted file mode 100755 index 5589a60..0000000 --- a/services/available/offlineimap/run +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exec offlineimap 2>&1 -- cgit v1.2.3-54-g00ecf