Re: [dev] Stripping html from email

From: Kurt H Maier <karmaflux_AT_gmail.com>
Date: Tue, 24 Aug 2010 10:45:41 -0400

On Tue, Aug 24, 2010 at 9:27 AM, Josh Rickmar <joshua_rickmar_AT_eumx.net> wrote:
> anonymous is right, I just want to remove the text/html attachments,
> not strip the html tags.

MIME sucks; there's no nice way to deal with it. I use perl and the
Mail::Message package from cpan.

------
#!/usr/bin/perl

use Mail::Message;

my $message = Mail::Message->read(\*STDIN);

if ($message->isMultipart) {
        foreach my $part ( $message->parts ) {
                if ( $part->contentType eq 'text/html' ) {
                        $part->delete;
                }
        }
}

$message->print(\*STDOUT);
------

That will delete html attachments, but only from multipart messages
(so html-only mail will be left alone). You just cat the message to
it and it outputs the message (properly restructured if necessary) to
stdout

-- 
# Kurt H Maier
Received on Tue Aug 24 2010 - 16:45:41 CEST

This archive was generated by hypermail 2.2.0 : Tue Aug 24 2010 - 16:48:02 CEST