//echo "<p>Plain text found ! ($sTextBody)</p>\n"; } $iPartIndex++; } // Try again but this time look for an HTML part if (!$bFound) { while ($iPartIndex < count($oStructure->parts) && !$bFound) { //echo "<p>Reading part $iPartIndex</p>\n"; if ($oStructure->parts[$iPartIndex]->ctype_primary == 'text' && $oStructure->parts[$iPartIndex]->ctype_secondary == 'html') { $sTextBody = $oStructure->parts[$iPartIndex]->body; $bFound = true; //echo "<p>HTML text found ! (".htmlentities($sTextBody, ENT_QUOTES, 'UTF-8').")</p>\n"; } $iPartIndex++; } } } // Bug: depending on the email, the email address could be found in : // email => '*****@*****.**' // name => 'john foo <*****@*****.**> $oTicket = CreateTicket($aSender['email'], $sSubject, $sTextBody); if ($oTicket != null) { // Ticket created, delete the email $oPop3->deleteMsg($index); echo "Ticket: " . $oTicket->GetName() . " created.\n"; } } $oPop3->disconnect(); ?>
function GetEmails() { global $trouble_email; /* Find out which pop accounts (categories) we have to check */ $cat_res = mysql_query("select * from tickets_categories;"); /* Check each pop accounts / categories */ if (!!$cat_res) { while ($cat_row = mysql_fetch_array($cat_res)) { $mbox = imap_open("{".$cat_row["pophost"].":110/pop3/notls}INBOX",$cat_row["popuser"],$cat_row["poppass"]) or die("can't connect: ".imap_last_error()); $curmsg = 1; while ($curmsg <= imap_num_msg($mbox)) { //print "Retrieving new message.<br>"; $body = get_part($mbox, $curmsg, "TEXT/PLAIN"); if ($body == "") $body = get_part($mbox, $curmsg, "TEXT/HTML"); // 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. $email = $head->reply_toaddress; $name = $head->fromaddress; $subject = $head->fetchsubject; //print "Subject: $subject<br>"; /* Check the subject for ticket number */ if (!ereg ("[[][#][0-9]{6}[]]", $head->fetchsubject)) { /* Seems like a new ticket, create it first */ //print "Creating a new ticket.<br>"; $ticket_id = CreateTicket($subject, $name, $email, $cat_row["id"], ""); 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>"; @mail ($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($head->fetchsubject, "[#"), 2, 6); //print "Follow up to ticket #$ticket_id<br>"; SendNotification($name, $email, "", $subject, $cat_row["id"]); } $body = ereg_replace("\n\n", "\n", $body); 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>"; mail ($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); } } }
if (value("submit") != "0" && $femail != "" && $captchaValid) { $mailstring = $headline . "\n"; $mailstring .= $body . "\n"; $mailstring .= "\n"; $mailstring .= "Name: " . $fname . "\n"; $mailstring .= "Vorname: " . $fsurname . "\n"; $mailstring .= "Strasse: " . $fstreet . "\n"; $mailstring .= "PLZ: " . $fzip . "\n"; $mailstring .= "Ort: " . $fcity . "\n"; $mailstring .= "Telefon: " . $ftel . "\n"; $mailstring .= "Fax: " . $ffax . "\n"; $mailstring .= "E-Mail: " . $femail . "\n\n"; $mailstring .= $fmessage . "\n"; $mailstring .= "\n\n"; include $c["path"] . "modules/customercare/tickets.inc.php"; $ticket = CreateTicket($fsubject, $fname . ', ' . $fsurname, $femail, $ticket_category, $fphone, "1"); if ($ticket == false) { mail($trouble_email, "{TROUBLE} {$fsubject}", "[ERROR: CreateTicket failed]\n" . $mailstring, "From: Mailing System\nReply-To: {$trouble_email}"); } else { if (!PostMessage($ticket, $mailstring)) { mail($trouble_email, "{TROUBLE} {$ticket_subject}", "[ERROR: PostMessage failed]\n" . $mailstring, "From: Mailing System\nReply-To: {$trouble_email}"); } } echo $cds->content->get("success"); } else { $body = $cds->content->get("Body"); if (strlen($body) > 0) { echo $body; br(); } if ($sma != 1) {