#!/usr/bin/env python3 import glob import json import sqlite3 import os profile_dirs = glob.glob( os.path.expanduser("~/.var/app/org.mozilla.Thunderbird/.thunderbird/*.default-esr") ) or glob.glob( os.path.expanduser("~/.thunderbird/*.default-esr") ) if not profile_dirs: print(json.dumps({"text": "", "tooltip": "No Thunderbird profile found"})) exit() db_path = os.path.join(profile_dirs[0], "global-messages-db.sqlite") if not os.path.exists(db_path): print(json.dumps({"text": "", "tooltip": "No message database"})) exit() try: conn = sqlite3.connect(f"file:{db_path}?mode=ro&nolock=1", uri=True) cursor = conn.cursor() cursor.execute( "SELECT COUNT(*) FROM messages WHERE jsonAttributes LIKE '%\"read\":false%' OR jsonAttributes LIKE '%\"read\": false%'" ) count = cursor.fetchone()[0] conn.close() except Exception: # fallback: try folderStatus try: conn = sqlite3.connect(f"file:{db_path}?mode=ro&nolock=1", uri=True) cursor = conn.cursor() cursor.execute("SELECT SUM(numNewMessages) FROM folderlocations WHERE numNewMessages > 0") row = cursor.fetchone() count = row[0] if row and row[0] else 0 conn.close() except Exception: count = 0 if count > 0: print(json.dumps({"text": f"󰇮 {count}", "tooltip": f"{count} unread emails", "class": "unread"})) else: print(json.dumps({"text": "󰇮", "tooltip": "No unread emails"}))