Stripping HTML, MIME and attachments from email before delivery.

1 post / 0 new
#1 Wed, 05/04/2016 - 02:25
AustinTX

Stripping HTML, MIME and attachments from email before delivery.

I have email which comes from one source, delivered to a particular email address, which needs to be stripped of all HTML/MIME content. These emails come from a social network [nextdoor.com - avoid it like cancer!], and the emails always contain a text version of the messages as well as a gargantuan html section with compressed blocs of javascript. Each email is empgregnated with sophisticated tracking code, and I do not care to provide them with IPs, activity times, or the identity of those I forward messages to (it's against their rules, and they DO punish!).

This simple filter has proven to be MUCH harder to find than you'd think. There seem to be no management add-ons for Thunderbird in the same vein as those which permanently remove attachments. There are armies of old geeks in the forums, insisting that stripping HTML/MIME isn't really what I want to do. You wouldn't believe the lengths some have gone through to argue about it!

I finally settled on a couple of promising candidates here: http://www.perlmonks.org/?node_id=53404 and here: http://www.phred.org/~alex/stripmime.html I liked how short and sweet the script on perlmonks was, but it requires additional modules and seems to do less than stripmime. I found that I could cat a variety of multipart email messages, with and without attachments, through the stripmime script and it performed perfectly. Now, I just needed to hook it into the email account which is hosted on my Virtualmin server. The email account can be managed with Usermin, as it is a real Linux account.

Get The Script

First download the script here: http://www.phred.org/~alex/stripmime.pl If the website is down, I have verified that it is stored on archive.org. Place the script in the email account's home directory. There may be better places for it, but I found this worked. Next, chmod +x stripmine.pl and then chown user:host stripmine.pl where "user" is the email username and "host" is the domain group. Other ownership attributes probably work, but these worked for me when root:root initially didn't seem wise.

Webmin

Next, go to the Webmin tab, Webmin settings, Usermin Configuration, Available Modules, and check Procmail Mail Filter to add this module to the Usermin interface.

Virtualmin

Now return to Virtualmin, Select the domain which your email user is in, and select Edit Users. Select your email user and then click Login to Usermin.

Usermin

Next to Mail, click the Usermin tab, and find "Procmail Mail Filter" in the list on the left (under Mail?). Click "Add a new filter action". Set Delivery mode to "Feed to program" and enter the whole path and name leading to stripmine.pl Check "Action program is a filter" below and Save.

This produces a .procmailrc in the email account's directory such as this:

:0f
| /home/hostname/homes/username/stripmime.pl

Repeat as desired for each individual account you want stripped of HTML, MIME content and attachments. You can probably install this filter script systemwide, but this won't usually be desireable.

When stripmime doesn't find plain-text, but there is an HTML section, it attempts to reduce it to text. Stripmime also adds a report footer, which you can disable by commenting out at least lines 359-364.

Please comment if you recommend better file attributes, or even a better way to strip HTML/MIME/attachments. Stripmime is around 15 years old at the time of this posting, but still works like a charm!