diff options
Diffstat (limited to 'local')
-rwxr-xr-x | local/bin/allsync | 16 | ||||
-rwxr-xr-x | local/sbin/newmail-notify | 34 |
2 files changed, 27 insertions, 23 deletions
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) |