Exemple #1
0
 /**
  * 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;
 }
<?php

/**
 * Decode note bodies again which have failed to decode unicode html entities
 */
// notes that need to be decoded
$res = $db->getAll('select not_id, not_iss_id, not_is_blocked, not_created_date, not_note, not_full_message from {{%note}} where not_note like ?', array('%&#x00%'));
$render_diff = function ($old, $new) {
    $diff = new Text_Diff(explode(PHP_EOL, $old), explode(PHP_EOL, $new));
    $renderer = new Text_Diff_Renderer_unified();
    return $renderer->render($diff);
};
$now = Date_Helper::getCurrentDateGMT();
foreach ($res as $i => $row) {
    $email = Mime_Helper::decode($row['not_full_message'], true);
    $note = trim($email->body);
    if ($row['not_is_blocked']) {
        $note = Mail_Helper::getCannedBlockedMsgExplanation() . $note;
    }
    $diff = $render_diff($row['not_note'], $note);
    echo "--- issue #{$row['not_iss_id']} {$row['not_created_date']} GMT\n";
    echo "+++ issue #{$row['not_iss_id']} {$now} GMT\n";
    echo $diff;
    $db->query('UPDATE {{%note}} ' . 'SET not_note=? ' . 'WHERE not_id=?', array($note, $row['not_id']));
}
echo count($res), " notes updated\n";