digitalgod Posted February 20, 2008 Share Posted February 20, 2008 hey guys, I'm trying to parse emails and store them in a db, everything works fine except for the fact that no matter what the body of the email is, I always get this message in the db This is a multipart message in MIME format.<br /> any ideas why it does that? I'm using pop3 and here's my parse function $email = $pop3->get_mail($i); $email = parse_email ($email); echo nl2br(htmlentities($email['message'])); function parse_email ($email) { // Split header and message $header = array(); $message = array(); $is_header = true; foreach ($email as $line) { if ($line == '<HEADER> ' . "\r\n") continue; if ($line == '<MESSAGE> ' . "\r\n") continue; if ($line == '</MESSAGE> ' . "\r\n") continue; if ($line == '</HEADER> ' . "\r\n") { $is_header = false; continue; } if ($is_header == true) { $header[] = $line; } else { $message[] = $line; } } // Parse headers $headers = array(); foreach ($header as $line) { $colon_pos = strpos($line, ':'); $space_pos = strpos($line, ' '); if ($colon_pos === false OR $space_pos < $colon_pos) { // attach to previous $previous .= "\r\n" . $line; continue; } // Get key $key = substr($line, 0, $colon_pos); // Get value $value = substr($line, $colon_pos+2); $headers[$key] = $value; $previous =& $headers[$key]; } // Parse message $message = implode('', $message); // Return array $email = array(); $email['message'] = $message; $email['headers'] = $headers; return $email; } *edit* I forgot to ask, is there any way of flagging an email as read without actually deleting it from the server? Link to comment https://forums.phpfreaks.com/topic/92193-parsing-emails/ Share on other sites More sharing options...
bpops Posted February 21, 2008 Share Posted February 21, 2008 I only started learning about parsing emails the other day, so I'm not an expert, but I think I know your problem. When an email is sent out as a multipart document, one part is the header, one part the message, one part an attachment, etc. If the email is sent out as HTML, however, I believe this is another part entirely. So you may want to try to parse for the HTML part. Just an idea. Wish I could help more. Link to comment https://forums.phpfreaks.com/topic/92193-parsing-emails/#findComment-472424 Share on other sites More sharing options...
digitalgod Posted February 21, 2008 Author Share Posted February 21, 2008 yeah that's what I figured but I'm still not exactly sure how to parse the HTML part... I'll look into it some more Link to comment https://forums.phpfreaks.com/topic/92193-parsing-emails/#findComment-472429 Share on other sites More sharing options...
aka_bigred Posted April 10, 2008 Share Posted April 10, 2008 Were you able to figure out how to parse the emails (and display attachments, etc)? I've got a project I'm trying to parse the raw file sent via SMTP for display in a browser. Link to comment https://forums.phpfreaks.com/topic/92193-parsing-emails/#findComment-513550 Share on other sites More sharing options...
digitalgod Posted April 10, 2008 Author Share Posted April 10, 2008 I don't know about attachments but yes I was able to parse emails, where are you having problems? Link to comment https://forums.phpfreaks.com/topic/92193-parsing-emails/#findComment-513913 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.