Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

decoding email attachments.

by tenny1204 (Novice)
on Mar 03, 2013 at 11:21 UTC ( [id://1021494]=perlquestion: print w/replies, xml ) Need Help??

tenny1204 has asked for the wisdom of the Perl Monks concerning the following question:

I am writing an emailprogram using the Net::IMAP:Client module, but i cannot access the attachments when they are encoded. I've taken a few lines of code to try and make my point.

$laat = @$summaries[$#$summaries]; $part = $laat->get_subpart(2.0); $body = $imap->get_part_body($laatste,2.0); $cte = $part->transfer_encoding; # after this print $cte would say 8b +it, so seems ok. $bod = Email::MIME::Encodings::decode($cte, $body); print $$bod;

After this everything is okay as long as it wasn't encoded. Then the encoded information still seems to lay there, beacuse it says something like "YyheDee=". Maybe someone can tell me how to proceed? Thank you.

Replies are listed 'Best First'.
Re: decoding email attachments.
by flexvault (Monsignor) on Mar 03, 2013 at 12:14 UTC

    Welcome tenny1204,

    I'm not familiar with Net::IMAP:Client, but I have written a full email package in Perl for a web mail system, and that series of packages took 2+ years to develop and I already had 10+ years working with email and Perl. I recommend that you get a copy of an O'Reilly book called "Programming Internet Email" written by David Wood. I got my copy used, but it was a great help in answering so many basic/advanced email questions. The most important part is that the examples are written in Perl (and Java), and Perl is what I needed. Also what helped me was the explanation of the terms and the rules for building a RFC compliant email.

    Now I'm going to guess how to help you.

    Once you use MIME, the format of the email document changes. Every part of the email is now controlled by '"Content-Type: ... boundary="..."'. Even the Capitalization of words used in the headers is mandatory.

    Now guessing, the parts of the "body" (which could be a series of nested multi-part messages) needs to be encoded without the headers and the headers have to be separated by two "\r\n" before and after the encoded message. So you need to make sure the boundary headers are not part of the encoded document.

    I use the free Mozilla Thunderbird and if you display a MIME email and then type '^U' (control U), you will see how the raw email is received by Thunderbird. This can help you determine if your generated email looks like the one generated by Thunderbird. I found other clients show the translated email and not the raw input.

    Good Luck...Ed

    "Well done is better than well said." - Benjamin Franklin

      Thank you for replying. I hope someday i will be able to make use of what you just told me. But in order to finish my program i've decided to parse the entire message, and work with that. Save the decoding/encoding for later. Best regards.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1021494]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-19 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found