Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

How to count unread messages from bash script?

  • 6 replies
  • 1 has this problem
  • 7 views
  • Last reply by wognatn

more options

Hello,

I would like to write a bash script to count new, unread emails, to show in conky. Apparently in the past,

grep -c "X-Mozilla-Status: 0000" /path/to/INBOX

worked, but no longer: INBOX file does not change when a new message is read. The corresponding INBOX.msf does, but the changes are pretty incomprehensible. Is there an unread message tag there that I could grep?

Or is there another way to find number of unread messages?

Thanks in advance.

MXLinux 17.1, Thunderbird 60.3.1

Hello, I would like to write a bash script to count new, unread emails, to show in conky. Apparently in the past, grep -c "X-Mozilla-Status: 0000" /path/to/INBOX worked, but no longer: INBOX file does not change when a new message is read. The corresponding INBOX.msf does, but the changes are pretty incomprehensible. Is there an unread message tag there that I could grep? Or is there another way to find number of unread messages? Thanks in advance. MXLinux 17.1, Thunderbird 60.3.1

Modified by wognatn

All Replies (6)

more options

If the account is IMAP and the account setting are not to store messages on this machine then there is no inbox file.

MSF files are in MORK format and ostensibly can be read with a script, but the effort would be significantly more that an unread email count is worth I would think.

more options

Matt said

the effort [to read msf file] would be significantly more that an unread email count is worth I would think.
Thanks, Matt. A little reading on MORK format convinces me you're right.
more options

wognatn said

Matt said
the effort [to read msf file] would be significantly more that an unread email count is worth I would think.
Thanks, Matt. A little reading on MORK format convinces me you're right.

MORK is also the format of the address book files That was my conclusion when I tried to extract information from them.

more options

I have a working check for new messages. As predicted, it was more effort than it was worth. In the unlikely event that anyone is interested ;) I'd welcome improvements and corrections.

It seems that unread messages result in a tag (^94=1) near the end of INBOX.msf. When any new message in that inbox is read or previewed, (^94=0) is appended. So the following works for me to check for new messages:

[loop over all accounts] tac /path/to/INBOX.msf | grep -m 1 '(^94=.)' | grep -v '(^94=0)' && [new mail action]

Modified by wognatn

more options

This is useful.

Any pointers to articles on how to make this part of my local setup (I'm on Win 10...) It would be a bit of a hack to get Msys2 + minnty etc to do all that.

I'm yet to dive into scripting/macros/aliasing (etc) for Thunderbird

more options

I found no documentation, it's all trial and error based on Matt's answer above. There's a little more detail here.