Created
April 24, 2022 11:05
-
-
Save thingsiplay/e03a84ebc6e01c9b475cd0277fb81def to your computer and use it in GitHub Desktop.
Count unread mails in Thunderbird and write to stdout.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
# Count unread mails in Thunderbird and write to stdout. | |
# Usage: | |
# checkmails.sh | |
# Path to your Thunderbird profile. | |
profile="$HOME/.thunderbird/aabbcc007.default" | |
# Regex to find the unread message lines. | |
# Adding "9F" in front of regex works for ImapMail, but not for pop3. in Mail. | |
regex='\(\^A2=([0-9]+)' | |
count_unreadmails() { | |
count=0 | |
result=$(grep -Eo "$regex" "$1" | tail -1) | |
if [[ $result =~ $regex ]] | |
then | |
count="${BASH_REMATCH[1]}" | |
unreadmail_count=$(($unreadmail_count + $count)) | |
fi | |
return $count | |
} | |
unreadmail_count=0 | |
# Either use smart mailboxes or the Mail and ImapMail inboxes directly. Smart | |
# mailboxes are those specifically selected and enabled from within | |
# Thunderbird's inbox folder (right mouse click on inbox). Therefore don't | |
# enable SMART MAILBOXES and those in MAILBOXES at the same time. | |
# SMART MAILBOXES | |
# Includes all grouped mail specified in the right mouse menu on inbox folder. | |
for inbox in "$profile/Mail/smart mailboxes/Inbox.msf" | |
do | |
count_unreadmails "$inbox" | |
done | |
# MAILBOXES | |
# for inbox in $profile/ImapMail/*/INBOX.msf | |
# do | |
# count_unreadmails "$inbox" | |
# done | |
# for inbox in $profile/Mail/pop3.*/Inbox.msf | |
# do | |
# count_unreadmails "$inbox" | |
# done | |
# OUTPUT | |
# Use `echo -n` if no newline should be added. | |
echo -n "$unreadmail_count" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To make this work, you first need to change the
profile
variable to point to your actual Thunderbird profile.Now if you run the script, it should count the mails in your inbox for every included account.
Alternatively comment the lines with SMART MAILBOXES out in the script and enable the lines below it. This will lookup the mailboxes inbox directly, so don't mix smart mailbox with this. Otherwise they are counted twice. You could even lookup the folder structure in your profile and select specific accounts directly.