I'm using Mail::Box and friends to find all the image/jpeg bodies in an mbox file.

Does anyone know of a handy way to take such a body and write it to a .jpg file? I have written it out as text and was going to use C for the .jpg, but looking at the original data in the mbox I'm realizing this is not a binary stream such as you would get with a normal HTTP response -- the values are all valid ascii, ie. this is not normative jpeg data.

Strangely, I can't find anything out about that googling either. Anyone know anything?

SOLVED
Okay, it's encoded in base64 -- for posterity:
use Mail::Box::Manager; use MIME::Base64::Perl; [...] my $msg = $folder->message(0); if ($msg->isMultipart) { my @parts = $msg->parts; foreach (@parts) { if ($_->contentType eq "image/jpeg") { (my $body = $_->body) =~ s/\n//g; my $jpg = decode_base64($body); } } }
$jpg can be written straight to a .jpg file.

Whew!

In reply to grabbing jpg from mbox [SOLVED] by halfcountplus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.