function send_comment($commentID, $emailRecipients, $email_receive = false, $files = array()) { $comment = new comment(); $comment->set_id($commentID); $comment->select(); $token = new token(); if ($comment->get_value("commentType") == "comment" && $comment->get_value("commentLinkID")) { $c = new comment(); $c->set_id($comment->get_value("commentLinkID")); $c->select(); $is_a_reply_comment = true; if ($token->select_token_by_entity_and_action("comment", $c->get_id(), "add_comment_from_email")) { $hash = $token->get_value("tokenHash"); } } if (!$hash) { if ($token->select_token_by_entity_and_action("comment", $comment->get_id(), "add_comment_from_email")) { $hash = $token->get_value("tokenHash"); } else { $hash = $comment->make_token_add_comment_from_email(); } } $rtn = $comment->send_emails($emailRecipients, $email_receive, $hash, $is_a_reply_comment, $files); if (is_array($rtn)) { $email_sent = true; list($successful_recipients, $messageid) = $rtn; } // Append success to end of the comment if ($successful_recipients) { $append_comment_text = "Email sent to: " . $successful_recipients; $message_good .= $append_comment_text; //$comment->set_value("commentEmailMessageID",$messageid); that's the outbound message-id :-( $comment->set_value("commentEmailRecipients", $successful_recipients); } $comment->skip_modified_fields = true; $comment->updateSearchIndexLater = true; $comment->save(); return $email_sent; }
function adjust_by_email_subject($email_receive, $e) { $current_user =& singleton("current_user"); $entity = $e->classname; $entityID = $e->get_id(); $subject = trim($email_receive->mail_headers["subject"]); $body = $email_receive->get_converted_encoding(); $msg_uid = $email_receive->msg_uid; list($emailAddress, $fullName) = parse_email_address($email_receive->mail_headers["from"]); list($personID, $clientContactID, $fullName) = comment::get_person_and_client($emailAddress, $fullName, $e->get_project_id()); // Load up the parent object that this comment refers to, be it task or timeSheet etc if ($entity == "comment" && $entityID) { $c = new comment(); $c->set_id($entityID); $c->select(); $object = $c->get_parent_object(); } else { if (class_exists($entity) && $entityID) { $object = new $entity(); $object->set_id($entityID); $object->select(); } } // If we're doing subject line magic, then we're only going to do it with // subject lines that have a {Key:fdsFFeSD} in them. preg_match("/\\{Key:[A-Za-z0-9]{8}\\}(.*)\\s*\$/i", $subject, $m); $commands = explode(" ", trim($m[1])); foreach ((array) $commands as $command) { $command = strtolower($command); list($command, $command2) = explode(":", $command); // for eg: duplicate:1234 // If "quiet" in the subject line, then the email/comment won't be re-emailed out again if ($command == "quiet") { $quiet = true; // To unsubscribe from this conversation } else { if ($command == "unsub" || $command == "unsubscribe") { if (interestedParty::active($entity, $entityID, $emailAddress)) { interestedParty::delete_interested_party($entity, $entityID, $emailAddress); } // To subscribe to this conversation } else { if ($command == "sub" || $command == "subscribe") { $ip = interestedParty::exists($entity, $entityID, $emailAddress); if (!$ip) { $data = array("entity" => $entity, "entityID" => $entityID, "fullName" => $fullName, "emailAddress" => $emailAddress, "personID" => $personID, "clientContactID" => $clientContactID); interestedParty::add_interested_party($data); // Else reactivate existing IP } else { if (!interestedParty::active($entity, $entityID, $emailAddress)) { $interestedParty = new interestedParty(); $interestedParty->set_id($ip["interestedPartyID"]); $interestedParty->select(); $interestedParty->set_value("interestedPartyActive", 1); $interestedParty->save(); } } // If there's a number/duration then add some time to a time sheet } else { if (is_object($current_user) && $current_user->get_id() && preg_match("/([\\.\\d]+)/i", $command, $m)) { $duration = $m[1]; if (is_numeric($duration)) { if (is_object($object) && $object->classname == "task" && $object->get_id() && $current_user->get_id()) { $timeSheet = new timeSheet(); $tsi_row = $timeSheet->add_timeSheetItem(array("taskID" => $object->get_id(), "duration" => $duration, "comment" => $body, "msg_uid" => $msg_uid, "msg_id" => $email_receive->mail_headers["message-id"], "multiplier" => 1)); $timeUnit = new timeUnit(); $units = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA"); $unitLabel = $units[$tsi_row["timeSheetItemDurationUnitID"]]; } } // Otherwise assume it's a status change } else { if (is_object($current_user) && $current_user->get_id() && $command) { if (is_object($object) && $object->get_id()) { $object->set_value("taskStatus", $command); if ($command2 && preg_match("/dup/i", $command)) { $object->set_value("duplicateTaskID", $command2); } else { if ($command2 && preg_match("/tasks/i", $command)) { $object->add_pending_tasks($command2); } } $object->save(); } } } } } } } return $quiet; }
if ($uid) { exit; } } //$lockfile = ATTACHMENTS_DIR."mail.lock.person_".$current_user->get_id(); $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");
* 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/>. */ // For use like get_attachment.php?entity=project&id=5&file=foo.bar require_once "../alloc.php"; if (isset($_GET["id"]) && $_GET["part"]) { $comment = new comment(); $comment->set_id($_GET["id"]); $comment->select() or die("Bad _GET[id]"); list($mail, $text, $mimebits) = $comment->find_email(false, true); if (!$mail) { list($mail, $text, $mimebits) = $comment->find_email(false, true, true); } if ($comment->has_attachment_permission($current_user)) { foreach ((array) $mimebits as $bit) { if ($bit["part"] == $_GET["part"]) { $thing = $bit["blob"]; $filename = $bit["name"]; break; } } header('Content-Type: ' . $mimetype); header("Content-Length: " . strlen($thing));
ob_implicit_flush(1); ini_set('max_execution_time', 180000); ini_set('memory_limit', "256M"); $db = new db_alloc(); // Loop through attachments directory $dir = ATTACHMENTS_DIR . "comment" . DIRECTORY_SEPARATOR; if (is_dir($dir)) { $handle = opendir($dir); while (false !== ($file = readdir($handle))) { clearstatcache(); if ($file == "." || $file == ".." || !is_numeric($file) || dir_is_empty($dir . $file) || !is_numeric($file)) { continue; } // Figure out which email created the comment $comment = new comment(); $comment->set_id($file); $comment->select(); echo "<br><br><hr>Examining comment " . $file; // Figure out what the mime parts are for the attachments and update comment.commentMimeParts list($email, $text, $mimebits) = $comment->find_email(true); if (!$email) { echo "<br>Couldn't find email for commentID: " . $file . "<br>"; rename($dir . $file, $dir . "fail_" . $file); } if ($mimebits) { echo "<br>Setting commentMimeParts for comment: " . $comment->get_id(); $comment->set_value("commentMimeParts", serialize($mimebits)); $comment->skip_modified_fields = true; $comment->save(); rename($dir . $file, $dir . "done_" . $file); }