V

Deleting mail attachments

For ages1) I have been using a Perl script called demime written by Nick Simicich in order to remove attachments and HTML from message, e.g. for mailing lists or my personal archiving. demime still works astonishingly good but it does have its quirks, and it is rather radical in what it does. Hence, I was always looking for alternatives.

Recently, I came across remove_mime.pl by Aaron Ciuffo which is based on a script by Mike A. Leonetti. Eventually, these two encouraged me to write my own script: attachment_filter.pl

Resources

A crude summary of what I have found so far on the Perl side:

Scripts

  • demime.pl by Nick Simicich: 15 years old and still rocking!
    Strips down messages to text/plain; allows to convert HTML by means of lynx; almost no dependencies; not for the faint of heart. Unfortunately, the original link http://scifi.squawk.com/demime.html is not available anymore, but feel free to download my copy: demime_1.1e_as1.pl
  • remove_mime.pl by Aaron Sciuffo: Removes attachments based on filename extensions; simple; depends on Email::MIME.
  • remove_attachments.pl by Mike A. Leonetti: The mother script of remove_mime.pl; also only depends on Email::MIME; includes instructions of how to use with Postfix; sends autoreply to sender if attachments have been removed.
  • strip-attachments.pl by Pjotr Prins: Uses Perl's Mail::Box; processes a mbox mailbox; writes attachments to a folder, and deletes the attachments from the e-mail. The script, as it is, removes attachments based on their size (if larger than 16K).
  • mimefilter.pl by D.G.M. Salvetti: Comes as a Debian package; some dependencies; filters based on Content-Type/MIME type; a bit awkward to handle; sends autoreplies.
  • stripmime.pl by Alex Wetmore: No dependencies; leaves only text/plain; converts HTML to text by means of an over-simplified HTML parser; not recommended because it breaks quite a bit.
  • attachment_filter.pl: my own attempt; uses Email::MIME; removes attachments based on their MIME Content-Type; works with nested multipart attachments; follows the KISS principle.

Modules

  • Email::MIME: Easy MIME message parsing, by Ricardo Signes, Casey West, Simon Cozens; depends on and extends Email::Simple; much recommended; for examples see the scripts by Mike A. Leonetti, Aaron Ciuffo, and my own.
  • Email::MIME::Attachment::Stripper: Handy to remove and extract attachments, but I couldn't find code that shows how to re-assemble messages so I haven't tried it, yet, and instead sticked to Email::MIME.

Further reading

1)
Well, almost ages, but I do remember the times where e-mail had no attachments ;-)

Discussion

Andreas Schamanek, 2015-07-20 15:54

alterMIME - email disclaimer and Xheader manipulation is a C program that i.a. can "remove attachments based on filename or content-type"

Enter your comment. Wiki syntax is allowed:
L D᠎ T᠎ C F
 
 
blog/130109_delete_mail_attachments.txt · Last modified: 2013-01-10 23:09 by andreas