yheffen Posted July 8, 2009 Share Posted July 8, 2009 I want to extract the body and attachment from an email. I would expect the mailparse package to do just this, but I am having problems. The mailparse documentation, http://us3.php.net/manual/en/book.mailparse.php, isn't giving me the clues that I need. I can extract the headers of the messages, but I want to extract the bodies and attachments of each MIME part, and the parts happen to pretty much all be Base64 encoded, even the body. I would expect this to be a pretty common thing, but I can't find mailparse examples to do this. The big problems I'm having with the documentation is that is not clear how to tell the functions to operate on parts of a MIME message rather than the message as a whole, or how to figure out what parts a message has in the first place. Anyone know of examples or can offer help? Or have recommendations for a different extension or class to use? Link to comment https://forums.phpfreaks.com/topic/165269-mailparse/ Share on other sites More sharing options...
trq Posted July 9, 2009 Share Posted July 9, 2009 I've never used nor even installed this package but going by there descriptions mailparse_msg_get_structure and mailparse_msg_get_part are surely what your looking for. Link to comment https://forums.phpfreaks.com/topic/165269-mailparse/#findComment-871841 Share on other sites More sharing options...
yheffen Posted July 9, 2009 Author Share Posted July 9, 2009 Yep, I've tried to figure out how to use those to get started, but I seem to be missing the last step. The mailparse_msg_get_structure() function will correctly show the structure of my email. I can then use mailparse_msg_get_part() to zero in on the MIME section that I want... But once I get down to there, a mailparse_mail_structure resource of the piece of the email that I want, I can't figure out which function can then pull the body out of there. I can use mailparse_msg_get_part_data() to pull the header out of the section, but how do I pull out the (decoded) body? Here's example code, <?php $msg = mailparse_msg_create(); $msg = mailparse_msg_parse_file('cattool.eml'); $msgstruct = mailparse_msg_get_structure($msg); var_dump($msgstruct); $msgpart = mailparse_msg_get_part($msg, "1.1"); var_dump($msgpart); $msgdata = mailparse_msg_get_part_data($msgpart); var_dump($msgdata); ?> That spits out, array(3) { [0]=> string(1) "1" [1]=> string(3) "1.1" [2]=> string(3) "1.2" } resource( of type (mailparse_mail_structure) array(11) { ["headers"]=> array(2) { ["content-type"]=> string(9) "text/HTML" ["content-transfer-encoding"]=> string(6) "base64" } ["starting-pos"]=> int(868) ["starting-pos-body"]=> int(927) ["ending-pos"]=> int(133536) ["ending-pos-body"]=> int(133536) ["line-count"]=> int(2044) ["body-line-count"]=> int(2041) ["charset"]=> string( "us-ascii" ["transfer-encoding"]=> string(6) "base64" ["content-type"]=> string(9) "text/html" ["content-base"]=> string(1) "/" } Link to comment https://forums.phpfreaks.com/topic/165269-mailparse/#findComment-872308 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.