function add_comment_from_email($email_receive, $entity) { $current_user =& singleton("current_user"); $commentID = comment::add_comment($entity->classname, $entity->get_id(), $email_receive->get_converted_encoding()); $commentID or alloc_error("Unable to create an alloc comment (" . $entity->classname . ":" . $entity->get_id() . ") from email."); $comment = new comment(); $comment->set_id($commentID); $comment->select(); $comment->set_value("commentEmailUID", $email_receive->msg_uid); $comment->set_value("commentEmailMessageID", $email_receive->mail_headers["message-id"]); $comment->rename_email_attachment_dir($email_receive->dir); // Try figure out and populate the commentCreatedUser/commentCreatedUserClientContactID fields list($from_address, $from_name) = parse_email_address($email_receive->mail_headers["from"]); list($personID, $clientContactID, $from_name) = comment::get_person_and_client($from_address, $from_name, $entity->get_project_id()); $personID and $comment->set_value('commentCreatedUser', $personID); $clientContactID and $comment->set_value('commentCreatedUserClientContactID', $clientContactID); $comment->set_value("commentCreatedUserText", $email_receive->mail_headers["from"]); $comment->set_value("commentEmailMessageID", $email_receive->mail_headers["message-id"]); $comment->updateSearchIndexLater = true; $comment->skip_modified_fields = true; $comment->save(); if ($email_receive->mimebits) { comment::update_mime_parts($comment->get_id(), $email_receive->mimebits); } // CYBER-ONLY: Re-open task, if comment has been made by an external party. if (config::for_cyber() && !$comment->get_value('commentCreatedUser')) { $e = $entity->get_parent_object(); if ($e->classname == "task" && substr($e->get_value("taskStatus"), 0, 4) != "open") { $tmp = $current_user; $current_user = new person(); $personID = $e->get_value("managerID") or $personID = $e->get_value("personID") or $personID = $e->get_value("creatorID"); $current_user->load_current_user($personID); // fake identity singleton("current_user", $current_user); $e->set_value("taskStatus", "open_inprogress"); $e->save(); $current_user = $tmp; } } return $comment; }
mkdir($dir, 0777); } // Write out all of the attachments and generated files to the local filesystem foreach ((array) $files as $k => $f) { $fullpath = $dir . DIRECTORY_SEPARATOR . $f["name"]; if ($f["blob"]) { file_put_contents($fullpath, $f["blob"]); } else { if ($f["tmp_name"]) { rename($f["tmp_name"], $fullpath); } } $files[$k]["fullpath"] = $fullpath; } if ($files) { comment::update_mime_parts($commentID, $files); } // Re-email the comment out, including any attachments if (!comment::send_comment($commentID, $emailRecipients, false, $files)) { alloc_error("Email failed to send."); } foreach ((array) $files as $k => $f) { if (file_exists($f["fullpath"])) { unlink($f["fullpath"]); } } rmdir_if_empty($dir); // Re-direct browser back home $TPL["message_good"][] = $message_good; $extra .= "&sbs_link=comments"; alloc_redirect($TPL["url_alloc_" . $_REQUEST["commentMaster"]] . $_REQUEST["commentMaster"] . "ID=" . $_REQUEST["commentMasterID"] . $extra);