Extracting .jpg from mbox file with MIME::Base64

From: Sally Shears (SallyShears_at_gmail.com)
Date: 02/04/05


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


Relevant Pages

  • Re: Extracting .jpg from mbox file with MIME::Base64
    ... > I want a program I can run with cron or procmail to extract the .jpg ... > The attachment is encoded base64. ... > I read the whole encoded portion of the mbox file into a character ...
    (comp.lang.perl.misc)
  • Embedding a picture in an Outlook email message
    ... I would like the recipient of my email message to see a .jpg in the body ... I could also save the picture as .html, ... points to the picture automatically when the user opens the message. ...
    (microsoft.public.outlook.program_vba)
  • Re: Extracting .jpg from mbox file with MIME::Base64
    ... >> I have an email message in an mbox file with a jpg attachment. ...
    (comp.lang.perl.misc)
  • Reply on Publisher email is scrambled.
    ... I am using MS Publisher to create an email. ... However, when I REPLY to my email message, it scrambles the formatting. ... How do I stop this (other than sending a JPG)? ...
    (microsoft.public.publisher)
  • Reply on Publisher email is scrambled.
    ... I am using MS Publisher to create an email. ... However, when I REPLY to my email message, it scrambles the formatting. ... How do I stop this (other than sending a JPG)? ...
    (microsoft.public.publisher.webdesign)