How to investigate Mail app's random popup bug on Mojave? My friend's computer (running the latest version Mojave) is experiencing that bug where mail.app suddenly — randomly? — and automatically takes focus while having his Google-account connected to it. I've seen others with this problem — and that it has been around for a while. 

Is there a way to find out what is actually happening? A log file perhaps that shows what prompts the Mail app to take focus by itself? It only seems to happen with Google btw. So could it be something with certain Google accounts that forces Mail app to exhibit this behaviour? Any help or pointers in the right direction is much appreciated!

Suggested fixes to this that I've seen so far, have been elaborate workarounds that really doesn't deal with the problem itself, or even what the problem is.
Copying the answer I wrote for this question, Catalina has NOT solved the problem.

Looking for a solution I tried to activate the logging of the connection status (from Mail menu: Windows -> Connection Status).
Examining the log when the Mail app is popping up, I found out these error messages at the exactly same time and on every occurrence of the problem (when the app doesn't pop up the error messages don't show up):

READ Oct 10 20:41:21.323 [kCFStreamSocketSecurityLevelTLSv1_2] -- host:imap.gmail.com -- port:993 -- socket:0x6000003b7de0 -- thread:0x60000322d080
5.659 NO [AUTHENTICATIONFAILED] Invalid credentials (Failure)
--
READ Oct 10 20:41:21.427 [kCFStreamSocketSecurityLevelTLSv1_2] -- host:imap.gmail.com -- port:993 -- socket:0x6000003b7de0 -- thread:0x60000322d080
6.659 BAD Invalid SASL argument. z66mb54202756wmc
--
READ Oct 10 20:41:21.732 [kCFStreamSocketSecurityLevelTLSv1_2] -- host:imap.gmail.com -- port:993 -- socket:0x6000003b7de0 -- thread:0x60000322d080
7.659 NO [AUTHENTICATIONFAILED] Invalid credentials (Failure)


(Just posting the lines containing the errors)

The error messages are present only on the log file of my Gmail account, every other mail account doesn't show any error message. 
So as many of you, I also think that the problem is due to the Gmail accounts.

Hope this can help to solve the problem in any meaningful way.