macOS Mail crashes when window is closed (app brought into background) For the last year (possibly longer) the Mail app on my iMac crashes after I close the window (not quit, just close using the red X button in the top left corner, or with cmd+w). This happens 100% of the time without fail. I submit a crash report to Apple each time but it seems like this isn't addressed. Note, I only have one account connected and that is my iCloud. Things I've tried:


resetting PRAM
removed Mail preferences files
removed the entire library (can't remember how, found instructions online. but after it was finished the app asked to rebuild the mail index)
rebuilding mailboxes (https://support.apple.com/guide/mail/rebuild-mailboxes-mlhlp1227/mac)
removing and re-adding my account


I'm out of ideas besides reinstalling macOS but that's my last resort. Here's part of the crash log:

Process:               Mail [10894]
Path:                  /Applications/Mail.app/Contents/MacOS/Mail
Identifier:            com.apple.mail
Version:               11.5 (3445.9.1)
Build Info:            Mail-3445009001000000~1
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           Mail [10894]
User ID:               501

Date/Time:             2018-08-30 11:29:14.606 -0400
OS Version:            Mac OS X 10.13.6 (17G65)
Report Version:        12
Anonymous UUID:        &lt;STRIPPED&gt;

Sleep/Wake UUID:       &lt;STRIPPED&gt;

Time Awake Since Boot: 45000 seconds
Time Since Wake:       6100 seconds

System Integrity Protection: disabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [0]

VM Regions Near 0:
--&gt; 
    __TEXT                 000000010a623000-000000010a9e5000 [ 3848K] r-x/rwx SM=COW   [/Applications/Mail.app/Contents/MacOS/Mail]


Edit to add detail:

When I disable my iCloud account in preferences, I can close the app without it crashing. But as soon as the account is re-enabled, it goes right back to crashing on close.

Another thing I noticed is that if I click the "Mailboxes" button to show all mailboxes (eg, Inbox, Flagged, Sent, etc). I can switch to any other mailbox and close the app without problems. It only crashes if I have the Inbox selected and close the app.

Update:

Opened Console and tracked error messages from Mail app. Here are the results, all of these errors are logged multiple times except the AEGetDescData error.

Error sending searchable item 29964 to CoreSpotlight:Error Domain=CSIndexErrorDomain Code=-1000 "(null)"

[AOSAccounts] : [ACAccount+iCloudAccount] : -[ACAccount(iCloudAccount) icaCloudKitToken] - icaCloudKitToken cannot be returned as account is still not vetted!

AEGetDescData of non-desc type 'reco' not a good idea


Update

A lot of events are logged in Console. I cleared the console before closing Mail, here's a screenshot with all the messages (my email address blurred out).
While evaluating your Console report I came across nasty malware on your system called "ScorecardResearch"

Since it is interacting with your Mail and who knows with what else and it is clearly sending your information without your consent, I assume it is also responsible for the Mail error.

Get rid of it.
https://www.2-spyware.com/remove-scorecardresearch-com.html