Beispiel #1
0
 function find_email($debug = false, $get_blobs = false, $ignore_date = false)
 {
     $info = inbox::get_mail_info();
     $mailbox = $this->get_value("commentMaster") . $this->get_value("commentMasterID");
     $mail = new email_receive($info);
     $mail->open_mailbox(config::get_config_item("allocEmailFolder") . "/" . $mailbox, OP_HALFOPEN + OP_READONLY);
     $mail->check_mail();
     $msg_nums = $mail->get_all_email_msg_uids();
     $debug and print "<hr><br><b>find_email(): " . date("Y-m-d H:i:s") . " found " . count($msg_nums) . " emails for mailbox: " . $mailbox . "</b>";
     // fetch and parse email
     foreach ((array) $msg_nums as $num) {
         $debug and print "<hr><br>Examining message number: " . $num;
         unset($mimebits);
         // this will stream output
         $mail->set_msg($num);
         $mail->get_msg_header();
         $text = $mail->fetch_mail_text();
         list($from1, $e1n) = parse_email_address($mail->mail_headers["from"]);
         list($from2, $e2n) = parse_email_address($this->get_value("commentCreatedUserText"));
         if (!$from2 && $this->get_value("commentCreatedUser")) {
             $p = new person();
             $p->set_id($this->get_value("commentCreatedUser"));
             $p->select();
             $from2 = $p->get_value("emailAddress");
         }
         if (!$from2 && $this->get_value("commentCreatedUserClientContactID")) {
             $p = new clientContact();
             $p->set_id($this->get_value("commentCreatedUserClientContactID"));
             $p->select();
             $from2 = $p->get_value("clientContactEmail");
         }
         $text1 = str_replace(array("\\s", "\n", "\r"), "", trim($text));
         $text2 = str_replace(array("\\s", "\n", "\r"), "", trim($this->get_value("comment")));
         $date = format_date("U", $this->get_value("commentCreatedTime"));
         $date1 = strtotime($mail->mail_headers["date"]) - 300;
         $date3 = strtotime($mail->mail_headers["date"]) + 300;
         similar_text($text1, $text2, $percent);
         if ($percent >= 99 && ($from1 == $from2 || !$from2 || same_email_address($from1, config::get_config_item("AllocFromEmailAddress"))) && ($date > $date1 && $date < $date3 || $ignore_date)) {
             $debug and print "<br><b style='color:green'>Found you! Msg no: " . $num . " in mailbox: " . $mailbox . " for commentID: " . $this->get_id() . "</b>";
             foreach ((array) $mail->mail_parts as $v) {
                 $s = $v["part_object"];
                 // structure
                 $raw_data = imap_fetchbody($mail->connection, $mail->msg_uid, $v["part_number"], FT_UID | FT_PEEK);
                 $thing = $mail->decode_part($s->encoding, $raw_data);
                 $filename = $mail->get_parameter_attribute_value($s->parameters, "name");
                 $filename or $filename = $mail->get_parameter_attribute_value($s->parameters, "filename");
                 $filename or $filename = $mail->get_parameter_attribute_value($s->dparameters, "name");
                 $filename or $filename = $mail->get_parameter_attribute_value($s->dparameters, "filename");
                 $bits = array();
                 $bits["part"] = $v["part_number"];
                 $bits["name"] = $filename;
                 $bits["size"] = strlen($thing);
                 $get_blobs and $bits["blob"] = $thing;
                 $filename and $mimebits[] = $bits;
             }
             $mail->close();
             return array($mail, $text, $mimebits);
         } else {
             similar_text($text1, $text2, $percent);
             $debug and print "<br>TEXT: " . sprintf("%d", $text1 == $text2) . " (" . sprintf("%d", $percent) . "%)";
             #$debug and print "<br>Text1:<br>".$text1."<br>* * *<br>";
             #$debug and print "Text2:<br>".$text2."<br>+ + +</br>";
             $debug and print "<br>FROM: " . sprintf("%d", $from1 == $from2 || !$from2 || same_email_address($from1, config::get_config_item("AllocFromEmailAddress")));
             $debug and print " From1: " . page::htmlentities($from1);
             $debug and print " From2: " . page::htmlentities($from2);
             $debug and print "<br>DATE: " . sprintf("%d", $date > $date1 && $date < $date3) . " (" . date("Y-m-d H:i:s", $date) . " | " . date("Y-m-d H:i:s", $date1) . " | " . date("Y-m-d H:i:s", $date3) . ")";
             $debug and print "<br>";
         }
     }
     $mail->close();
     return array(false, false, false);
 }