1

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?

2

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.)

Added:

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?

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.