Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][tlug] Re: .forward file
- Date: Fri, 12 Dec 2003 13:44:23 +0100
- From: Tobias Diedrich <ranma@example.com>
- Subject: [tlug] Re: .forward file
- References: <3FD9338A.3050005@example.com>
- User-agent: Mutt/1.5.4i
Sven Simon wrote: > I, therefore, would like to strip off the attachment and forward only > the text > message to my mobile. I know we can pipe stuff to external commands from > the .forward file, but how do I get rid of the attachments? Try the following perl script: ------- begin MULTIPART-strip.pl --------- #!/usr/bin/perl -w use strict; use MIME::Parser; use MIME::Entity; use MIME::QuotedPrint; $|++; my $envelope = <STDIN>; my $parser = MIME::Parser->new; $parser->output_to_core('ALL'); my $ent = $parser->read(\*STDIN); sub getplainpart { my $ent = shift; if ($ent->is_multipart) { for (my $part = 0; $part < $ent->parts; $part++) { if ($ent->parts($part)->effective_type eq "text/plain") { return $ent->parts($part); } if ($ent->parts($part)->is_multipart) { return getplainpart($ent->parts($part)); } } } else { if ($ent->effective_type eq "text/plain") { return $ent; } else { return MIME::Entity->build( Data => "[[ text/plain part is missing ]]\n", Encoding => '7bit', Type => 'text/plain'); } } } my $plainpart = getplainpart($ent); my $content_transfer_encoding = $plainpart->head->get('Content-Transfer-Encoding') || '7bit'; my $content_type = $plainpart->head->get('Content-Type') || 'text/plain'; my $body = $plainpart->body_as_string; if ($content_transfer_encoding =~ /^quoted-printable/i) { $body = decode_qp($body); $content_transfer_encoding = '8bit'; } my $newent; if ($ent->is_multipart) { $newent = MIME::Entity->build( Data => $body . "\n\n[[ Multipart mail stripped ]]\n", Encoding => $content_transfer_encoding, Type => $content_type); $ent->parts([$newent]); $ent->head->add('X-Mailfilter', 'Multipart mail stripped'); $ent->make_singlepart; $ent->sync_headers(Length => 'COMPUTE', Nonstandard => 'ERASE'); } else { $newent = MIME::Entity->build( Data => $body, Encoding => $content_transfer_encoding, Type => $content_type); $ent->make_multipart; $ent->parts([$newent]); $ent->make_singlepart; $ent->sync_headers(Length => 'COMPUTE', Nonstandard => 'ERASE'); } # Netscape does not understand the "In-Reply-To" header when parsing. # Add to References my $inreplyto = $ent->head->get('In-Reply-To'); if(defined($inreplyto)) { my $reference = $ent->head->get('References'); if(defined($reference)) { my @example.com = split(/ /, $reference); my $lastref = pop(@example.com); if ($lastref ne $inreplyto) { $ent->head->replace('References', $reference . ' ' . $inreplyto); $ent->head->add('X-References', 'Modified'); } } else { $ent->head->add('References', $inreplyto); $ent->head->add('X-References', 'Modified'); } } # print $envelope; $ent->print; ------- end MULTIPART-strip.pl --------- -- Tobias PGP: http://9ac7e0bc.2ya.com This mail is made of 100% recycled bits. np: Yoko Kanno: Ghost in The Shell : Stand Alone Complex - be Human (VICL-61217 09 - spotter []
- Follow-Ups:
- Re: [tlug] Re: .forward file
- From: Sven Simon
- References:
- [tlug] .forward file
- From: Sven Simon
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] [REMINDER] 2003 Bonenkai
- Next by Date: Re: [tlug] .forward file
- Previous by thread: Re: [tlug] .forward file
- Next by thread: Re: [tlug] Re: .forward file
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links