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
Maybe someone who knows mork could explain how to extract the right number?