From b147e764e6278f34f338de58cb2a51f3c54f42cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 23 Nov 2020 22:41:06 +0100 Subject: Switch away from mutt to notmuch --- config/i3blocks/scripts/email | 23 ++++++++--- install | 28 ++++++-------- local/bin/allsync | 16 ++++++-- local/sbin/newmail-notify | 34 +++++++---------- mutt/color | 88 ------------------------------------------- mutt/mailcap | 12 ------ mutt/muttemail | 8 ---- mutt/muttrc | 50 ------------------------ private | 2 +- 9 files changed, 57 insertions(+), 204 deletions(-) delete mode 100644 mutt/color delete mode 100644 mutt/mailcap delete mode 100644 mutt/muttemail delete mode 100644 mutt/muttrc diff --git a/config/i3blocks/scripts/email b/config/i3blocks/scripts/email index 2d26280..d2213e0 100755 --- a/config/i3blocks/scripts/email +++ b/config/i3blocks/scripts/email @@ -1,6 +1,19 @@ -#!/bin/sh -# Note: we cut last character because output ends with new line -OUT="$(email-unread -s | tr "\n" " " | sed 's/ $//')" -echo "$OUT" -echo "$OUT" +#!/bin/bash +filter=("tag:unread" "and" "not" "tag:killed") + +part=() +all=0 +for mail in email gmail nic fel; do + counts="$(notmuch count -- "${filter[@]}" and "tag:$mail")" + [ "$counts" = "0" ] || \ + part+=("$mail:$counts") + ((all = all + counts)) +done + +echo "${part[@]}" +if [ "$all" = "0" ]; then + echo +else + echo "mails:$all" +fi echo "#ffff00" diff --git a/install b/install index aa0fe89..2910504 100755 --- a/install +++ b/install @@ -56,27 +56,21 @@ if ask "dev" "Development tools configuration"; then inst pylintrc ~/.pylintrc fi -if ask "cal" "Install calendar and contacts"; then - inst config/khal/config ~/.config/khal/config - inst config/khard/khard.conf ~/.config/khard/khard.conf - inst private/vdirsyncer/ ~/.vdirsyncer -fi - -if ask "mutt" "Install mutt configuration"; then - inst urlview ~/.urlview - inst lynxrc ~/.lynxrc - inst mutt/mailcap ~/.mutt/ - inst mutt/color ~/.mutt/ - inst private/mutt/ ~/.mutt - inst private/msmtprc ~/.msmtprc - mkdir -p ~/.cache/mutt # directory for temporaly html files -fi - if ask "sync" "Install synchronization"; then inst local/bin/allsync ~/.local/bin/allsync + + inst private/mbsyncrc ~/.mbsyncrc + inst private/notmuch-config ~/.notmuch-config + inst private/notmuch-tag-new ~/.notmuch-tag-new inst local/bin/email-unread ~/.local/bin/email-unread inst local/sbin/newmail-notify ~/.local/sbin/newmail-notify - inst private/mbsyncrc ~/.mbsyncrc + inst private/msmtprc ~/.msmtprc + inst private/astroid/config ~/.config/astroid/config + + inst private/vdirsyncer/ ~/.vdirsyncer + inst config/khal/config ~/.config/khal/config + inst config/khard/khard.conf ~/.config/khard/khard.conf + inst_sync fi diff --git a/local/bin/allsync b/local/bin/allsync index 3943ab4..51d6bef 100755 --- a/local/bin/allsync +++ b/local/bin/allsync @@ -5,14 +5,24 @@ sec() { echo -e '\e[1;34m==========' "$@" '==========\e[0m' } +ecode=0 fail() { echo -e '\e[1;31m---' "$@" '---' "($?)" '\e[0m' + ecode=1 } sec "Mail" -mbsync -a -~/.local/sbin/newmail-notify || fail "Mail synchronization reported failure" +mbsync -a || fail "Mail synchronization reported failure" +notmuch new +~/.local/sbin/newmail-notify +notmuch tag --batch --input="$HOME/.notmuch-tag-new" sec "Calendar and contacts" -vdirsyncer sync || "Calendar and contacts synchronization reported failure" +vdirsyncer sync || fail "Calendar and contacts synchronization reported failure" + +sec "Passwords" +pass git pull || fail "Passwords pull failed" +pass git push || fail "Passwords push failed" + +exit $ecode diff --git a/local/sbin/newmail-notify b/local/sbin/newmail-notify index 7c6b803..74aea66 100755 --- a/local/sbin/newmail-notify +++ b/local/sbin/newmail-notify @@ -1,23 +1,17 @@ -#!/bin/bash +#!/usr/bin/env python3 +import json +import subprocess -cd ~/.mail +subproc = subprocess.run(["notmuch", "show", "--format=json", "--", "tag:new"], check=True, capture_output=True) -if [ -f notify-notified ]; then - NOTIFIED=`cat notify-notified` - rm notify-notified -fi +mails = json.loads(subproc.stdout) +print(len(mails)) -for account in `ls`; do - if cd "$account"/INBOX/new; then - for m in `ls`; do - echo $m - echo $m >> ~/.mail/notify-notified - if echo "$NOTIFIED" | grep "$m" >/dev/null; then continue; fi - FROM=`grep -E "^From: " "$m" | sed 's/^From: //' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)'` - TO=`grep -E "^To: " "$m" | sed 's/^To: //' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)'` - SUBJECT=`grep -E "^Subject: " "$m" | sed 's/^Subject: //' | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)'` - notify-send "$TO: $FROM" "$SUBJECT" - done - fi - cd ~/.mail -done +for mail in mails: + headers = mail[0][0]["headers"] + if 'To' in headers: + summary = f"{headers['From']} -> {headers['To']}" + else: + summary = f"{headers['From']}" + body = headers["Subject"] + subprocess.run(["notify-send", summary, body], check=True) diff --git a/mutt/color b/mutt/color deleted file mode 100644 index b603f9e..0000000 --- a/mutt/color +++ /dev/null @@ -1,88 +0,0 @@ -## Theme kindly inspired from -## http://nongeekshandbook.blogspot.ie/2009/03/mutt-color-configuration.html - -## Colours for items in the index -color index brightcyan black ~N -color index brightred black ~O -color index brightyellow black ~F -color index black green ~T -color index brightred black ~D -mono index bold ~N -mono index bold ~F -mono index bold ~T -mono index bold ~D - -## Highlights inside the body of a message. - -## URLs -color body brightgreen black "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*" -color body brightgreen black "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+" -mono body bold "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*" -mono body bold "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+" - -## Email addresses. -color body brightgreen black "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+" - -## Header -color header green black "^from:" -color header green black "^to:" -color header green black "^cc:" -color header green black "^date:" -color header yellow black "^newsgroups:" -color header yellow black "^reply-to:" -color header brightcyan black "^subject:" -color header red black "^x-spam-rule:" -color header green black "^x-mailer:" -color header yellow black "^message-id:" -color header yellow black "^Organization:" -color header yellow black "^Organisation:" -color header yellow black "^User-Agent:" -color header yellow black "^message-id: .*pine" -color header yellow black "^X-Fnord:" -color header yellow black "^X-WebTV-Stationery:" - -color header red black "^x-spam-rule:" -color header green black "^x-mailer:" -color header yellow black "^message-id:" -color header yellow black "^Organization:" -color header yellow black "^Organisation:" -color header yellow black "^User-Agent:" -color header yellow black "^message-id: .*pine" -color header yellow black "^X-Fnord:" -color header yellow black "^X-WebTV-Stationery:" -color header yellow black "^X-Message-Flag:" -color header yellow black "^X-Spam-Status:" -color header yellow black "^X-SpamProbe:" -color header red black "^X-SpamProbe: SPAM" - -## Coloring quoted text - coloring the first 7 levels: -color quoted cyan black -color quoted1 yellow black -color quoted2 red black -color quoted3 green black -color quoted4 cyan black -color quoted5 yellow black -color quoted6 red black -color quoted7 green black - -## Default color definitions -#color hdrdefault white green -color signature brightmagenta black -color indicator black cyan -color attachment black green -color error red black -color message white black -color search brightwhite magenta -color status brightyellow blue -color tree brightblue black -color normal white black -color tilde green black -color bold brightyellow black -#color underline magenta black -color markers brightcyan black - -## Colour definitions when on a mono screen -mono bold bold -mono underline underline -mono indicator reverse - diff --git a/mutt/mailcap b/mutt/mailcap deleted file mode 100644 index 8d59638..0000000 --- a/mutt/mailcap +++ /dev/null @@ -1,12 +0,0 @@ -##this is used when (v)iewing a text/html attachment: -##allowing you to browse and "click" links -##order matters the first entry which passes the test is used -#text browser -text/html; w3m -v -F -T text/html %s; nametemplate=%s.html; needsterminal - -##auto_view will use the entry with the copiousoutput part: -text/html; lynx -stdin -dump -force_html -display_charset utf-8 ; copiousoutput - -image/*; feh --conversion-timeout 1 %s -application/pdf; mupdf %s - diff --git a/mutt/muttemail b/mutt/muttemail deleted file mode 100644 index 680ff9c..0000000 --- a/mutt/muttemail +++ /dev/null @@ -1,8 +0,0 @@ -# vim: set filetype=muttrc: -color status green default -set folder = "~/.mail/email" -set spoolfile = "+INBOX" -set copy = no -#set record = "+sent" -set postponed = "+drafts" -set from = "Karel Kočí " diff --git a/mutt/muttrc b/mutt/muttrc deleted file mode 100644 index 1fde214..0000000 --- a/mutt/muttrc +++ /dev/null @@ -1,50 +0,0 @@ -set editor="vim" -set my_name="Karel Kočí" -set edit_headers=yes -set askcc=yes - -hdr_order Date From To Cc #Sorting emails by the given criteria (from left to right) -set pager_index_lines= 5 -set sort=reverse-threads -set sort_aux=last-date-received -set mailcap_path = "~/.mutt/mailcap" -set sleep_time = 0 -set delete = yes -set include=yes -set ispell="aspell" -set mime_forward=yes -set mime_forward_rest=yes - -auto_view text/html -alternative_order text/enriched text/plain text/html -macro attach 'V' "cat >~/.cache/mutt/mail.html && ( surf ~/.cache/mutt/mail.html >/dev/null & )" - -set crypt_autosign = yes -set crypt_replyencrypt = yes -set crypt_use_gpgme = yes -set sendmail="/usr/bin/msmtp --read-envelope-from" - -set query_command= "khard email --parsable '%s'" -bind editor complete-query - -macro index S 's=archive' - -set sidebar_visible = yes -bind index,pager B sidebar-toggle-visible -# Ctrl-n, Ctrl-p to select next, previous folder. -# Ctrl-o to open selected folder. -bind index,pager \CP sidebar-prev -bind index,pager \CN sidebar-next -bind index,pager \CO sidebar-open - -bind pager j next-line -bind pager k previous-line -bind attach,index,pager \CD next-page -bind attach,index,pager \CU previous-page - -macro index ':source ~/.mutt/muttemailc~/.mail/email/INBOX' - -source ~/.mutt/color - -# As default open email -source ~/.mutt/muttemail diff --git a/private b/private index 3a6d6b9..27dbc70 160000 --- a/private +++ b/private @@ -1 +1 @@ -Subproject commit 3a6d6b902279ca0121756de0f2f28ac78844af5a +Subproject commit 27dbc7007a2613023a03a60410c1f42626b3252e -- cgit v1.2.3