本文整理汇总了PHP中Support::insertEmail方法的典型用法代码示例。如果您正苦于以下问题:PHP Support::insertEmail方法的具体用法?PHP Support::insertEmail怎么用?PHP Support::insertEmail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Support
的用法示例。
在下文中一共展示了Support::insertEmail方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertNote
/**
* Converts a note to a draft or an email
*
* @param int $note_id The id of the note
* @param string $target What the note should be converted too (email, etc)
* @param bool $authorize_sender If $authorize_sender If the sender should be added to authorized senders list.
* @return int
*/
public static function convertNote($note_id, $target, $authorize_sender = false)
{
$issue_id = self::getIssueID($note_id);
$email_account_id = Email_Account::getEmailAccount();
$blocked_message = self::getBlockedMessage($note_id);
$unknown_user = self::getUnknownUser($note_id);
$structure = Mime_Helper::decode($blocked_message, true, true);
$body = $structure->body;
$sender_email = strtolower(Mail_Helper::getEmailAddress($structure->headers['from']));
$current_usr_id = Auth::getUserID();
if ($target == 'email') {
if (Mime_Helper::hasAttachments($structure)) {
$has_attachments = 1;
} else {
$has_attachments = 0;
}
list($blocked_message, $headers) = Mail_Helper::rewriteThreadingHeaders($issue_id, $blocked_message, @$structure->headers);
$t = array('issue_id' => $issue_id, 'ema_id' => $email_account_id, 'message_id' => @$structure->headers['message-id'], 'date' => Date_Helper::getCurrentDateGMT(), 'from' => @$structure->headers['from'], 'to' => @$structure->headers['to'], 'cc' => @$structure->headers['cc'], 'subject' => @$structure->headers['subject'], 'body' => @$body, 'full_email' => @$blocked_message, 'has_attachment' => $has_attachments, 'headers' => $headers);
// need to check for a possible customer association
if (!empty($structure->headers['from'])) {
$details = Email_Account::getDetails($email_account_id);
// check from the associated project if we need to lookup any customers by this email address
if (CRM::hasCustomerIntegration($details['ema_prj_id'])) {
$crm = CRM::getInstance($details['ema_prj_id']);
// check for any customer contact association
try {
$contact = $crm->getContactByEmail($sender_email);
$issue_contract = $crm->getContract(Issue::getContractID($issue_id));
if ($contact->canAccessContract($issue_contract)) {
$t['customer_id'] = $issue_contract->getCustomerID();
}
} catch (CRMException $e) {
}
}
}
if (empty($t['customer_id'])) {
$update_type = 'staff response';
$t['customer_id'] = null;
} else {
$update_type = 'customer action';
}
$res = Support::insertEmail($t, $structure, $sup_id);
if ($res != -1) {
Support::extractAttachments($issue_id, $structure);
// notifications about new emails are always external
$internal_only = false;
// special case when emails are bounced back, so we don't want to notify the customer about those
if (Notification::isBounceMessage($sender_email)) {
$internal_only = true;
}
Notification::notifyNewEmail($current_usr_id, $issue_id, $t, $internal_only, false, '', $sup_id);
Issue::markAsUpdated($issue_id, $update_type);
self::remove($note_id, false);
History::add($issue_id, $current_usr_id, 'note_converted_email', 'Note converted to e-mail (from: {from}) by {user}', array('from' => @$structure->headers['from'], 'user' => User::getFullName($current_usr_id)));
// now add sender as an authorized replier
if ($authorize_sender) {
Authorized_Replier::manualInsert($issue_id, @$structure->headers['from']);
}
}
return $res;
}
// save message as a draft
$res = Draft::saveEmail($issue_id, $structure->headers['to'], $structure->headers['cc'], $structure->headers['subject'], $body, false, $unknown_user);
// remove the note, if the draft was created successfully
if ($res) {
self::remove($note_id, false);
$usr_id = $current_usr_id;
History::add($issue_id, $usr_id, 'note_converted_draft', 'Note converted to draft (from: {from}) by {user}', array('from' => @$structure->headers['from'], 'user' => User::getFullName($current_usr_id)));
}
return $res;
}
示例2: close
/**
* Method used to close off an issue.
*
* @param integer $usr_id The user ID
* @param integer $issue_id The issue ID
* @param bool $send_notification Whether to send a notification about this action or not
* @param integer $resolution_id The resolution ID
* @param integer $status_id The status ID
* @param string $reason The reason for closing this issue
* @param string $send_notification_to Who this notification should be sent too
* @return integer 1 if the update worked, -1 otherwise
*/
public static function close($usr_id, $issue_id, $send_notification, $resolution_id, $status_id, $reason, $send_notification_to = 'internal')
{
$usr_id = (int) $usr_id;
$issue_id = (int) $issue_id;
$resolution_id = (int) $resolution_id;
$status_id = (int) $status_id;
$params = array('iss_updated_date' => Date_Helper::getCurrentDateGMT(), 'iss_last_public_action_date' => Date_Helper::getCurrentDateGMT(), 'iss_last_public_action_type' => 'closed', 'iss_closed_date' => Date_Helper::getCurrentDateGMT(), 'iss_sta_id' => $status_id);
if (!empty($resolution_id)) {
$params['iss_res_id'] = $resolution_id;
}
$stmt = 'UPDATE {{%issue}} SET ' . DB_Helper::buildSet($params) . ' WHERE iss_id=?';
$params[] = $issue_id;
try {
DB_Helper::getInstance()->query($stmt, $params);
} catch (DbException $e) {
return -1;
}
$prj_id = self::getProjectID($issue_id);
// record the change
History::add($issue_id, $usr_id, 'issue_closed', "Issue updated to status '{status}' by {user}", array('status' => Status::getStatusTitle($status_id), 'user' => User::getFullName($usr_id)));
if ($send_notification_to == 'all') {
$from = User::getFromHeader($usr_id);
$message_id = User::getFromHeader($usr_id);
$full_email = Support::buildFullHeaders($issue_id, $message_id, $from, '', '', 'Issue closed comments', $reason, '');
$structure = Mime_Helper::decode($full_email, true, false);
$email = array('ema_id' => Email_Account::getEmailAccount(self::getProjectID($issue_id)), 'issue_id' => $issue_id, 'message_id' => $message_id, 'date' => Date_Helper::getCurrentDateGMT(), 'subject' => 'Issue closed comments', 'from' => $from, 'has_attachment' => 0, 'body' => $reason, 'full_email' => $full_email, 'headers' => $structure->headers);
$sup_id = null;
Support::insertEmail($email, $structure, $sup_id, true);
$ids = $sup_id;
} else {
// add note with the reason to close the issue
$_POST['title'] = 'Issue closed comments';
$_POST['note'] = $reason;
Note::insertFromPost($usr_id, $issue_id, false, true, true, $send_notification);
$ids = false;
}
if ($send_notification) {
if (CRM::hasCustomerIntegration($prj_id)) {
$crm = CRM::getInstance($prj_id);
// send a special confirmation email when customer issues are closed
$stmt = 'SELECT
iss_customer_contact_id
FROM
{{%issue}}
WHERE
iss_id=?';
$customer_contact_id = DB_Helper::getInstance()->getOne($stmt, array($issue_id));
if (!empty($customer_contact_id)) {
try {
$contact = $crm->getContact($customer_contact_id);
$contact->notifyIssueClosed($issue_id, $reason);
} catch (CRMException $e) {
}
}
}
// send notifications for the issue being closed
Notification::notify($issue_id, 'closed', $ids);
}
Workflow::handleIssueClosed($prj_id, $issue_id, $send_notification, $resolution_id, $status_id, $reason, $usr_id);
return 1;
}
示例3: sendEmail
//.........这里部分代码省略.........
$HTTP_POST_VARS['title'] = $HTTP_POST_VARS["subject"];
$HTTP_POST_VARS['note'] = Mail_API::getCannedBlockedMsgExplanation() . $HTTP_POST_VARS["message"];
Note::insert(Auth::getUserID(), $HTTP_POST_VARS["issue_id"]);
Workflow::handleBlockedEmail(Issue::getProjectID($HTTP_POST_VARS['issue_id']), $HTTP_POST_VARS['issue_id'], $HTTP_POST_VARS, 'web');
return 1;
}
}
// only send a direct email if the user doesn't want to add the Cc'ed people to the notification list
if (@$HTTP_POST_VARS['add_unknown'] == 'yes') {
if (!empty($HTTP_POST_VARS['issue_id'])) {
// add the recipients to the notification list of the associated issue
$recipients = array($HTTP_POST_VARS['to']);
$recipients = array_merge($recipients, Support::getRecipientsCC($HTTP_POST_VARS['cc']));
for ($i = 0; $i < count($recipients); $i++) {
if (!empty($recipients[$i]) && !Notification::isIssueRoutingSender($HTTP_POST_VARS["issue_id"], $recipients[$i])) {
Notification::subscribeEmail(Auth::getUserID(), $HTTP_POST_VARS["issue_id"], Mail_API::getEmailAddress($recipients[$i]), array('emails'));
}
}
}
} else {
// Usually when sending out emails associated to an issue, we would
// simply insert the email in the table and call the Notification::notifyNewEmail() method,
// but on this case we need to actually send the email to the recipients that are not
// already in the notification list for the associated issue, if any.
// In the case of replying to an email that is not yet associated with an issue, then
// we are always directly sending the email, without using any notification list
// functionality.
if (!empty($HTTP_POST_VARS['issue_id'])) {
// send direct emails only to the unknown addresses, and leave the rest to be
// catched by the notification list
$from = Notification::getFixedFromHeader($HTTP_POST_VARS['issue_id'], $HTTP_POST_VARS['from'], 'issue');
// build the list of unknown recipients
if (!empty($HTTP_POST_VARS['to'])) {
$recipients = array($HTTP_POST_VARS['to']);
$recipients = array_merge($recipients, Support::getRecipientsCC($HTTP_POST_VARS['cc']));
} else {
$recipients = Support::getRecipientsCC($HTTP_POST_VARS['cc']);
}
$unknowns = array();
for ($i = 0; $i < count($recipients); $i++) {
if (!Notification::isSubscribedToEmails($HTTP_POST_VARS['issue_id'], $recipients[$i])) {
$unknowns[] = $recipients[$i];
}
}
if (count($unknowns) > 0) {
$to = array_shift($unknowns);
$cc = implode('; ', $unknowns);
// send direct emails
Support::sendDirectEmail($HTTP_POST_VARS['issue_id'], $from, $to, $cc, $HTTP_POST_VARS['subject'], $HTTP_POST_VARS['message'], $message_id, $sender_usr_id);
}
} else {
// send direct emails to all recipients, since we don't have an associated issue
$project_info = Project::getOutgoingSenderAddress(Auth::getCurrentProject());
// use the project-related outgoing email address, if there is one
if (!empty($project_info['email'])) {
$from = Mail_API::getFormattedName(User::getFullName(Auth::getUserID()), $project_info['email']);
} else {
// otherwise, use the real email address for the current user
$from = User::getFromHeader(Auth::getUserID());
}
// send direct emails
Support::sendDirectEmail($HTTP_POST_VARS['issue_id'], $from, $HTTP_POST_VARS['to'], $HTTP_POST_VARS['cc'], $HTTP_POST_VARS['subject'], $HTTP_POST_VARS['message'], $message_id);
}
}
$t = array('customer_id' => 'NULL', 'issue_id' => $HTTP_POST_VARS["issue_id"] ? $HTTP_POST_VARS["issue_id"] : 0, 'ema_id' => $HTTP_POST_VARS['ema_id'], 'message_id' => $message_id, 'date' => Date_API::getCurrentDateGMT(), 'from' => $HTTP_POST_VARS['from'], 'to' => $HTTP_POST_VARS['to'], 'cc' => @$HTTP_POST_VARS['cc'], 'subject' => @$HTTP_POST_VARS['subject'], 'body' => $HTTP_POST_VARS['message'], 'full_email' => $full_email, 'has_attachment' => 0);
// associate this new email with a customer, if appropriate
if (Auth::getCurrentRole() == User::getRoleID('Customer')) {
$customer_id = User::getCustomerID(Auth::getUserID());
if (!empty($customer_id) && $customer_id != -1) {
$t['customer_id'] = $customer_id;
}
}
$structure = Mime_Helper::decode($full_email, true, false);
$t['headers'] = $structure->headers;
$res = Support::insertEmail($t, $structure, $sup_id);
if (!empty($HTTP_POST_VARS["issue_id"])) {
// need to send a notification
Notification::notifyNewEmail(Auth::getUserID(), $HTTP_POST_VARS["issue_id"], $t, $internal_only, false, $type, $sup_id);
// mark this issue as updated
if (!empty($t['customer_id']) && $t['customer_id'] != 'NULL') {
Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'customer action');
} else {
if (!empty($sender_usr_id) && User::getRoleByUser($sender_usr_id, Issue::getProjectID($HTTP_POST_VARS['issue_id'])) > User::getRoleID('Customer')) {
Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'staff response');
} else {
Issue::markAsUpdated($HTTP_POST_VARS["issue_id"], 'user response');
}
}
// save a history entry for this
History::add($HTTP_POST_VARS["issue_id"], Auth::getUserID(), History::getTypeID('email_sent'), 'Outgoing email sent by ' . User::getFullName(Auth::getUserID()));
// also update the last_response_date field for the associated issue
if (Auth::getCurrentRole() > User::getRoleID('Customer')) {
$stmt = "UPDATE\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n SET\n iss_last_response_date='" . Date_API::getCurrentDateGMT() . "'\n WHERE\n iss_id=" . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]);
$GLOBALS["db_api"]->dbh->query($stmt);
$stmt = "UPDATE\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n SET\n iss_first_response_date='" . Date_API::getCurrentDateGMT() . "'\n WHERE\n iss_first_response_date IS NULL AND\n iss_id=" . Misc::escapeInteger($HTTP_POST_VARS["issue_id"]);
$GLOBALS["db_api"]->dbh->query($stmt);
}
}
return 1;
}
示例4: close
/**
* Method used to close off an issue.
*
* @access public
* @param integer $usr_id The user ID
* @param integer $issue_id The issue ID
* @param bool $send_notification Whether to send a notification about this action or not
* @param integer $resolution_id The resolution ID
* @param integer $status_id The status ID
* @param string $reason The reason for closing this issue
* @param string $send_notification_to Who this notification should be sent too
* @return integer 1 if the update worked, -1 otherwise
*/
function close($usr_id, $issue_id, $send_notification, $resolution_id, $status_id, $reason, $send_notification_to = 'internal')
{
global $HTTP_POST_VARS;
$usr_id = Misc::escapeInteger($usr_id);
$issue_id = Misc::escapeInteger($issue_id);
$resolution_id = Misc::escapeInteger($resolution_id);
$status_id = Misc::escapeInteger($status_id);
$stmt = "UPDATE\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n SET\n iss_updated_date='" . Date_API::getCurrentDateGMT() . "',\n iss_last_public_action_date='" . Date_API::getCurrentDateGMT() . "',\n iss_last_public_action_type='closed',\n iss_closed_date='" . Date_API::getCurrentDateGMT() . "',\n";
if (!empty($resolution_id)) {
$stmt .= "iss_res_id={$resolution_id},\n";
}
$stmt .= "iss_sta_id={$status_id}\n WHERE\n iss_id={$issue_id}";
$res = $GLOBALS["db_api"]->dbh->query($stmt);
if (PEAR::isError($res)) {
Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
return -1;
} else {
$prj_id = Issue::getProjectID($issue_id);
// record the change
History::add($issue_id, $usr_id, History::getTypeID('issue_closed'), "Issue updated to status '" . Status::getStatusTitle($status_id) . "' by " . User::getFullName($usr_id));
if ($send_notification_to == 'all') {
$from = User::getFromHeader($usr_id);
$message_id = User::getFromHeader($usr_id);
$full_email = Support::buildFullHeaders($issue_id, $message_id, $from, '', '', 'Issue closed comments', $reason, '');
$structure = Mime_Helper::decode($full_email, true, false);
$email = array('ema_id' => Email_Account::getEmailAccount(), 'issue_id' => $issue_id, 'message_id' => $message_id, 'date' => Date_API::getCurrentDateGMT(), 'subject' => 'Issue closed comments', 'from' => $from, 'has_attachment' => 0, 'body' => $reason, 'full_email' => $full_email, 'headers' => $structure->headers);
Support::insertEmail($email, $structure, $sup_id, true);
$ids = $sup_id;
} else {
// add note with the reason to close the issue
$HTTP_POST_VARS['title'] = 'Issue closed comments';
$HTTP_POST_VARS["note"] = $reason;
Note::insert($usr_id, $issue_id, false, true, true);
$ids = false;
}
if ($send_notification) {
if (Customer::hasCustomerIntegration($prj_id)) {
// send a special confirmation email when customer issues are closed
$stmt = "SELECT\n iss_customer_contact_id\n FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n WHERE\n iss_id={$issue_id}";
$customer_contact_id = $GLOBALS["db_api"]->dbh->getOne($stmt);
if (!empty($customer_contact_id)) {
Customer::notifyIssueClosed($prj_id, $issue_id, $customer_contact_id);
}
}
// send notifications for the issue being closed
Notification::notify($issue_id, 'closed', $ids);
}
Workflow::handleIssueClosed($prj_id, $issue_id, $send_notification, $resolution_id, $status_id, $reason);
return 1;
}
}
示例5: route_emails
//.........这里部分代码省略.........
}
$issue_prj_id = Issue::getProjectID($issue_id);
if (empty($issue_prj_id)) {
return array(self::EX_DATAERR, ev_gettext('Error: The routed email had no associated Eventum issue ID or had an invalid recipient address.') . "\n");
}
$email_account_id = Email_Account::getEmailAccount($issue_prj_id);
if (empty($email_account_id)) {
return array(self::EX_CONFIG, ev_gettext('Error: Please provide the email account ID.') . "\n");
}
$body = $structure->body;
// hack for clients that set more then one from header
if (is_array($structure->headers['from'])) {
$structure->headers['from'] = $structure->headers['from'][0];
}
// associate the email to the issue
$parts = array();
Mime_Helper::parse_output($structure, $parts);
// get the sender's email address
$sender_email = strtolower(Mail_Helper::getEmailAddress($structure->headers['from']));
// strip out the warning message sent to staff users
if ($setup['email_routing']['status'] == 'enabled' && $setup['email_routing']['warning']['status'] == 'enabled') {
$full_message = Mail_Helper::stripWarningMessage($full_message);
$body = Mail_Helper::stripWarningMessage($body);
}
$prj_id = Issue::getProjectID($issue_id);
AuthCookie::setAuthCookie(APP_SYSTEM_USER_ID);
AuthCookie::setProjectCookie($prj_id);
if (Mime_Helper::hasAttachments($structure)) {
$has_attachments = 1;
} else {
$has_attachments = 0;
}
// remove certain CC addresses
if (!empty($structure->headers['cc']) && $setup['smtp']['save_outgoing_email'] == 'yes') {
$ccs = explode(',', @$structure->headers['cc']);
foreach ($ccs as $i => $address) {
if (Mail_Helper::getEmailAddress($address) == $setup['smtp']['save_address']) {
unset($ccs[$i]);
}
}
$structure->headers['cc'] = implode(', ', $ccs);
}
// Remove excess Re's
$structure->headers['subject'] = Mail_Helper::removeExcessRe(@$structure->headers['subject'], true);
$t = array('issue_id' => $issue_id, 'ema_id' => $email_account_id, 'message_id' => @$structure->headers['message-id'], 'date' => Date_Helper::getCurrentDateGMT(), 'from' => @$structure->headers['from'], 'to' => @$structure->headers['to'], 'cc' => @$structure->headers['cc'], 'subject' => @$structure->headers['subject'], 'body' => @$body, 'full_email' => @$full_message, 'has_attachment' => $has_attachments, 'headers' => @$structure->headers);
// automatically associate this incoming email with a customer
if (CRM::hasCustomerIntegration($prj_id)) {
$crm = CRM::getInstance($prj_id);
if (!empty($structure->headers['from'])) {
try {
$contact = $crm->getContactByEmail($sender_email);
$issue_contract = $crm->getContract(Issue::getContractID($issue_id));
if ($contact->canAccessContract($issue_contract)) {
$t['customer_id'] = $issue_contract->getCustomerID();
}
} catch (CRMException $e) {
}
}
}
if (empty($t['customer_id'])) {
$t['customer_id'] = null;
}
if (Support::blockEmailIfNeeded($t)) {
return true;
}
// re-write Threading headers if needed
list($t['full_email'], $t['headers']) = Mail_Helper::rewriteThreadingHeaders($t['issue_id'], $t['full_email'], $t['headers'], 'email');
$res = Support::insertEmail($t, $structure, $sup_id);
if ($res != -1) {
Support::extractAttachments($issue_id, $structure);
// notifications about new emails are always external
$internal_only = false;
$assignee_only = false;
// special case when emails are bounced back, so we don't want a notification to customers about those
if (Notification::isBounceMessage($sender_email)) {
// broadcast this email only to the assignees for this issue
$internal_only = true;
$assignee_only = true;
}
Notification::notifyNewEmail(Auth::getUserID(), $issue_id, $t, $internal_only, $assignee_only, '', $sup_id);
// try to get usr_id of sender, if not, use system account
$usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($structure->headers['from']));
if (!$usr_id) {
$usr_id = APP_SYSTEM_USER_ID;
}
// mark this issue as updated
if (!empty($t['customer_id']) && $t['customer_id'] != null) {
Issue::markAsUpdated($issue_id, 'customer action');
} else {
if (!empty($usr_id) && $usr_id != APP_SYSTEM_USER_ID && User::getRoleByUser($usr_id, $prj_id) > User::ROLE_CUSTOMER) {
Issue::markAsUpdated($issue_id, 'staff response');
} else {
Issue::markAsUpdated($issue_id, 'user response');
}
}
// log routed email
History::add($issue_id, $usr_id, 'email_routed', 'Email routed from {from}', array('from' => $structure->headers['from']));
}
return true;
}
示例6: route_emails
//.........这里部分代码省略.........
$issue_prj_id = Issue::getProjectID($issue_id);
if (empty($issue_prj_id)) {
return array(65, "Error: The routed email had no associated Eventum issue ID or had an invalid recipient address.\n");
}
$email_account_id = Email_Account::getEmailAccount($issue_prj_id);
}
if (empty($email_account_id)) {
return array(78, "Error: Please provide the email account ID.\n");
}
$body = Mime_Helper::getMessageBody($structure);
// hack for clients that set more then one from header
if (is_array($structure->headers['from'])) {
$structure->headers['from'] = $structure->headers['from'][0];
}
// associate the email to the issue
$parts = array();
Mime_Helper::parse_output($structure, $parts);
// get the sender's email address
$sender_email = strtolower(Mail_API::getEmailAddress($structure->headers['from']));
// strip out the warning message sent to staff users
if ($setup['email_routing']['status'] == 'enabled' && $setup['email_routing']['warning']['status'] == 'enabled') {
$full_message = Mail_API::stripWarningMessage($full_message);
$body = Mail_API::stripWarningMessage($body);
}
$prj_id = Issue::getProjectID($issue_id);
Auth::createFakeCookie(APP_SYSTEM_USER_ID, $prj_id);
$staff_emails = Project::getUserEmailAssocList($prj_id, 'active', User::getRoleID('Customer'));
$staff_emails = array_map('strtolower', $staff_emails);
// only allow staff users to use the magic cookie
if (!in_array($sender_email, array_values($staff_emails))) {
$has_magic_cookie = false;
}
if (Mime_Helper::hasAttachments($full_message)) {
$has_attachments = 1;
} else {
$has_attachments = 0;
}
// remove certain CC addresses
if (!empty($structure->headers['cc']) && @$setup['smtp']['save_outgoing_email'] == 'yes') {
$ccs = explode(",", @$structure->headers['cc']);
for ($i = 0; $i < count($ccs); $i++) {
if (Mail_API::getEmailAddress($ccs[$i]) == $setup['smtp']['save_address']) {
unset($ccs[$i]);
}
}
@($structure->headers['cc'] = join(', ', $ccs));
}
// Remove excess Re's
@($structure->headers['subject'] = Mail_API::removeExcessRe(@$structure->headers['subject'], true));
$t = array('issue_id' => $issue_id, 'ema_id' => $email_account_id, 'message_id' => @$structure->headers['message-id'], 'date' => Date_API::getCurrentDateGMT(), 'from' => @$structure->headers['from'], 'to' => @$structure->headers['to'], 'cc' => @$structure->headers['cc'], 'subject' => @$structure->headers['subject'], 'body' => @$body, 'full_email' => @$full_message, 'has_attachment' => $has_attachments, 'headers' => @$structure->headers);
// automatically associate this incoming email with a customer
if (Customer::hasCustomerIntegration($prj_id)) {
if (!empty($structure->headers['from'])) {
list($customer_id, ) = Customer::getCustomerIDByEmails($prj_id, array($sender_email));
if (!empty($customer_id)) {
$t['customer_id'] = $customer_id;
}
}
}
if (empty($t['customer_id'])) {
$t['customer_id'] = "NULL";
}
if (!$has_magic_cookie && Support::blockEmailIfNeeded($t)) {
return true;
}
// re-write Threading headers if needed
list($t['full_email'], $t['headers']) = Mail_API::rewriteThreadingHeaders($t['issue_id'], $t['full_email'], $t['headers'], "email");
$res = Support::insertEmail($t, $structure, $sup_id);
if ($res != -1) {
Support::extractAttachments($issue_id, $full_message);
// notifications about new emails are always external
$internal_only = false;
$assignee_only = false;
// special case when emails are bounced back, so we don't want a notification to customers about those
if (Notification::isBounceMessage($sender_email)) {
// broadcast this email only to the assignees for this issue
$internal_only = true;
$assignee_only = true;
}
Notification::notifyNewEmail(Auth::getUserID(), $issue_id, $t, $internal_only, $assignee_only, '', $sup_id);
// try to get usr_id of sender, if not, use system account
$usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($structure->headers['from']));
if (!$usr_id) {
$usr_id = APP_SYSTEM_USER_ID;
}
// mark this issue as updated
if (!empty($t['customer_id']) && $t['customer_id'] != 'NULL') {
Issue::markAsUpdated($issue_id, 'customer action');
} else {
if (!empty($usr_id) && User::getRoleByUser($usr_id, $prj_id) > User::getRoleID('Customer')) {
Issue::markAsUpdated($issue_id, 'staff response');
} else {
Issue::markAsUpdated($issue_id, 'user response');
}
}
// log routed email
History::add($issue_id, $usr_id, History::getTypeID('email_routed'), "Email routed from " . $structure->headers['from']);
}
return true;
}