Perl MIME modules

Stephen R Laniel steve at laniels.org
Sun Sep 25 15:17:44 UTC 2005


I have a very simple email task that I want to perform using
Perl and procmail:

1) Message comes in, destined for username+box at hostname.
   Intercept it.
2) Message may or may not contain a MIME attachment of type
   image/jpeg. If it does, extract that attachment and throw
   away the rest of the message.
3) Create a new message with that image/jpeg attachment.
4) Send that new message on to a given email address.

Step 1 can be handled by procmail. I can't tell what the
best -- simplest, stablest -- way to do steps 2, 3, and 4 in
Perl is. I've looked around, and I see a lot of libraries
like MIME::Decoder, but they all seem too complicated for
what I want. I'd like to be able to do something like

# Extract attachments from existing msg
my $message = join '', <>;
my $newMsg = new Email::Foo($message);
my @attachments = $newMsg->extractAttachments($newMsg);
my @newAttachments = ();
foreach(@attachments) {
	if( $_->mime_type == 'image/jpeg' ) {
		push @newAttachments, $_;
	}
}

# Note that objects in @newAttachments are MIME objects
# containing a file and a MIME type, among other things

# Create a new message with the right attachments
my $outboundMsg = new Email::Bar;
foreach(@newAttachments) {
	$outboundMsg->attach($_);
}

# Send it
$outboundMsg->send('user at domain.com');

What's the best library to do this? My needs are simple, so
the coding should be simple as well.

-- 
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20050925/bc09fe3e/attachment.sig>


More information about the ubuntu-users mailing list