aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dot_config/waybar/executable_tb-unread.sh
diff options
context:
space:
mode:
authorLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2026-05-13 13:43:27 +0100
committerLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2026-05-13 13:43:27 +0100
commitb5a8319d1aaa6d06655005e22d461ab41afcbe78 (patch)
tree5975ebd1bcafa9b07b705d9cb43528b70e08904a /dot_config/waybar/executable_tb-unread.sh
parent0d820cf864a04a4e81c47cc85d577bf3756e0561 (diff)
downloaddotfiles-b5a8319d1aaa6d06655005e22d461ab41afcbe78.tar.gz
dotfiles-b5a8319d1aaa6d06655005e22d461ab41afcbe78.tar.bz2
dotfiles-b5a8319d1aaa6d06655005e22d461ab41afcbe78.zip
feat(waybar): add Thunderbird inbox-unread module
Polls the protonmail-bridge IMAP socket every 60s with STATUS INBOX (UNSEEN), displays the count next to the tray, and clicking the badge runs tb-toggle.sh to bring TB out of the scratchpad (or launch it). Setup: store bridge credentials in pass at email/protonmail-bridge/{user, pass}. The bridge surfaces them via 'protonmail-bridge --cli' -> 'info'. With no entries (or with the bridge unreachable) the module shows 'MAIL ?' in red and is otherwise inert.
Diffstat (limited to 'dot_config/waybar/executable_tb-unread.sh')
-rw-r--r--dot_config/waybar/executable_tb-unread.sh51
1 files changed, 51 insertions, 0 deletions
diff --git a/dot_config/waybar/executable_tb-unread.sh b/dot_config/waybar/executable_tb-unread.sh
new file mode 100644
index 0000000..ebf2fd4
--- /dev/null
+++ b/dot_config/waybar/executable_tb-unread.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+# Emit waybar JSON with the count of unread messages in the protonmail-bridge
+# IMAP Inbox. Requires bridge credentials in `pass` at the paths below; the
+# bridge prints them via `protonmail-bridge --cli` → `info`.
+#
+# The on-click handler in waybar config drives tb-toggle.sh, so a click on
+# the badge brings Thunderbird out of the scratchpad (or launches it if it
+# isn't running yet).
+set -eu
+
+PASS_USER=email/protonmail-bridge/user
+PASS_PW=email/protonmail-bridge/pass
+HOST=127.0.0.1
+PORT=1143
+
+emit() { printf '%s\n' "$1"; exit 0; }
+
+# Cheap reachability probe — avoids a 30s python TLS timeout when the bridge
+# is down (e.g. before it has finished unlocking on a fresh login).
+ncat -z -w 1 "$HOST" "$PORT" 2>/dev/null || \
+ emit '{"text":"MAIL ?","tooltip":"bridge unreachable","class":"error","alt":"error"}'
+
+user=$(pass show "$PASS_USER" 2>/dev/null) || \
+ emit '{"text":"MAIL ?","tooltip":"missing pass entry: '"$PASS_USER"'","class":"error","alt":"error"}'
+pw=$(pass show "$PASS_PW" 2>/dev/null) || \
+ emit '{"text":"MAIL ?","tooltip":"missing pass entry: '"$PASS_PW"'","class":"error","alt":"error"}'
+
+n=$(PROTONMAIL_BRIDGE_USER="$user" PROTONMAIL_BRIDGE_PASS="$pw" \
+ python3 - "$HOST" "$PORT" <<'PY' 2>/dev/null || true
+import imaplib, os, ssl, sys
+host, port = sys.argv[1], int(sys.argv[2])
+ctx = ssl.create_default_context()
+ctx.check_hostname = False
+ctx.verify_mode = ssl.CERT_NONE
+try:
+ m = imaplib.IMAP4(host, port)
+ m.starttls(ssl_context=ctx)
+ m.login(os.environ["PROTONMAIL_BRIDGE_USER"], os.environ["PROTONMAIL_BRIDGE_PASS"])
+ typ, data = m.status("INBOX", "(UNSEEN)")
+ m.logout()
+ print(int(data[0].split(b"UNSEEN ")[1].rstrip(b")")))
+except Exception:
+ pass
+PY
+)
+
+case "$n" in
+ '') emit '{"text":"MAIL ?","tooltip":"IMAP query failed","class":"error","alt":"error"}' ;;
+ 0) emit '{"text":"MAIL 0","tooltip":"Inbox: no unread","class":"empty","alt":"empty"}' ;;
+ *) emit "$(printf '{"text":"MAIL %s","tooltip":"Inbox: %s unread","class":"unread","alt":"unread"}' "$n" "$n")" ;;
+esac