I want to add to i3 status bar indicator showing number of unread emails in Thunderbird profile. Since Thunderbird itself doesn't have command-line options to get that info, I've tried to query it's database using X-Mozilla-Status code:

$ grep 'X-Mozilla-Status:' ~/.thunderbird/<profile>/ImapMail/<email>/INBOX

But it appears that all messages has the same status code (there is no difference whether message unread or not):

X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000

Is there are any other way to build a script get total/unread emails count statistics?

5 Answers 5


I hope the results of some experiments are useful. (Tbird 60.3.1, MX-Linux 17.1) As anlar said, the INBOX file changes when a message is received but not when it is previewed or read. The corresponding INBOX.msf, which is in incomprehensible mork format, records such actions.

A tag (^94=1) is added to INBOX.msf when a new message is received and (^94=0) is appended when a previously unread message is read or previewed. Therefore, if

grep '(^94=.)' /home/user/.thunderbird/profile-name/ImapMail/imap.account.com/INBOX.msf | tail -1

shows (^94=1), there is at least one new message on that account. If (^94=0) then the last action was to read or preview a new message; there may still be unread messages, though. (Edit: corrected file name)

This is only trial and error, but a script based on it (new msg detector only, no count) is working well so far :) (see this question on Mozilla forum.)


msf file fields are listed at the beginning; among them are (A1=numMsgs)(A2=numNewMsgs). It's not clear how to use this to get a count. For example, this account has 3 new messages:

grep -n '(^A2=.)' INBOX.msf
432:    (^A8^85)(^B5=50)(^A1=20)(^A2=2)(^A6=50)(^BD^77A)(^C4=12)(^C5=2)
433:    (^C6=0)(^C7=0)(^C9^5B0)(^C8^A0)(^A4^760)(^A2=0)(^A2=0)(^A2=0)(^AA=0)]}
480:    (^B0=1)(^88^83)(^B1=222)(^B2^84)(^A8^85)(^B5=50)(^A1=21)(^A2=3)
482:    (^A4^760)(^A2=0)(^A2=0)(^A2=0)(^AA=0)]

Maybe someone who knows mork could explain how to extract the right number?

  • The A2 field seems to work for me. To list the unread counts of all mailboxes I use: find ~/.thunderbird/profile-name/ImapMail -name 'INBOX*.msf' -exec sh -c "echo '{}' && grep '(^A2=' '{}' | tail -n1 | sed -r 's/.*\(\^A2=(\w+)\).*/\1/' | xargs -n1 -L1 --replace=__ printf '%d\n' '0x__'" \; Commented May 1, 2020 at 9:32
  • A2 field works great mostly, but if received several emails at once (for example when thunderbird just started) then A2 fields gives wrong info.
    – Monu
    Commented Jul 17, 2022 at 20:47
  • Seems that the (^94=.) fields are now (^93=.) in recent Thunderbird versions (>= 115). A2 fields are now named A1. Probably all fields were decremented by one.
    – IngoMeyer
    Commented Sep 18, 2023 at 17:21

I know this is old and it's probably answered already, but here are my two cents. Hope it helps!




COUNTS=`find . -name '*.msf' -exec grep -REo 'A2=[0-9]' {} + | grep -Eo 'imap.gmail.*INBOX.*=[0-9]+'`


# Counts are in chronological order, so it's safe to assume that the latest is the most recent update
for line in $COUNTS; do
    ACCOUNT=`echo $line | awk -F ':A2=' '{ print $1 }'`
    COUNT=`echo $line | awk -F ':A2=' '{ print $2 }'`



I have two email accounts (Personal and Work). Both have separate msf files used by Thunderbird to update information about them.

This script just greps "A2=" on those files, which is the field Thunderbird uses to keep unread emails count, and gets always the latest of those lines (sometimes the counts get duplicated but from what I've seen the last row is always the most recent).

  • 1
    It would be nice if you added a few words of explanation of what your code does and how it does it.  Also, you might want to consider using $(…) instead of `…`. Commented May 27, 2020 at 0:07
  • Thanks for your input Scott. You're right, I added a brief description about how the script works. Commented May 27, 2020 at 23:49

From this article:

Thunderbird doesn't have a scripting capability.

The same article actually recommends reading from the mailbox files directly, checking the X-Mozilla-Status as you're already doing (and apparently not really working as expected.) See that article for more pointera on the X-Mozilla-Status header and the mbox format, to double check that what you're doing is matching their instructions.

Another possibility is that you're using IMAP from Thunderbird and it behaves differently in that case. IMAP has special flags (such as \Seen to track message status and it's possible Thunderbird is caching and processing those, so maybe look for them too. If you're using IMAP, another option is to use a separate IMAP client to query the server directly (you'll find IMAP bindings for most common scripting languages.) This approach has the disadvantage that you'll use the network for this check and also you'll have to manage and store credentials.


Hope this helps, only check if have unreads, not counts.

grep '(^94=.)'  INBOX.msf |tail -1|grep '(^94=1)'|wc -l

Pointing to your INBOX.msf

Tested and used with Conky.

  • grep .. | wc -l can be replaced by grep -c ..
    – Archemar
    Commented May 14, 2021 at 8:25

INBOX.msf is complex. This works okay but not great because it overly simplifies reading INBOX.msf. It can ignore new mail if left unread.

Edit: I had to install the apt version of Thunderbird, this didn't work on the Snap version (Ubuntu 18.04.6 LTS, Thunderbird 91.11.0).


cd $HOME/.thunderbird
inbox=$(find . -name 'INBOX.msf')

#list file in reverse, strip 94's, remove the first occurrence of 94=0 and all after
count=$(tac $inbox | grep '(^94=' | sed -n '/94=0/q;p')

#count line number for new emails
echo $count | grep -o "94=" | wc -l

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .