How do I prevent imap-mail.outlook.com-<GUID>.txt from consuming disk space? [duplicate]

I am fixing an acquaintance's computer that ran out of disk space. Space was so critical that the OS did not launch any apps. I booted in Safe Mode (holding Shift during startup), deleted 1.5 GB of applications, and was able to launch the OS in normal mode and inspect the file system.

A search with du -sh * by hand revealed log files in ~/Library/Containers/com.apple.mail/Data/Library/Logs/Mail, in the format imagp.gmail.com-<UID>.txt that were 29 GB and 6 GB. I understood from this thread that these files are simply a log of all connections to the Gmail server:

Gmail is having trouble with the mac Mail client for quite some time. ... The Mail logs keep a record of the connection process, they're useful to to diagnose problems, ... It's safe to delete those logs.

I inspected the files: they contain both the records of the connections (error codes, server names) and also the content of emails (headers, plain text bodies, and mime-type attachments).

To prevent these problems in the future, does the OS have a way to limit the size of those logs, e.g. keeping only the last 30 days of connection, or doing a first-in-first-out of lines up to a certain file size?


I use some gmail accounts & I also faced a 11 GB log file while analysing disk space one day. But it is not a behaviour of Gmail, rather of Window Menu → Connection Doctor.

Mail Connection Doctor

Also, it's best to not ignore the low space warnings.