What does messagestats use to count number of used licenses?
Messagestats counts the following mailboxes towards the total license counts
Physical Mailboxes - any mailbox created on an information store that has been logged into or has received at least one email.
System Mailboxes
System Attendant mailboxes
SMTP mailboxes