Extracting .jpg from mbox file with MIME::Base64
From: Sally Shears (SallyShears_at_gmail.com)
Date: 02/04/05
- Next message: Alan Stewart: "Re: PAR/PP on Windows XP with ActiveState"
- Previous message: leo.hou_at_gmail.com: "Re: a very bad question (and getting OT)"
- Next in thread: Sally Shears: "Re: Extracting .jpg from mbox file with MIME::Base64"
- Reply: Sally Shears: "Re: Extracting .jpg from mbox file with MIME::Base64"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 03 Feb 2005 21:40:03 -0500
I have an email message in an mbox file with a jpg attachment.
I want a program I can run with cron or procmail to extract the .jpg
attachment from the last message in the mbox. That is, to store the
.jpg as a normal file to be served up by Apache.
The attachment is encoded base64.
I read the whole encoded portion of the mbox file into a character
string and then attempt to decode it with MIME::Base64::decode($str)
The result is zero length, so MIME::Bae64 must be choking on the
content.
Can anyone give me some advice?
-- Sally
Note: cat mbox-file is the STDIN. Output is >file.jpg
#!/usr/bin/perl
use MIME::Base64;
$inheader=1;
$havedata=0;
while (<>) {
if (/.+/) { # ..any character but line-end
chop;
unless ($inheader) {$encoded=$encoded.$_; $havedata=1;}
}
else {$inheader=0;} #discard blank line; now past hdr
}
if ($havedata) {$decoded=MIME::Base64::decode($encoded); print;}
-- Sally Shears (a.k.a. "Molly") SallyShears@gmail.com -or- Sally@Shears.org http://theWorld.com/~sshears
- Next message: Alan Stewart: "Re: PAR/PP on Windows XP with ActiveState"
- Previous message: leo.hou_at_gmail.com: "Re: a very bad question (and getting OT)"
- Next in thread: Sally Shears: "Re: Extracting .jpg from mbox file with MIME::Base64"
- Reply: Sally Shears: "Re: Extracting .jpg from mbox file with MIME::Base64"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|