示例#1
0
$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
                $from_staff = inbox::change_current_user($email_receive->mail_headers["from"]);
                if ($from_staff) {
                    inbox::convert_email_to_new_task($email_receive, true);
                } else {
                    $email_receive->mark_seen();
                    // mark it seen so we don't poll for it again
                    alloc_error("Could not create a task from this email. Email was not sent by a staff member. Email resides in INBOX.");
                }
                // Else if we have a key, append to comment
            } else {
                // Skip over emails that are from alloc. These emails are kept only for
                // posterity and should not be parsed and downloaded and re-emailed etc.
                if (same_email_address($email_receive->mail_headers["from"], ALLOC_DEFAULT_FROM_ADDRESS)) {
                    $email_receive->mark_seen();
                    $email_receive->archive();
                } else {
示例#2
0
 function convert_email_to_new_task($email_receive, $change_user = false)
 {
     global $TPL;
     $current_user =& singleton("current_user");
     $orig_current_user =& $current_user;
     if ($change_user) {
         inbox::change_current_user($email_receive->mail_headers["from"]);
         $current_user =& singleton("current_user");
         if (is_object($current_user) && method_exists($current_user, "get_id") && $current_user->get_id()) {
             $personID = $current_user->get_id();
         }
     }
     $email_receive->save_email();
     // Subject line is name, email body is body
     $task = new task();
     $task->set_value("taskName", $email_receive->mail_headers["subject"]);
     $task->set_value("taskDescription", $email_receive->mail_text);
     $task->set_value("priority", "3");
     $task->set_value("taskTypeID", "Task");
     $task->save();
     if (!$TPL["message"] && $task->get_id()) {
         $dir = ATTACHMENTS_DIR . DIRECTORY_SEPARATOR . "task" . DIRECTORY_SEPARATOR . $task->get_id();
         if (!is_dir($dir)) {
             mkdir($dir);
             foreach ((array) $email_receive->mimebits as $file) {
                 $fh = fopen($dir . DIRECTORY_SEPARATOR . $file["name"], "wb");
                 fputs($fh, $file["blob"]);
                 fclose($fh);
             }
         }
         rmdir_if_empty(ATTACHMENTS_DIR . DIRECTORY_SEPARATOR . "task" . DIRECTORY_SEPARATOR . $task->get_id());
         $msg = "Created task " . $task->get_task_link(array("prefixTaskID" => true)) . " and moved the email to the task's mail folder.";
         $mailbox = "INBOX/task" . $task->get_id();
         $email_receive->create_mailbox($mailbox) and $msg .= "\nCreated mailbox: " . $mailbox;
         $email_receive->archive($mailbox) and $msg .= "\nMoved email to " . $mailbox;
         $msg and $TPL["message_good_no_esc"][] = $msg;
         list($from_address, $from_name) = parse_email_address($email_receive->mail_headers["from"]);
         $ip["emailAddress"] = $from_address;
         $ip["name"] = $from_name;
         $ip["personID"] = $personID;
         $ip["entity"] = "task";
         $ip["entityID"] = $task->get_id();
         interestedParty::add_interested_party($ip);
     }
     // Put current_user back to normal
     $current_user =& $orig_current_user;
     singleton("current_user", $current_user);
 }