Filtering Email Contents

Hello automators.

Having used email for 30-odd years, I've suddenly realized that my least favourite thing about it is the pollution of the communication thread by privacy disclaimers, signatures, etc.

What I really want is a "Rules" feature (as in macOS Mail, for example) that operates on lines of text within emails rather than on the emails themselves. If a known contact includes a signature, I want to select that text, right-click (or whatever), and choose "Don't Show Me This Anymore." It would then be filtered out of emails as I see them in my inbox, and also out of the quoted content when I reply. That would be a good email program.

Lacking that, is there any role for KM in addressing this problem? I don't see how it could help on the inbox side, but on the outgoing messages I can imagine macros that would copy all the text, do some find-and-replace matching, and paste it back in sans all the boilerplate. At least then I would not be contributing to the problem.

Does anyone see a more elegant solution?

Thank you.

It is very difficult, if not impossible, to edit all of your inbound email to remove the offensive text prior to you opening the email. Even if you open a specific email for viewing/reading, I don't see a way to first edit that email to remove the offensive text.

It is possible to remove the offensive text when doing a reply or forward.
If the email signature that you want to remove is always consistent, then it is possible, but difficult, to build a database of these signatures to be used each time.

This task could easily take several hours (or more) even by an experienced developer who has a good grasp of AppleScript and Apple Mail. Sorry, but I do not have that sort of time available on a pro bono basis.

Good luck. Maybe someone else will know how to do this.

Thank you! That helps me understand the nature and scope of the problem.

Hey @Somfy,

I do feel your pain.

Back in the '90s I had a couple of 1000+ line AppleScripts that used a RegEx OSAX to parse incoming and outgoing email in Eudora.

I made many adjustments with those scripts.

But Eudora had the capability of scripted alteration of incoming and outgoing emails – Apple Mail does not.

So – while your task is possible – it would take an enormous development effort and most likely require a plug-in to be written for Mail.

Not to mention the fact that you have to be able to deal with both plain-text and styled email, which is no mean trick.

Unless you employed a developer like the ones at SmallCubed Software who specialize in Mail plug-in and already have the required expertise, you're probably looking at well over a hundred hours of development time and a huge learning curve for building Mail plug-ins and handling the tricky bits of email.

While I would love to regain the capabilities I had decades ago, I would not want to tackle this project.


I'm back to this topic and am exploring the inelegant "copy all, filter, paste it back" solution. The first problem:

I reply to a message in Mail and get the quoted thread text below my cursor. If I select all that text, cut it, and then paste it back, the quote level indicators are pasted back along with the text itself. But if I do all of the forgoing with a macro and add the "Search and Replace" action before pasting, the quote level indicators disappear once pasted. (Just to be clear, the actual searching-and-replacing part for my specified text works fine.)

I've peered at the various options for the action and can't think of a way to keep the quote indicators. Any suggestions? Thank you.

Mail is probably using an HTML data-type to manage the email structure and quote layers.

When you do a find/replace with Keyboard Maestro that data structure is destroyed, and you're left with RTF – which does not support email quote layers.

So – the only alternative I can think of is to:

  • Extract the HTML data from the clipboard.
  • Parse it to your heart's content.
  • Put the correct data-type back onto the clipboard.
  • Paste.

I looked into doing that years ago and decided it was more than I wanted to mess with...