Apple Mail automatic cleanup tips request

This weekend Apple Mail on my dad’s ‘ancient’ Mac Mini (a core2duo running El Capitan) all of a sudden stopped working. It crashed immediately after opening the app. After a bit of trial and error I came to the conclusion that the number of e-mails in one of his IMAP accounts was probably too much to handle for Over the years he gathered some 6,000+ e-mails in his Inbox and another 2,000+ in an Archive folder I created some time ago (but didn’t get used afterwards…).

So I spent quite a bit of time going through years and years of shipping and delivery notifications, newsletters and what have you until I reached a reasonable number of mails. Storing most of the remaining mail in Archive folders per year. Thankfully there’s a web interface for this mail account, so I could still do this task.

I think it’s safe to say my dad doesn’t like to clean up his mail. :wink: I also know now he likes to sign up for newsletters.

To avoid the same issue in the future, I’m looking for ways to automate the cleanup process for him. Does anyone have tips to keep his Inbox within limits without relying too much on his lacking digital cleaning skills? Ideally I’d like to run a rule, or set of rules, that deletes newsletters, etc. from his Inbox after x amount of time if they are read (which all of them are).

All tips and tricks are welcome.

P.S. The IMAP account itself was not the bottleneck as it has basically unlimited storage (self-hosted).

I have close to 100K emails, combined, in the eight email IMAP accounts Mail handles for me. I don’t think that’s likely to cause a crash.

The number of emails isn’t the cause - it’s probably database corruption. Two things to try:

  • use a utility like Onyx to rebuild the mailboxes
  • vacuum the database - exact syntax (needs Terminal) varies depending on version of MacOS. Has worked well for me. Examples here:

For Snow Leopard (10.6): sqlite3 ~/Library/Mail/Envelope Index vacuum;
For Lion (10.7), Mountain Lion (10.8), Mavericks (10.9), or Yosemite (10.10): sqlite3 ~/Library/Mail/V2/MailData/Envelope\ Index vacuum;
For El Capitan (10.11): sqlite3 ~/Library/Mail/V3/MailData/Envelope\ Index vacuum;
For Sierra (10.12): sqlite3 ~/Library/Mail/V4/MailData/Envelope\ Index vacuum;
For High Sierra (10.13): sqlite3 ~/Library/Mail/V5/MailData/Envelope\ Index vacuum;
For Mojave (10.14): sqlite3 ~/Library/Mail/V6/MailData/Envelope\ Index vacuum;
For Catalina (10.15): sqlite3 ~/Library/Mail/V7/MailData/Envelope\ Index vacuum;

Best thing to do is have him stop using e-mail as a filing system. As mentioned, it's likely database corruption as Mail can handle many more e-mails than that. If he had tens of thousands of emails and the store gets corrupted, it can be hard to recover from that. I prefer to save any e-mails as a PDF (or the often attached PDF) into my existing filing system. Easier to backup and restore.

Before retirement my wife worked as an Exchange administrator. She had users with immense email stores that would occasionally break and it was a lot of work to recover them.

1 Like

I was working on an Exchange migration from one cloud host to another. The migration script did not call for moving Trash. One day, in a panic, a corporate attorney called in because her years of filed correspondence was gone! This very senior counsel had the practice of using Outlook trash as her filing cabinet. Go figure.

1 Like

Thanks for the tips for vacuuming the database. :thumbsup: Didn’t come across that when I looked for a solution.

It’s not so much that he’s using email as a filing system. It’s more that he forgets to delete mail that’s really of no use. I myself like to keep a lot of mail for reference: orders, receipts, etc. And I think that’s fine. But to keep the “newsletter” from the local grocery store for more than a week is useless. It’s that problem that I try to get an automated solution for.

That being said, it doesn’t look like Apple mail (nor any other mail client for that matter) has a time-based trigger for rules. So that makes it a bit more challenging.

You can set “Date Received (or Sent) is greater than …” in Mail rules.

So something like:

From contains “the local grocery”
Date sent is greater than 7 days

Action: Delete message (or Move message to designated archive mailbox)

That would be a solution. If it wasn’t for the fact that rules only get triggered when e-mail messages arrive. So in order to apply this rule to old e-mail one has to manually select them and apply the rule. AFAIK.

Ah, hmmm…, yes. You have found the one tiny detail that invalidates the whole idea :flushed:

Apologies for that

No problem. Like I wrote in my initial post: all tips and tricks are welcome. :slight_smile:

But surely you’d prefer ones that worked?

Long shot, but if you can get him access to MS Outlook (perhaps on one of your computers?), you can use its auto-archive/delete on the IMAP account to keep it slim, and then those changes will sync over to Mail.

imapfilter is the tool you are looking for.

It has been a huge timesaver for me .
I use it with my work account and here are a few things I do with it -

  1. Filter every email from a sender not in my address book to a different folder
  2. Filter emails from newsletters (like LinkedIn) into a separate folder
  3. Delete emails in newsletter folders (like LinkedIn ) which are older than 3 months

I have been an imapfilter user for several years now and it helps preserve my sanity while processing email. It ensures that emails from clients and colleagues are addressed first .




SaneBox can automatically sort the non-important stuff to different folders (SaneLater, SaneNews, etc).

You can also set it to automatically delete email from certain folders after X days.

(I’ve been a paying SaneBox customer since… 2013, I think.)

Thanks a lot! That’s indeed the tool I’m looking for. Great tip. It’s available through homebrew too. :slight_smile:

1 Like