* along with allocPSA. If not, see <http://www.gnu.org/licenses/>. */ define("NO_AUTH", 1); require_once "../alloc.php"; singleton("errors_fatal", false); singleton("errors_format", "text"); singleton("errors_logged", false); singleton("errors_thrown", true); singleton("errors_haltdb", true); $nl = "<br>\n"; $info = inbox::get_mail_info(); if (!$info["host"]) { alloc_error("Email mailbox host not defined, assuming email receive function is inactive.", true); } $email_receive = new email_receive($info); $email_receive->open_mailbox(config::get_config_item("allocEmailFolder")); $email_receive->check_mail(); $num_new_emails = $email_receive->get_num_new_emails(); if ($num_new_emails > 0) { $msg_nums = $email_receive->get_new_email_msg_uids(); print $nl . date("Y-m-d H:i:s") . " Found " . count($msg_nums) . " new/unseen emails." . $nl; foreach ($msg_nums as $num) { // Errors from previous iterations shouldn't affect processing of the next email db_alloc::$stop_doing_queries = false; $email_receive->set_msg($num); $email_receive->get_msg_header(); $keys = $email_receive->get_hashes(); try { // If no keys if (!$keys) { // If email sent from a known staff member
*/ require_once "../alloc.php"; if (!have_entity_perm("config", PERM_UPDATE, $current_user, true)) { alloc_error("Permission denied.", true); } if ($_POST["test_email_gateway"]) { $info["host"] = config::get_config_item("allocEmailHost"); $info["port"] = config::get_config_item("allocEmailPort"); $info["username"] = config::get_config_item("allocEmailUsername"); $info["password"] = config::get_config_item("allocEmailPassword"); $info["protocol"] = config::get_config_item("allocEmailProtocol"); if (!$info["host"]) { alloc_error("Email mailbox host not defined, assuming email receive function is inactive."); } else { $mail = new email_receive($info, $lockfile); $mail->open_mailbox(config::get_config_item("allocEmailFolder")); $mail->check_mail(); $TPL["message_good"][] = "Connection succeeded!"; } } $db = new db_alloc(); $db->query("SELECT name,value,type FROM config"); while ($db->next_record()) { $fields_to_save[] = $db->f("name"); $types[$db->f("name")] = $db->f("type"); if ($db->f("type") == "text") { $TPL[$db->f("name")] = page::htmlentities($db->f("value")); } else { if ($db->f("type") == "array") { $TPL[$db->f("name")] = unserialize($db->f("value")); }
//e(sprintf("Found %d emails sent.",$row["sum"])); $row = $db->qr("SELECT count(*) AS sum FROM comment WHERE commentCreatedTime >= '2012-05-12 00:00:00'"); //e(sprintf("Found %d comments created.",$row["sum"])); $info["host"] = config::get_config_item("allocEmailHost"); $info["port"] = config::get_config_item("allocEmailPort"); $info["username"] = config::get_config_item("allocEmailUsername"); $info["password"] = config::get_config_item("allocEmailPassword"); $info["protocol"] = config::get_config_item("allocEmailProtocol"); $qid = $db->query("SELECT * FROM comment WHERE commentCreatedTime >= '2012-05-12 00:00:00'"); while ($row = $db->row($qid)) { // For each comment, ascertain the taskID $entity = $row["commentMaster"]; $entityID = $row["commentMasterID"]; // Use the taskID to query the mbox.taskID for all its emails $mail = new email_receive($info); $mail->open_mailbox("INBOX"); $created = $mail->create_mailbox("INBOX/" . $entity . $entityID); $created or $created = $mail->create_mailbox("INBOX." . $entity . $entityID); $opened = $mail->open_mailbox("INBOX/" . $entity . $entityID); $uids = $mail->get_all_email_msg_uids(); //e("Entity: ".$entity.$entityID." comment: ".$row["commentID"]." uids: ".print_r($uids,1)); $found = false; foreach ((array) $uids as $uid) { // If there's one that looks like the current one, forgeddaboutit list($header, $body) = $mail->get_raw_email_by_msg_uid($uid); similar_text(preg_replace("/\\s+/", "", trim($row["comment"])), preg_replace("/\\s+/", "", trim($body)), $percent); if ($percent > 97) { $found = true; #e("percent: ".$percent); #e("1-------------------"); #e($row["comment"]);
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); }
if ($from_address) { $f = $from_address; } } } return $f; } } // Tests if (basename($_SERVER["PHP_SELF"]) == "email_receive.inc.php") { define("NO_AUTH", 1); require_once "alloc.php"; //require_once("emailsettings.php"); $num = 30; $e = new email_receive($info); $e->open_mailbox("INBOX"); echo "\nNum emails: " . $e->get_num_emails(); echo "\nNew emails: " . $e->get_num_new_emails(); echo "\ncheck_mail(): " . str_replace("\n", " ", print_r($e->mail_info, 1)); echo "\nget_new_email_msg_uids(): " . str_replace("\n", " ", print_r($e->get_new_email_msg_uids(), 1)); echo "\nget_all_email_msg_uids(): " . str_replace("\n", " ", print_r($e->get_all_email_msg_uids(), 1)); //exit(); echo "\nget_emails_UIDs_search(): " . str_replace("\n", " ", print_r($e->get_emails_UIDs_search("SUBJECT alloc"), 1)); //echo "\nget_msg_header(): ".str_replace("\n"," ",print_r($e->get_msg_header($num),1)); echo "\n"; $e->set_msg($num); $e->load_structure(); echo "\nload_structure(): " . str_replace(" ", " ", print_r($e->mail_structure, 1)); echo "\nget_charset(): " . $e->get_charset(); //exit(); list($h, $b) = $e->get_raw_email_by_msg_uid($num);
* under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at * your option) any later version. * * allocPSA is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public * License for more details. * * You should have received a copy of the GNU Affero General Public License * along with allocPSA. If not, see <http://www.gnu.org/licenses/>. */ require_once "../alloc.php"; $info["host"] = config::get_config_item("allocEmailHost"); $info["port"] = config::get_config_item("allocEmailPort"); $info["username"] = config::get_config_item("allocEmailUsername"); $info["password"] = config::get_config_item("allocEmailPassword"); $info["protocol"] = config::get_config_item("allocEmailProtocol"); if (!$info["host"]) { alloc_error("Email mailbox host not defined, assuming email function is inactive.", true); } $email_receive = new email_receive($info); $email_receive->open_mailbox(config::get_config_item("allocEmailFolder"), OP_HALFOPEN | OP_READONLY); $email_receive->set_msg($_REQUEST["id"]); $new_nums = $email_receive->get_new_email_msg_uids(); in_array($_REQUEST["id"], (array) $new_nums) and $new = true; $mail_text = $email_receive->fetch_mail_text(); $new and $email_receive->set_unread(); // might have to "unread" the email, if it was new, i.e. set it back to new $email_receive->close(); echo nl2br(trim(page::htmlentities($mail_text)));
$alloc_from_addresses2[] = "*****@*****.**"; $alloc_from_addresses2[] = "*****@*****.**"; $alloc_from_addresses2[] = "*****@*****.**"; $lockfile = ATTACHMENTS_DIR . "mail.lock.patch179"; $info["host"] = config::get_config_item("allocEmailHost"); $info["port"] = config::get_config_item("allocEmailPort"); $info["username"] = config::get_config_item("allocEmailUsername"); $info["password"] = config::get_config_item("allocEmailPassword"); $info["protocol"] = config::get_config_item("allocEmailProtocol"); if (true) { // regular users probably won't need to apply this patch, so let them skip it define("FORCE_PATCH_SUCCEED_patch-00179-alla.php", 1); } else { $fp = fopen(ATTACHMENTS_DIR . "updatecommentpatch179.log", "a+"); $mail = new email_receive($info, $lockfile); $mail->open_mailbox(config::get_config_item("allocEmailFolder"), OP_HALFOPEN + OP_READONLY); $mail->check_mail(); $msg_nums = $mail->get_all_email_msg_uids(); # foreach ($msg_nums as $n) { # $n == 326 and $go = true; # $go and $remaining[] = $n; # } # unset($msg_nums); # $msg_nums = $remaining; printorlog("\n"); printorlog(date("Y-m-d H:i:s") . " Found " . count($msg_nums) . " emails."); $db = new db_alloc(); // fetch and parse email foreach ($msg_nums as $num) { // this will stream output flush();
$info["host"] = config::get_config_item("allocEmailHost"); $info["port"] = config::get_config_item("allocEmailPort"); $info["username"] = config::get_config_item("allocEmailUsername"); $info["password"] = config::get_config_item("allocEmailPassword"); $info["protocol"] = config::get_config_item("allocEmailProtocol"); if (!$info["host"]) { alloc_error("Email mailbox host not defined, assuming email fetch function is inactive.", true); } if ($_REQUEST["commentID"]) { $c = new comment(); $c->set_id($_REQUEST["commentID"]); $c->select(); $entity = $c->get_value("commentMaster"); $entityID = $c->get_value("commentMasterID"); $mail = new email_receive($info); $mail->open_mailbox(config::get_config_item("allocEmailFolder") . "/" . $entity . $entityID); if ($_REQUEST["uid"]) { header('Content-Type: text/plain; charset=utf-8'); list($h, $b) = $mail->get_raw_email_by_msg_uid($_REQUEST["uid"]); $mail->close(); echo $h . $b; exit; } //$uids = $mail->get_all_email_msg_uids(); $t = new token(); $t->select_token_by_entity_and_action($c->get_value("commentType"), $c->get_value("commentLinkID"), "add_comment_from_email"); $hash = $t->get_value("tokenHash"); // First try a messageID search if ($c->get_value("commentEmailMessageID")) { $str = sprintf('TEXT "%s"', $c->get_value("commentEmailMessageID")); $uids = $mail->get_emails_UIDs_search($str);
@apache_setenv('no-gzip', 1); @ini_set('zlib.output_compression', 0); @ini_set('implicit_flush', 1); for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); } ob_implicit_flush(1); ini_set('max_execution_time', 180000); ini_set('memory_limit', "256M"); $info["host"] = config::get_config_item("allocEmailHost"); $info["port"] = config::get_config_item("allocEmailPort"); $info["username"] = config::get_config_item("allocEmailUsername"); $info["password"] = config::get_config_item("allocEmailPassword"); $info["protocol"] = config::get_config_item("allocEmailProtocol"); $mail = new email_receive($info); $mail->open_mailbox(config::get_config_item("allocEmailFolder"), CL_EXPUNGE); $mail->check_mail(); $msg_nums = $mail->get_all_email_msg_uids(); printorlog("\n"); printorlog(date("Y-m-d H:i:s") . " Found " . count($msg_nums) . " emails."); // fetch and parse email foreach ($msg_nums as $num) { $x++; // this will stream output flush(); $mail->set_msg($num); $mail->get_msg_header($num); $keys = $mail->get_hashes(); $mailbox = hash_to_entity($keys[0]); if (!$mailbox) { printorlog("\n");
/** * Get a list of IMAP email UIDs, based on a string search * @param string $str the search string * @return array an array of email UIDs */ public function get_comment_email_uids_search($str) { if ($str) { $current_user =& singleton("current_user"); $info = $this->init_email_info(); $mail = new email_receive($info); $mail->open_mailbox(config::get_config_item("allocEmailFolder"), OP_READONLY); $rtn = $mail->get_emails_UIDs_search($str); $mail->close(); } return (array) $rtn; }
public static function get_list() { // Get list of emails $info = inbox::get_mail_info(); $email_receive = new email_receive($info); $email_receive->open_mailbox($info["folder"], OP_HALFOPEN | OP_READONLY); $email_receive->check_mail(); $new_nums = $email_receive->get_new_email_msg_uids(); $msg_nums = $email_receive->get_all_email_msg_uids(); if ($msg_nums) { foreach ($msg_nums as $num) { $row = array(); $email_receive->set_msg($num); $email_receive->get_msg_header(); $row["from"] = $email_receive->get_printable_from_address(); in_array($num, (array) $new_nums) and $row["new"] = true; $row["id"] = $num; $row["date"] = $email_receive->mail_headers["date"]; $row["subject"] = $email_receive->mail_headers["subject"]; $rows[] = $row; } } $email_receive->close(); return $rows; }