/** * Check if this email needs to be blocked and if so, block it. * * */ public static function blockEmailIfNeeded($email) { if (empty($email['issue_id'])) { return false; } $issue_id = $email['issue_id']; $prj_id = Issue::getProjectID($issue_id); $sender_email = strtolower(Mail_Helper::getEmailAddress($email['from'])); list($text_headers, $body) = Mime_Helper::splitHeaderBody($email['full_email']); if (Mail_Helper::isVacationAutoResponder($email['headers']) || Notification::isBounceMessage($sender_email) || !self::isAllowedToEmail($issue_id, $sender_email)) { // add the message body as a note $_POST = array('full_message' => $email['full_email'], 'title' => @$email['headers']['subject'], 'note' => Mail_Helper::getCannedBlockedMsgExplanation($issue_id) . $email['body'], 'message_id' => Mail_Helper::getMessageID($text_headers, $body)); // avoid having this type of message re-open the issue if (Mail_Helper::isVacationAutoResponder($email['headers'])) { $closing = true; $notify = false; } else { $closing = false; $notify = true; } $res = Note::insertFromPost(Auth::getUserID(), $issue_id, $email['headers']['from'], false, $closing, $notify, true); // associate the email attachments as internal-only files on this issue if ($res != -1) { self::extractAttachments($issue_id, $email['full_email'], true, $res); } $_POST['issue_id'] = $issue_id; $_POST['from'] = $sender_email; // avoid having this type of message re-open the issue if (Mail_Helper::isVacationAutoResponder($email['headers'])) { $email_type = 'vacation-autoresponder'; } else { $email_type = 'routed'; } Workflow::handleBlockedEmail($prj_id, $issue_id, $_POST, $email_type); // try to get usr_id of sender, if not, use system account $usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($email['from']), true); if (!$usr_id) { $usr_id = APP_SYSTEM_USER_ID; } History::add($issue_id, $usr_id, 'email_blocked', "Email from '{from}' blocked", array('from' => $email['from'])); return true; } return false; }