How to investigate Mail app's random popup bug on Mojave?

Solution 1:

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.