Apple Mail Statistics from Terminal

Mail keeps a lot of metadata in a SQLite database stored in ~/Library/Mail/V6/MailData/Envelope Index (the V6 changes from time to time with major macOS releases). It's not officially documented and a quick web search didn't yield a lot of results (https://javarants.com/build-your-own-mail-analyzer-for-mac-mail-app-747143e94ccc, https://labs.wordtothewise.com/mailapp/). But you should be able to reverse-engineer the schema using either sqlite3 or any of the GUI-based SQLite tools (just make sure to use a copy of the database to play with).