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 --- local/sbin/newmail-notify | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'local/sbin/newmail-notify') 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) -- cgit v1.2.3