Autor | Zpráva | ||
---|---|---|---|
Kalby Profil |
#1 · Zasláno: 8. 6. 2009, 14:47:56
Zdravim
pro jednu aplikaci pisu takoveho jednodusiho mailoveho klienta, posilani mailu mam vyreseno, prijmani ze serveru take, pres nejakou imap tridu (pripojeni klasicky pres fsockopen). Problem je v tom, ze pri stazeni mailu musim veskery data dostavat z hlavicky a tela pres regularni vyrazy (datum poslani, odesilatel, predmet atd.) a je v tom bordel, pac staci jiny kodovani, poslana priloha v tele zpravy atd. A tak sem se chtel zeptat neexistuje jiz neco hotoveho na parsovani tehle dat? Moc clanku na netu sem na tohle tema nenasel tak nevim, diky za kazdou radu |
||
peta Profil |
#2 · Zasláno: 9. 6. 2009, 13:33:42
phpTicket, ale cely program jsem prepisovat, protoze neuvazoval ruzna kodovani a i tak to dela chybne asi. Zkusim ti najit fragmenty kodu, ale nevim, jak moc je to spolehlive...
Tez cz.php.net/nazevfunkce function text_convert ($text, $charset) { global $CFG; if ($charset) { $text = iconv($charset, $CFG['charset'], $text); if ($text) return ($text); } return ($text); } ============= //$charset function pp_decode($str) { global $CFG; $elements = imap_mime_header_decode($str); $charset = $elements[0]->charset; $text = $elements[0]->text; //text to utf-8 $text2 = ""; $charset = strtolower($charset); if ($CFG['charset']=='utf-8' && ($charset=="utf-8" || $charset=="utf-7")) {$charset = false;} $text = text_convert($text,$charset); return $text; } ============= $mbox = imap_open("{".$cat_row["pop_host"]."/pop3:110/notls}INBOX",$cat_row["pop_user"],$cat_row["pop_psw"]) or print ("Error retrieving new mail from ".$cat_row["pop_host"]."<br>\n"); ========= if (imap_num_msg($mbox)>0) { print "Retrieving new messages.<br>"; while ($curmsg <= imap_num_msg($mbox)) { $body1 = get_part($mbox, $curmsg, "TEXT/PLAIN"); if ($body1 == "") {$body1 = get_part($mbox, $curmsg, "TEXT/HTML");} $body = text_convert($body1[0],$body1[1]); $body = eregi_replace("-----Original.*","",$body); // filters out outlook's quotes from replies if ($body == "") { /* We can't do anything with this email, leave it there */ print "Error: Message could not be parsed. I left it in the mailbox.<br>"; continue; } $head = imap_headerinfo($mbox, $curmsg, 800, 800); // TODO: Name and Email address should be properly parsed here. //print_r($head); $email = $head->reply_toaddress; $email = ereg_replace(".*<","",$email); // pl - quick hack to parse name, email $email = ereg_replace(">.*","",$email); // pl - quick hack contd. $name = pp_decode($head->fromaddress); $name = ereg_replace(" <.*","",$name); // pl - quick hack contd. $name = trim($name);//pp $name = ($name!="" || $name!=" ") ? $name : $email; //pp $subject0= pp_decode($head->fetchsubject); $subject = trim($subject0);//pp $subject = ($subject!="" || $subject!=" ") ? $subject : $email; //pp print "Subject: $subject<br>"; /* Check the subject for ticket number */ if (!ereg ("[[][#][0-9]{6}[]]", $subject0)) { /* Seems like a new ticket, create it first */ print "Creating a new ticket.<br>"; $ticket_id = CreateTicket($subject, $name, $email, $cat_row["id"], "", "2", $body); if ($ticket_id == false) { /* We had troubles creating the ticket. Forward the problematic email to a real human */ print "Warning: CreateTicket failed! Message forwarded to $trouble_email <br>"; Send_Email ($trouble_email, "{TROUBLE} $subject", "[ERROR: CreateTicket failed]\n".$body, "From: $name\nReply-To: $email"); imap_delete($mbox, $curmsg); $curmsg++; continue; } } else { /* Seems like a followup of an existing ticket, extract ticket_id from subject */ $ticket_id = substr(strstr($subject0, "[#"), 2, 6); print "Follow up to ticket #$ticket_id<br>"; } if (!PostMessage($ticket_id, $body)) { /* Could not post the ticket, forward the problematic email to a real human */ print "Warning: PostMessage failed! Message forwarded to $trouble_email <bR>"; Send_Email ($trouble_email, "{TROUBLE} $subject", "[ERROR: PostMessage failed]\n".$body, "From: $name\nReply-To: $email"); } imap_delete($mbox, $curmsg); $curmsg++; } } imap_expunge($mbox); imap_close($mbox); } |
||
Časová prodleva: 15 let
|
0