/** * Method used to get the support email entry details. * * @access public * @param integer $ema_id The support email account ID * @param integer $sup_id The support email ID * @return array The email entry details */ function getEmailDetails($ema_id, $sup_id) { $stmt = "SELECT\n " . APP_TABLE_PREFIX . "support_email.*,\n " . APP_TABLE_PREFIX . "support_email_body.*\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email,\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email_body\n WHERE\n sup_id=seb_sup_id AND\n sup_id=" . Misc::escapeInteger($sup_id) . " AND\n sup_ema_id=" . Misc::escapeInteger($ema_id); $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return ""; } else { // gotta parse MIME based emails now $output = Mime_Helper::decode($res["seb_full_email"], true); $res["message"] = Mime_Helper::getMessageBody($output); // XXX: check which code relies on this var $res["attachments"] = Mime_Helper::getAttachmentCIDs($res["seb_full_email"]); $res["timestamp"] = Date_API::getUnixTimestamp($res['sup_date'], 'GMT'); $res["sup_date"] = Date_API::getFormattedDate($res["sup_date"]); $res["sup_subject"] = Mime_Helper::fixEncoding($res["sup_subject"]); // remove extra 'Re: ' from subject $res['reply_subject'] = Mail_API::removeExcessRe('Re: ' . $res["sup_subject"], true); $res["sup_from"] = Mime_Helper::fixEncoding($res["sup_from"]); $res["sup_to"] = Mime_Helper::fixEncoding($res["sup_to"]); if (!empty($res['sup_iss_id'])) { $res['reply_subject'] = Mail_API::formatSubject($res['sup_iss_id'], $res['reply_subject']); } return $res; } }
/** * Method used to forward the new email to the list of subscribers. * * @access public * @param integer $user_id The user ID of the person performing this action * @param integer $issue_id The issue ID * @param array $message An array containing the email * @param boolean $internal_only Whether the email should only be redirected to internal users or not * @param boolean $assignee_only Whether the email should only be sent to the assignee * @param boolean $type The type of email this is * @param integer $sup_id the ID of this email * @return void */ function notifyNewEmail($usr_id, $issue_id, $message, $internal_only = FALSE, $assignee_only = FALSE, $type = '', $sup_id = false) { $full_message = $message['full_email']; $sender = $message['from']; $sender_email = strtolower(Mail_API::getEmailAddress($sender)); // get ID of whoever is sending this. $sender_usr_id = User::getUserIDByEmail($sender_email); if (empty($sender_usr_id)) { $sender_usr_id = false; } // automatically subscribe this sender to email notifications on this issue $subscribed_emails = Notification::getSubscribedEmails($issue_id, 'emails'); $subscribed_emails = array_map('strtolower', $subscribed_emails); if (!Notification::isIssueRoutingSender($issue_id, $sender) && !Notification::isBounceMessage($sender_email) && !in_array($sender_email, $subscribed_emails)) { $actions = array('emails'); Notification::subscribeEmail($usr_id, $issue_id, $sender_email, $actions); } // get the subscribers $emails = array(); $users = Notification::getUsersByIssue($issue_id, 'emails'); for ($i = 0; $i < count($users); $i++) { if (empty($users[$i]["sub_usr_id"])) { if ($internal_only == false) { $email = $users[$i]["sub_email"]; } } else { // if we are only supposed to send email to internal users, check if the role is lower than standard user if ($internal_only == true && User::getRoleByUser($users[$i]["sub_usr_id"], Issue::getProjectID($issue_id)) < User::getRoleID('standard user')) { continue; } // check if we are only supposed to send email to the assignees if ($internal_only == true && $assignee_only == true) { $assignee_usr_ids = Issue::getAssignedUserIDs($issue_id); if (!in_array($users[$i]["sub_usr_id"], $assignee_usr_ids)) { continue; } } $email = User::getFromHeader($users[$i]["sub_usr_id"]); } if (!empty($email)) { // don't send the email to the same person who sent it if (strtolower(Mail_API::getEmailAddress($email)) == $sender_email) { continue; } $emails[] = $email; } } if (count($emails) == 0) { return; } $setup = Setup::load(); // change the sender of the message to {prefix}{issue_id}@{host} // - keep everything else in the message, except 'From:', 'Sender:', 'To:', 'Cc:' // make 'Joe Blow <*****@*****.**>' become 'Joe Blow [CSC] <*****@*****.**>' $from = Notification::getFixedFromHeader($issue_id, $sender, 'issue'); list($_headers, $body) = Mime_Helper::splitBodyHeader($full_message); // strip any 'Received:' headers $_headers = Mail_API::stripHeaders($_headers); $header_names = Mime_Helper::getHeaderNames($_headers); // we don't want to keep the (B)Cc list for an eventum-based email $ignore_headers = array('to', 'cc', 'bcc'); $headers = array(); // build the headers array required by the smtp library foreach ($message['headers'] as $header_name => $value) { if (in_array(strtolower($header_name), $ignore_headers) || !in_array($header_name, array_keys($header_names)) || strstr($header_name, ' ')) { continue; } elseif ($header_name == 'from') { $headers['From'] = $from; } else { if (is_array($value)) { $value = implode("; ", $value); } $headers[$header_names[$header_name]] = $value; } } $headers["Subject"] = Mail_API::formatSubject($issue_id, $headers['Subject']); if (empty($type)) { if (User::getRoleByUser($usr_id, Issue::getProjectID($issue_id)) == User::getRoleID("Customer")) { $type = 'customer_email'; } else { $type = 'other_email'; } } @(include_once APP_PEAR_PATH . 'Mail/mime.php'); foreach ($emails as $to) { $recipient_usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($to)); $to = MIME_Helper::encodeAddress($to); // add the warning message about replies being blocked or not $fixed_body = Mail_API::addWarningMessage($issue_id, $to, $body); $headers['To'] = $to; $mime = new Mail_mime("\r\n"); $hdrs = $mime->headers($headers); Mail_Queue::add($to, $hdrs, $fixed_body, 1, $issue_id, $type, $sender_usr_id, $sup_id); } }