I was writing something that pulls off file attachmets from an e-mail through IMAP.

I used Mail::IMAPClient to access the email.

The attachments are encoded base64 so I did $imap->bodypart_string($uid,2) to get the base64 encoded file , just because I knew precisely that the second MIME part was supposed to be my file.

Now I had to decode it so I thought I know , "I'll use MIME::Base64::decode_base64 on what I got above and store that in a file" , and that's exactly what I did only to find out later that the file that was supposed to be decoded wound up corrupt , it was a 7z file and couldn't be opened any more.

So I thought , what could have changed ? And I went and ran kdiff3  modif.7z orig.7z and it told me:

"File A and B have equal text, but are not binary equal" then I got really mad and I diffed them to see what's going on , I couldn't make much out of the diff of two binaries

Again I thought what could've been the trouble so I thought I should shave the \r\n off the end of the lines before I decode_base64 , that didn't work either.

Then I just dropped the whole thing , outputted the base64 to a file and tried to decode it with  base64 -d modif.base64 and I got <some bytes..> invalid input . After that, by reading the manpage of base64 I got to know that

       -i, --ignore-garbage
              When decoding, ignore non-alphabet characters.
So I decided to use that , and then base64 -i -d modif.base64 > file.7z.

Apparently that worked and I got my file back and also found a port of base64 on Windows.

But I don't like this , I've added some binaries as dependencies.. I'd like to find alternative encodings to base64 when sending some e-mail, what modules and alternatives are there on CPAN ? I'm interested in portable modules, and how I can use them in combination with Email::Stuff

Best regards,

Stefan

P.S. It turned out to only be a problem for Windows , that MIME::Base64 has , it's most likely a bug that I will report , I have a testcase ready with a base64 file that proves it.


In reply to Base64 and alternative portable encodings for MIME attachments to e-mails by spx2

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.