include_once APP_INC_PATH . "class.issue.php"; include_once APP_INC_PATH . "class.misc.php"; include_once APP_INC_PATH . "class.support.php"; include_once APP_INC_PATH . "db_access.php"; $tpl = new Template_API(); $tpl->setTemplate("view_email.tpl.html"); Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true); $email = Support::getEmailDetails($HTTP_GET_VARS["ema_id"], $HTTP_GET_VARS["id"]); $email["message"] = str_replace(" ", " ", $email["message"]); $issue_id = Support::getIssueFromEmail($HTTP_GET_VARS["id"]); if (!Issue::canAccess($issue_id, Auth::getUserID())) { $tpl->setTemplate("permission_denied.tpl.html"); $tpl->displayTemplate(); exit; } $tpl->bulkAssign(array("email" => $email, "issue_id" => $issue_id, 'extra_title' => "Email #" . $HTTP_GET_VARS['id'] . ": " . $email['sup_subject'], 'email_accounts' => Email_Account::getAssocList(array_keys(Project::getAssocList(Auth::getUserID())), true))); if (@$HTTP_GET_VARS['cat'] == 'list_emails') { $sides = Support::getListingSides($HTTP_GET_VARS["id"]); $tpl->assign(array('previous' => $sides['previous'], 'next' => $sides['next'])); } elseif (@$HTTP_GET_VARS['cat'] == 'move_email' && Auth::getCurrentRole() >= User::getRoleID("Standard User")) { $res = Support::moveEmail(@$HTTP_GET_VARS['id'], @$HTTP_GET_VARS['ema_id'], @$HTTP_GET_VARS['new_ema_id']); $tpl->assign("move_email_result", $res); $tpl->assign("current_user_prefs", Prefs::get(Auth::getUserID())); } else { $sides = Support::getIssueSides($issue_id, $HTTP_GET_VARS["id"]); $tpl->assign(array('previous' => $sides['previous'], 'next' => $sides['next'])); } // set the page charset to whatever is set on this email $charset = Mime_Helper::getCharacterSet($email['seb_full_email']); if (!empty($charset)) { header("Content-Type: text/html; charset=" . $charset);
/** * 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; }
/** * 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; }
/** * Moves an email from one account to another. * * @param integer $sup_id The ID of the message. * @param integer $current_ema_id The ID of the account the message is currently in. * @param integer $new_ema_id The ID of the account to move the message too. * @return integer -1 if there was error moving the message, 1 otherwise. */ public static function moveEmail($sup_id, $current_ema_id, $new_ema_id) { $email = self::getEmailDetails($current_ema_id, $sup_id); if (!empty($email['sup_iss_id'])) { return -1; } $info = Email_Account::getDetails($new_ema_id); $full_email = self::getFullEmail($sup_id); $structure = Mime_Helper::decode($full_email, true, true); $headers = ''; foreach ($structure->headers as $key => $value) { if (is_array($value)) { continue; } $headers .= "{$key}: {$value}\n"; } // handle auto creating issues (if needed) $should_create_array = self::createIssueFromEmail($info, $headers, $email['seb_body'], $email['timestamp'], $email['sup_from'], $email['sup_subject'], $email['sup_to'], $email['sup_cc']); $issue_id = $should_create_array['issue_id']; $customer_id = $should_create_array['customer_id']; if (empty($issue_id)) { $issue_id = 0; } if (empty($customer_id)) { $customer_id = 'NULL'; } $sql = 'UPDATE {{%support_email}} SET sup_ema_id = ?, sup_iss_id = ?, sup_customer_id = ? WHERE sup_id = ? AND sup_ema_id = ?'; $params = array($new_ema_id, $issue_id, $customer_id, $sup_id, $current_ema_id); try { DB_Helper::getInstance()->query($sql, $params); } catch (DbException $e) { return -1; } $row = array('sup_id' => $email['sup_id'], 'customer_id' => $customer_id, 'issue_id' => $issue_id, 'ema_id' => $new_ema_id, 'message_id' => $email['sup_message_id'], 'date' => $email['timestamp'], 'from' => $email['sup_from'], 'to' => $email['sup_to'], 'cc' => $email['sup_cc'], 'subject' => $email['sup_subject'], 'body' => $email['seb_body'], 'full_email' => $email['seb_full_email'], 'has_attachment' => $email['sup_has_attachment']); Workflow::handleNewEmail(self::getProjectByEmailAccount($new_ema_id), $issue_id, $structure, $row); return 1; }
if (@$HTTP_POST_VARS['cat'] == 'associate') { if ($HTTP_POST_VARS['target'] == 'email') { $res = Support::associate(Auth::getUserID(), $HTTP_POST_VARS['issue'], $HTTP_POST_VARS['item']); if ($res == 1) { Workflow::handleManualEmailAssociation(Issue::getProjectID($HTTP_POST_VARS['issue']), $HTTP_POST_VARS['issue']); } $tpl->assign("associate_result", $res); } elseif ($HTTP_POST_VARS['target'] == 'reference') { $res = Support::associateEmail(Auth::getUserID(), $HTTP_POST_VARS['issue'], $HTTP_POST_VARS['item']); if ($res == 1) { Workflow::handleManualEmailAssociation(Issue::getProjectID($HTTP_POST_VARS['issue']), $HTTP_POST_VARS['issue']); } $tpl->assign("associate_result", $res); } else { for ($i = 0; $i < count($HTTP_POST_VARS['item']); $i++) { $email = Support::getEmailDetails(Email_Account::getAccountByEmail($HTTP_POST_VARS['item'][$i]), $HTTP_POST_VARS['item'][$i]); // add the message body as a note $HTTP_POST_VARS['blocked_msg'] = $email['seb_full_email']; $HTTP_POST_VARS['title'] = $email['sup_subject']; $HTTP_POST_VARS['note'] = $email['seb_body']; // XXX: probably broken to use the current logged in user as the 'owner' of // XXX: this new note, but that's how it was already $res = Note::insert(Auth::getUserID(), $HTTP_POST_VARS['issue']); // remove the associated email if ($res) { list($HTTP_POST_VARS["from"]) = Support::getSender(array($HTTP_POST_VARS['item'][$i])); Workflow::handleBlockedEmail(Issue::getProjectID($HTTP_POST_VARS['issue']), $HTTP_POST_VARS['issue'], $HTTP_POST_VARS, 'associated'); Support::removeEmail($HTTP_POST_VARS['item'][$i]); } } $tpl->assign("associate_result", $res);
/** * Method used to remove a given set of projects from the system. * * @return boolean */ public static function remove() { $items = $_POST['items']; $stmt = 'DELETE FROM {{%project}} WHERE prj_id IN (' . DB_Helper::buildList($items) . ')'; try { DB_Helper::getInstance()->query($stmt, $items); } catch (DbException $e) { return -1; } self::removeUserByProjects($items); Category::removeByProjects($items); Release::removeByProjects($items); Filter::removeByProjects($items); Email_Account::removeAccountByProjects($items); Issue::removeByProjects($items); Custom_Field::removeByProjects($items); $statuses = array_keys(Status::getAssocStatusList($items)); foreach ($items as $prj_id) { Status::removeProjectAssociations($statuses, $prj_id); } Group::disassociateProjects($items); return 1; }
// | Authors: João Prado Maia <*****@*****.**> | // +----------------------------------------------------------------------+ require_once dirname(__FILE__) . '/../init.php'; $tpl = new Template_Helper(); $tpl->setTemplate('emails.tpl.html'); Auth::checkAuthentication(APP_COOKIE); if (!Access::canAccessAssociateEmails(Auth::getUserID())) { $tpl->assign('no_access', 1); $tpl->displayTemplate(); exit; } $pagerRow = Support::getParam('pagerRow'); if (empty($pagerRow)) { $pagerRow = 0; } $rows = Support::getParam('rows'); if (empty($rows)) { $rows = APP_DEFAULT_PAGER_SIZE; } $options = Support::saveSearchParams(); $tpl->assign('options', $options); $tpl->assign('sorting', Support::getSortingInfo($options)); $list = Support::getEmailListing($options, $pagerRow, $rows); $tpl->assign('list', $list['list']); $tpl->assign('list_info', $list['info']); $tpl->assign('issues', Issue::getColList()); $tpl->assign('accounts', Email_Account::getAssocList(Auth::getCurrentProject())); $prefs = Prefs::get(Auth::getUserID()); $tpl->assign('refresh_rate', $prefs['email_refresh_rate'] * 60); $tpl->assign('refresh_page', 'emails.php'); $tpl->displayTemplate();
$columns[1][] = array('title' => ev_gettext('Associated Issues'), 'field' => 'associated_issues'); if (!isset($issue_fields_display['expected_resolution']) || $issue_fields_display['expected_resolution'] != false) { $columns[1][] = array('title' => ev_gettext('Expected Resolution Date'), 'field' => 'expected_resolution'); } if (!isset($issue_fields_display['estimated_dev_time']) || $issue_fields_display['estimated_dev_time'] != false) { $columns[1][] = array('title' => ev_gettext('Estimated Dev. Time'), 'data' => empty($details['iss_dev_time']) ? '' : $details['iss_dev_time'] . ' hours', 'field' => 'estimated_dev_time'); } if ($role_id > User::getRoleID('Customer')) { $columns[1][] = array('title' => ev_gettext('Duplicates'), 'field' => 'duplicates', 'title_bgcolor' => APP_INTERNAL_COLOR); $columns[1][] = array('title' => ev_gettext('Authorized Repliers'), 'field' => 'authorized_repliers', 'title_bgcolor' => APP_INTERNAL_COLOR); } $groups = Group::getAssocList($prj_id); if ($role_id > User::getRoleID('Customer') && count($groups) > 0) { $columns[1][] = array('title' => ev_gettext('Group'), 'data' => isset($details['group']) ? $details['group']['grp_name'] : '', 'title_bgcolor' => APP_INTERNAL_COLOR); } $tpl->assign(array('next_issue' => @$sides['next'], 'previous_issue' => @$sides['previous'], 'subscribers' => Notification::getSubscribers($issue_id), 'custom_fields' => Custom_Field::getListByIssue($prj_id, $issue_id), 'files' => Attachment::getList($issue_id), 'emails' => Support::getEmailsByIssue($issue_id), 'zones' => Date_Helper::getTimezoneList(), 'users' => Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer')), 'ema_id' => Email_Account::getEmailAccount(), 'max_attachment_size' => Attachment::getMaxAttachmentSize(), 'quarantine' => Issue::getQuarantineInfo($issue_id), 'grid' => $columns, 'can_update' => Issue::canUpdate($issue_id, $usr_id), 'enabled_partners' => Partner::getPartnersByProject($prj_id), 'partners' => Partner::getPartnersByIssue($issue_id), 'issue_access' => Access::getIssueAccessArray($issue_id, $usr_id), 'is_user_notified' => Notification::isUserNotified($issue_id, $usr_id))); if ($role_id != User::getRoleID('customer')) { if (@$_COOKIE['show_all_drafts'] == 1) { $show_all_drafts = true; } else { $show_all_drafts = false; } if (Workflow::hasWorkflowIntegration($prj_id)) { $statuses = Workflow::getAllowedStatuses($prj_id, $issue_id); // if currently selected release is not on list, go ahead and add it. } else { $statuses = Status::getAssocStatusList($prj_id, false); } if (!empty($details['iss_sta_id']) && empty($statuses[$details['iss_sta_id']])) { $statuses[$details['iss_sta_id']] = Status::getStatusTitle($details['iss_sta_id']); }
/** * 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; } }
if (!empty($HTTP_POST_VARS['time_spent'])) { $HTTP_POST_VARS['issue_id'] = $issue_id; $HTTP_POST_VARS['category'] = Time_Tracking::getCategoryID('Email Discussion'); $HTTP_POST_VARS['summary'] = 'Time entry inserted when saving an email draft.'; Time_Tracking::insertEntry(); } } if (@$HTTP_GET_VARS['cat'] == 'view_draft') { $draft = Draft::getDetails($HTTP_GET_VARS['id']); $email = array('sup_subject' => $draft['emd_subject'], 'seb_body' => $draft['emd_body'], 'sup_from' => $draft['to'], 'cc' => implode('; ', $draft['cc'])); // try to guess the correct email account to be associated with this email if (!empty($draft['emd_sup_id'])) { $HTTP_GET_VARS['ema_id'] = Email_Account::getAccountByEmail($draft['emd_sup_id']); } else { // if we are not replying to an existing message, just get the first email account you can find... $HTTP_GET_VARS['ema_id'] = Email_Account::getEmailAccount(); } $tpl->bulkAssign(array("draft_id" => $HTTP_GET_VARS['id'], "email" => $email, "parent_email_id" => $draft['emd_sup_id'], "draft_status" => $draft['emd_status'])); if ($draft['emd_status'] != 'pending') { $tpl->assign("read_only", 1); } } elseif (@$HTTP_GET_VARS['cat'] == 'create_draft') { $tpl->assign("hide_email_buttons", "yes"); } else { if (!@empty($HTTP_GET_VARS["id"])) { $email = Support::getEmailDetails($HTTP_GET_VARS["ema_id"], $HTTP_GET_VARS["id"]); $date = Misc::formatReplyDate($email["timestamp"]); $header = "To " . $email["sup_from"] . ",\n\n\nThank you, \n" . Auth::getCurrentProjectName() . "\n\nOn {$date}, " . $email["sup_from"] . " wrote:\n>\n"; $email["seb_body"] = $header . Misc::formatReply($email["message"]); $tpl->bulkAssign(array("email" => $email, "parent_email_id" => $HTTP_GET_VARS["id"])); }
/** * Method used to send an email notification to the sender of a * set of email messages that were manually converted into an * issue. * * @param integer $prj_id The project ID * @param integer $issue_id The issue ID * @param array $sup_ids The email IDs * @param bool|int $customer_id The customer ID * @return array The list of recipient emails */ public static function notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id = false) { if (CRM::hasCustomerIntegration($prj_id)) { $crm = CRM::getInstance($prj_id); return $crm->notifyEmailConvertedIntoIssue($issue_id, $sup_ids, $customer_id); } else { // build the list of recipients $recipients = array(); $recipient_emails = array(); foreach ($sup_ids as $sup_id) { $senders = Support::getSender(array($sup_id)); if (count($senders) > 0) { $sender_email = Mail_Helper::getEmailAddress($senders[0]); $recipients[$sup_id] = $senders[0]; $recipient_emails[] = $sender_email; } } if (!$recipients) { return false; } $data = Issue::getDetails($issue_id); foreach ($recipients as $sup_id => $recipient) { $recipient_usr_id = User::getUserIDByEmail(Mail_Helper::getEmailAddress($recipient)); // open text template $tpl = new Template_Helper(); $tpl->setTemplate('notifications/new_auto_created_issue.tpl.text'); $tpl->assign(array('data' => $data, 'sender_name' => Mail_Helper::getName($recipient), 'app_title' => Misc::getToolCaption(), 'recipient_name' => Mail_Helper::getName($recipient))); $email_details = Support::getEmailDetails(Email_Account::getAccountByEmail($sup_id), $sup_id); $tpl->assign(array('email' => array('date' => $email_details['sup_date'], 'from' => $email_details['sup_from'], 'subject' => $email_details['sup_subject']))); // change the current locale if (!empty($recipient_usr_id)) { Language::set(User::getLang($recipient_usr_id)); } else { Language::set(APP_DEFAULT_LOCALE); } $text_message = $tpl->getTemplateContents(); // send email (use PEAR's classes) $mail = new Mail_Helper(); $mail->setTextBody($text_message); $setup = $mail->getSMTPSettings(); $from = self::getFixedFromHeader($issue_id, $setup['from'], 'issue'); $mail->setHeaders(Mail_Helper::getBaseThreadingHeaders($issue_id)); // TRANSLATORS: %1 - issue_id, %2 - iss_summary $subject = ev_gettext('[#%1$s] Issue Created: %2$s', $issue_id, $data['iss_summary']); $mail->send($from, $recipient, $subject, 1, $issue_id, 'email_converted_to_issue'); } Language::restore(); return $recipient_emails; } }
/** * Converts an draft to and email and sends it. * * @param integer $draft_id The id of the draft to send. * @return int */ public static function send($draft_id) { $draft = self::getDetails($draft_id); $from = User::getFromHeader(Auth::getUserID()); $to = $draft['to']; $cc = implode(';', $draft['cc']); $subject = $draft['emd_subject']; $options = array('ema_id' => Email_Account::getEmailAccount()); $res = Support::sendEmail($draft['emd_iss_id'], null, $from, $to, $cc, $subject, $draft['emd_body'], $options); if ($res == 1) { self::remove($draft_id); } return $res; }
/** * Routes an email to the correct issue. * * @param string $full_message The full email message, including headers * @return mixed true or array(ERROR_CODE, ERROR_STRING) in case of failure */ public static function route_emails($full_message) { // need some validation here if (empty($full_message)) { return array(self::EX_NOINPUT, ev_gettext('Error: The email message was empty') . ".\n"); } // save the full message for logging purposes Support::saveRoutedEmail($full_message); // check if the email routing interface is even supposed to be enabled $setup = Setup::get(); if ($setup['email_routing']['status'] != 'enabled') { return array(self::EX_CONFIG, ev_gettext('Error: The email routing interface is disabled.') . "\n"); } if (empty($setup['email_routing']['address_prefix'])) { return array(self::EX_CONFIG, ev_gettext('Error: Please configure the email address prefix.') . "\n"); } if (empty($setup['email_routing']['address_host'])) { return array(self::EX_CONFIG, ev_gettext('Error: Please configure the email address domain.') . "\n"); } // associate routed emails to the internal system account $sys_account = User::getNameEmail(APP_SYSTEM_USER_ID); if (empty($sys_account['usr_email'])) { return array(self::EX_CONFIG, ev_gettext('Error: The associated user for the email routing interface needs to be set.') . "\n"); } unset($sys_account); // join the Content-Type line (for easier parsing?) if (preg_match('/^boundary=/m', $full_message)) { $pattern = "#(Content-Type: multipart/.+); ?\r?\n(boundary=.*)\$#im"; $replacement = '$1; $2'; $full_message = preg_replace($pattern, $replacement, $full_message); } // remove the reply-to: header if (preg_match('/^reply-to:.*/im', $full_message)) { $full_message = preg_replace("/^(reply-to:).*\n/im", '', $full_message, 1); } AuthCookie::setAuthCookie(APP_SYSTEM_USER_ID); $structure = Mime_Helper::decode($full_message, true, true); // find which issue ID this email refers to if (isset($structure->headers['to'])) { $issue_id = self::getMatchingIssueIDs($structure->headers['to'], 'email'); } // we need to try the Cc header as well if (empty($issue_id) and isset($structure->headers['cc'])) { $issue_id = self::getMatchingIssueIDs($structure->headers['cc'], 'email'); } if (empty($issue_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"); } $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; }
/** * Method used to send an email notification to the sender of a * set of email messages that were manually converted into an * issue. * * @access public * @param integer $prj_id The project ID * @param integer $issue_id The issue ID * @param array $sup_ids The email IDs * @param integer $customer_id The customer ID * @return array The list of recipient emails */ function notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id = FALSE) { if (Customer::hasCustomerIntegration($prj_id)) { return Customer::notifyEmailConvertedIntoIssue($prj_id, $issue_id, $sup_ids, $customer_id); } else { // build the list of recipients $recipients = array(); $recipient_emails = array(); for ($i = 0; $i < count($sup_ids); $i++) { $senders = Support::getSender(array($sup_ids[$i])); if (count($senders) > 0) { $sender_email = Mail_API::getEmailAddress($senders[0]); $recipients[$sup_ids[$i]] = $senders[0]; $recipient_emails[] = $sender_email; } } if (count($recipients) == 0) { return false; } $data = Issue::getDetails($issue_id); foreach ($recipients as $sup_id => $recipient) { // open text template $tpl = new Template_API(); $tpl->setTemplate('notifications/new_auto_created_issue.tpl.text'); $tpl->bulkAssign(array("data" => $data, "sender_name" => Mail_API::getName($recipient))); $email_details = Support::getEmailDetails(Email_Account::getAccountByEmail($sup_id), $sup_id); $tpl->assign(array('email' => array('date' => $email_details['sup_date'], 'from' => $email_details['sup_from'], 'subject' => $email_details['sup_subject']))); $text_message = $tpl->getTemplateContents(); // send email (use PEAR's classes) $mail = new Mail_API(); $mail->setTextBody($text_message); $setup = $mail->getSMTPSettings(); $from = Notification::getFixedFromHeader($issue_id, $setup["from"], 'issue'); $mail->setHeaders(Mail_API::getBaseThreadingHeaders($issue_id)); $mail->send($from, $recipient, 'New Issue Created', 1, $issue_id, 'email_converted_to_issue'); } return $recipient_emails; } }
* * @copyright (c) Eventum Team * @license GNU General Public License, version 2 or later (GPL-2+) * * For the full copyright and license information, * please see the COPYING and AUTHORS files * that were distributed with this source code. */ require_once __DIR__ . '/../../init.php'; $tpl = new Template_Helper(); $tpl->setTemplate('manage/email_accounts.tpl.html'); Auth::checkAuthentication(); $tpl->assign('all_projects', Project::getAll()); $role_id = Auth::getCurrentRole(); if ($role_id < User::ROLE_REPORTER) { Misc::setMessage(ev_gettext('Sorry, you are not allowed to access this page.'), Misc::MSG_ERROR); $tpl->displayTemplate(); exit; } if (@$_POST['cat'] == 'new') { Misc::mapMessages(Email_Account::insert(), array(1 => array(ev_gettext('Thank you, the email account was added successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to add the new account.'), Misc::MSG_ERROR))); } elseif (@$_POST['cat'] == 'update') { Misc::mapMessages(Email_Account::update(), array(1 => array(ev_gettext('Thank you, the email account was updated successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to update the account information.'), Misc::MSG_ERROR))); } elseif (@$_POST['cat'] == 'delete') { Misc::mapMessages(Email_Account::remove(), array(1 => array(ev_gettext('Thank you, the email account was deleted successfully.'), Misc::MSG_INFO), -1 => array(ev_gettext('An error occurred while trying to delete the account information.'), Misc::MSG_ERROR))); } if (@$_GET['cat'] == 'edit') { $tpl->assign('info', Email_Account::getDetails($_GET['id'])); } $tpl->assign('list', Email_Account::getList()); $tpl->displayTemplate();
} } if (@$HTTP_GET_VARS["cat"] == "associate") { if (@count($HTTP_GET_VARS["item"]) > 0) { $res = Support::getListDetails($HTTP_GET_VARS["item"]); $tpl->assign("emails", $res); $tpl->assign("attached_emails", @implode(",", $HTTP_GET_VARS["item"])); if (Customer::hasCustomerIntegration($prj_id)) { // also need to guess the contact_id from any attached emails $info = Customer::getCustomerInfoFromEmails($prj_id, $HTTP_GET_VARS["item"]); $tpl->assign(array("customer_id" => $info['customer_id'], 'customer_name' => $info['customer_name'], "contact_id" => $info['contact_id'], 'contact_name' => $info['contact_name'], 'contacts' => $info['contacts'])); } // if we are dealing with just one message, use the subject line as the // summary for the issue, and the body as the description if (count($HTTP_GET_VARS["item"]) == 1) { $email_details = Support::getEmailDetails(Email_Account::getAccountByEmail($HTTP_GET_VARS["item"][0]), $HTTP_GET_VARS["item"][0]); $tpl->assign(array('issue_summary' => $email_details['sup_subject'], 'issue_description' => $email_details['message'])); // also auto pre-fill the customer contact text fields if (Customer::hasCustomerIntegration($prj_id)) { $sender_email = Mail_API::getEmailAddress($email_details['sup_from']); list(, $contact_id) = Customer::getCustomerIDByEmails($prj_id, array($sender_email)); if (!empty($contact_id)) { $tpl->assign("contact_details", Customer::getContactDetails($prj_id, $contact_id)); } } } } } $tpl->assign(array("cats" => Category::getAssocList($prj_id), "priorities" => Priority::getAssocList($prj_id), "users" => Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer')), "releases" => Release::getAssocList($prj_id), "custom_fields" => Custom_Field::getListByProject($prj_id, 'report_form'), "max_attachment_size" => Attachment::getMaxAttachmentSize(), "field_display_settings" => Project::getFieldDisplaySettings($prj_id), "groups" => Group::getAssocList($prj_id))); $setup = Setup::load(); $tpl->assign("allow_unassigned_issues", @$setup["allow_unassigned_issues"]);
if (@$_POST['cat'] == 'associate') { if ($_POST['target'] == 'email') { $res = Support::associate(Auth::getUserID(), $_POST['issue_id'], $_POST['item']); if ($res == 1) { Workflow::handleManualEmailAssociation(Issue::getProjectID($_POST['issue_id']), $_POST['issue_id']); } $tpl->assign('associate_result', $res); } elseif ($_POST['target'] == 'reference') { $res = Support::associateEmail(Auth::getUserID(), $_POST['issue_id'], $_POST['item']); if ($res == 1) { Workflow::handleManualEmailAssociation(Issue::getProjectID($_POST['issue_id']), $_POST['issue_id']); } $tpl->assign('associate_result', $res); } else { foreach ($_POST['item'] as $item) { $email = Support::getEmailDetails(Email_Account::getAccountByEmail($item), $item); // add the message body as a note $_POST['full_message'] = $email['seb_full_email']; $_POST['title'] = $email['sup_subject']; $_POST['note'] = $email['seb_body']; // XXX: probably broken to use the current logged in user as the 'owner' of // XXX: this new note, but that's how it was already $res = Note::insertFromPost(Auth::getUserID(), $_POST['issue_id'], false, true, false, true, true); // remove the associated email if ($res) { list($_POST['from']) = Support::getSender(array($item)); Workflow::handleBlockedEmail(Issue::getProjectID($_POST['issue_id']), $_POST['issue_id'], $_POST, 'associated'); Support::removeEmail($item); } } $tpl->assign('associate_result', $res);
// | Boston, MA 02110-1301, USA. | // +----------------------------------------------------------------------+ // | Authors: João Prado Maia <*****@*****.**> | // +----------------------------------------------------------------------+ require_once dirname(__FILE__) . '/../init.php'; $usr_id = Auth::getUserID(); $prj_id = Auth::getCurrentProject(); $tpl = new Template_Helper(); $tpl->setTemplate('view_email.tpl.html'); Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true); $issue_id = Support::getIssueFromEmail($_GET['id']); if ($issue_id != 0 && !Issue::canAccess($issue_id, $usr_id) || $issue_id == 0 && User::getRoleByUser($usr_id, $prj_id) < User::ROLE_USER) { $tpl->setTemplate('permission_denied.tpl.html'); $tpl->displayTemplate(); exit; } $email = Support::getEmailDetails($_GET['ema_id'], $_GET['id']); $email['seb_body'] = str_replace('&nbsp;', ' ', $email['seb_body']); $tpl->assign(array('email' => $email, 'issue_id' => $issue_id, 'extra_title' => ev_gettext('Issue #%1$s Email #%3$s: %2$s', $issue_id, $email['sup_subject'], Support::getSequenceByID($_GET['id'])), 'email_accounts' => Email_Account::getAssocList(array_keys(Project::getAssocList(Auth::getUserID())), true), 'recipients' => Mail_Queue::getMessageRecipients(array('customer_email', 'other_email'), $_GET['id']))); if (@$_GET['cat'] == 'list_emails') { $sides = Support::getListingSides($_GET['id']); $tpl->assign(array('previous' => $sides['previous'], 'next' => $sides['next'])); } elseif (@$_GET['cat'] == 'move_email' && Auth::getCurrentRole() >= User::getRoleID('Standard User')) { $res = Support::moveEmail(@$_GET['id'], @$_GET['ema_id'], @$_GET['new_ema_id']); $tpl->assign('move_email_result', $res); $tpl->assign('current_user_prefs', Prefs::get(Auth::getUserID())); } else { $sides = Support::getIssueSides($issue_id, $_GET['id']); $tpl->assign(array('previous' => $sides['previous'], 'next' => $sides['next'])); } $tpl->displayTemplate();
if (!Lock::acquire('download_emails_' . $account_id)) { if (SAPI_CLI) { fatal('Another instance of the script is still running for the specified account.', "If this is not accurate, you may fix it by running this script with '--fix-lock'", "as the 4th parameter or you may unlock ALL accounts by running this script with '--fix-lock'", 'as the only parameter.'); } else { fatal('Another instance of the script is still running for the specified account. ', "If this is not accurate, you may fix it by running this script with 'fix-lock=1'", "in the query string or you may unlock ALL accounts by running this script with 'fix-lock=1'", 'as the only parameter.'); } exit; } // clear the lock in all cases of termination function cleanup_lock() { global $account_id; Lock::release('download_emails_' . $account_id); } register_shutdown_function('cleanup_lock'); $account = Email_Account::getDetails($account_id); $mbox = Support::connectEmailServer($account); if ($mbox == false) { $uri = Support::getServerURI($account); $login = $account['ema_username']; $error = imap_last_error(); fatal("{$error}\n", "Could not connect to the email server '{$uri}' with login: '******'.", 'Please verify your email account settings and try again.'); } // if we only want new emails if ($account['ema_get_only_new']) { $new_emails = Support::getNewEmails($mbox); foreach ($new_emails as $new_email) { Support::getEmailInfo($mbox, $account, $new_email); } } else { $total_emails = Support::getTotalEmails($mbox);
// include_once "../config.inc.php"; include_once APP_INC_PATH . "class.template.php"; include_once APP_INC_PATH . "class.auth.php"; include_once APP_INC_PATH . "class.user.php"; include_once APP_INC_PATH . "class.project.php"; include_once APP_INC_PATH . "class.support.php"; include_once APP_INC_PATH . "db_access.php"; $tpl = new Template_API(); $tpl->setTemplate("manage/index.tpl.html"); Auth::checkAuthentication(APP_COOKIE); $tpl->assign("type", "email_accounts"); $tpl->assign("all_projects", Project::getAll()); $role_id = Auth::getCurrentRole(); if ($role_id == User::getRoleID('administrator')) { $tpl->assign("show_setup_links", true); if (@$HTTP_POST_VARS["cat"] == "new") { $tpl->assign("result", Email_Account::insert()); } elseif (@$HTTP_POST_VARS["cat"] == "update") { $tpl->assign("result", Email_Account::update()); } elseif (@$HTTP_POST_VARS["cat"] == "delete") { Email_Account::remove(); } if (@$HTTP_GET_VARS["cat"] == "edit") { $tpl->assign("info", Email_Account::getDetails($HTTP_GET_VARS["id"])); } $tpl->assign("list", Email_Account::getList()); } else { $tpl->assign("show_not_allowed_msg", true); } $tpl->displayTemplate();
$date = (array) $_POST['date']; $ttc_id = Time_Tracking::getCategoryId($prj_id, 'Email Discussion'); $time_spent = (int) $_POST['time_spent']; $summary = 'Time entry inserted when saving an email draft.'; Time_Tracking::addTimeEntry($issue_id, $ttc_id, $time_spent, $date, $summary); } } if ($cat == 'view_draft') { $draft = Draft::getDetails($_GET['id']); $email = array('sup_subject' => $draft['emd_subject'], 'seb_body' => $draft['emd_body'], 'sup_from' => $draft['to'], 'cc' => implode('; ', $draft['cc'])); // try to guess the correct email account to be associated with this email if (!empty($draft['emd_sup_id'])) { $_GET['ema_id'] = Email_Account::getAccountByEmail($draft['emd_sup_id']); } else { // if we are not replying to an existing message, just get the first email account you can find... $_GET['ema_id'] = Email_Account::getEmailAccount(); } $tpl->assign(array('draft_id' => $_GET['id'], 'email' => $email, 'parent_email_id' => $draft['emd_sup_id'], 'draft_status' => $draft['emd_status'])); if ($draft['emd_status'] != 'pending') { $tpl->assign('read_only', 1); } } elseif ($cat == 'create_draft') { $tpl->assign('hide_email_buttons', 'yes'); } else { if (!empty($_GET['id'])) { $email = Support::getEmailDetails($_GET['ema_id'], $_GET['id']); $header = Misc::formatReplyPreamble($email['timestamp'], $email['sup_from']); $email['seb_body'] = $header . Misc::formatReply($email['seb_body']); $tpl->assign(array('email' => $email, 'parent_email_id' => $_GET['id'])); } }
$show_releases = 0; } // get if categories should be displayed $cats = Category::getList($prj_id); if (count($cats) > 0) { $show_category = 1; } else { $show_category = 0; } $cookie = Auth::getCookieInfo(APP_PROJECT_COOKIE); if (!empty($auto_switched_from)) { $tpl->assign(array("project_auto_switched" => 1, "old_project" => Project::getName($auto_switched_from))); } $setup = Setup::load(); $tpl->assign("allow_unassigned_issues", @$setup["allow_unassigned_issues"]); $tpl->assign(array('next_issue' => @$sides['next'], 'previous_issue' => @$sides['previous'], 'subscribers' => Notification::getSubscribers($issue_id), 'custom_fields' => Custom_Field::getListByIssue($prj_id, $issue_id), 'files' => Attachment::getList($issue_id), 'emails' => Support::getEmailsByIssue($issue_id), 'zones' => Date_API::getTimezoneList(), 'users' => Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer')), 'ema_id' => Email_Account::getEmailAccount(), 'max_attachment_size' => Attachment::getMaxAttachmentSize(), 'show_releases' => $show_releases, 'show_category' => $show_category, 'categories' => Category::getAssocList($prj_id), 'quarantine' => Issue::getQuarantineInfo($issue_id))); if ($role_id != User::getRoleID('customer')) { if (@$_REQUEST['show_all_drafts'] == 1) { $show_all_drafts = true; } else { $show_all_drafts = false; } if (Workflow::hasWorkflowIntegration($prj_id)) { $statuses = Workflow::getAllowedStatuses($prj_id, $issue_id); // if currently selected release is not on list, go ahead and add it. } else { $statuses = Status::getAssocStatusList($prj_id); } if (!empty($details['iss_sta_id']) && empty($statuses[$details['iss_sta_id']])) { $statuses[$details['iss_sta_id']] = Status::getStatusTitle($details['iss_sta_id']); }
include_once APP_INC_PATH . "class.misc.php"; include_once APP_INC_PATH . "class.project.php"; include_once APP_INC_PATH . "class.setup.php"; include_once APP_INC_PATH . "db_access.php"; $tpl = new Template_API(); $tpl->setTemplate("manage/index.tpl.html"); Auth::checkAuthentication(APP_COOKIE); $tpl->assign("type", "issue_auto_creation"); @($ema_id = $HTTP_POST_VARS["ema_id"] ? $HTTP_POST_VARS["ema_id"] : $HTTP_GET_VARS["ema_id"]); $role_id = Auth::getCurrentRole(); if ($role_id == User::getRoleID('administrator') || $role_id == User::getRoleID('manager')) { if ($role_id == User::getRoleID('administrator')) { $tpl->assign("show_setup_links", true); } $prj_id = Email_Account::getProjectID($ema_id); if (@$HTTP_POST_VARS["cat"] == "update") { @Email_Account::updateIssueAutoCreation($ema_id, $HTTP_POST_VARS['issue_auto_creation'], $HTTP_POST_VARS['options']); } // load the form fields $tpl->assign("info", Email_Account::getDetails($ema_id)); $tpl->assign("cats", Category::getAssocList($prj_id)); $tpl->assign("priorities", Priority::getList($prj_id)); $tpl->assign("users", Project::getUserAssocList($prj_id, 'active')); $tpl->assign("options", Email_Account::getIssueAutoCreationOptions($ema_id)); $tpl->assign("ema_id", $ema_id); $tpl->assign("prj_title", Project::getName($prj_id)); $tpl->assign("uses_customer_integration", Customer::hasCustomerIntegration($prj_id)); } else { $tpl->assign("show_not_allowed_msg", true); } $tpl->displayTemplate();
/** * Converts an email to a draft and sends it. * * @access public * @param integer $draft_id The id of the draft to send. */ function send($draft_id) { global $HTTP_POST_VARS; $draft_id = Misc::escapeInteger($draft_id); $draft = Draft::getDetails($draft_id); $HTTP_POST_VARS["issue_id"] = $draft["emd_iss_id"]; $HTTP_POST_VARS["subject"] = $draft["emd_subject"]; $HTTP_POST_VARS["from"] = User::getFromHeader(Auth::getUserID()); $HTTP_POST_VARS["to"] = $draft["to"]; $HTTP_POST_VARS["cc"] = @join(";", $draft["cc"]); $HTTP_POST_VARS["message"] = $draft["emd_body"]; $HTTP_POST_VARS["ema_id"] = Email_Account::getEmailAccount(); $res = Support::sendEmail(); if ($res == 1) { Draft::remove($draft_id); } return $res; }
/** * Method used to remove a given set of projects from the system. * * @access public * @return boolean */ function remove() { global $HTTP_POST_VARS; $items = @implode(", ", Misc::escapeInteger($HTTP_POST_VARS["items"])); $stmt = "DELETE FROM\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project\n WHERE\n prj_id IN ({$items})"; $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return false; } else { Project::removeUserByProjects($HTTP_POST_VARS["items"]); Category::removeByProjects($HTTP_POST_VARS["items"]); Release::removeByProjects($HTTP_POST_VARS["items"]); Filter::removeByProjects($HTTP_POST_VARS["items"]); Email_Account::removeAccountByProjects($HTTP_POST_VARS["items"]); Issue::removeByProjects($HTTP_POST_VARS["items"]); Custom_Field::removeByProjects($HTTP_POST_VARS["items"]); $statuses = array_keys(Status::getAssocStatusList($HTTP_POST_VARS["items"])); foreach ($HTTP_POST_VARS["items"] as $prj_id) { Status::removeProjectAssociations($statuses, $prj_id); } Group::disassociateProjects($HTTP_POST_VARS["items"]); return true; } }
/** * Moves an email from one account to another. * * @access public * @param integer $sup_id The ID of the message. * @param integer $current_ema_id The ID of the account the message is currently in. * @param integer $new_ema_id The ID of the account to move the message too. * @return integer -1 if there was error moving the message, 1 otherwise. */ function moveEmail($sup_id, $current_ema_id, $new_ema_id) { $usr_id = Auth::getUserID(); $email = Support::getEmailDetails($current_ema_id, $sup_id); if (!empty($email['sup_iss_id'])) { return -1; } $info = Email_Account::getDetails($new_ema_id); $full_email = Support::getFullEmail($sup_id); $structure = Mime_Helper::decode($full_email, true, true); $headers = ''; foreach ($structure->headers as $key => $value) { if (is_array($value)) { continue; } $headers .= "{$key}: {$value}\n"; } // handle auto creating issues (if needed) $should_create_array = Support::createIssueFromEmail($info, $headers, $email['seb_body'], $email['timestamp'], $email['sup_from'], $email['sup_subject']); $should_create_issue = $should_create_array['should_create_issue']; $associate_email = $should_create_array['associate_email']; $issue_id = $should_create_array['issue_id']; $customer_id = $should_create_array['customer_id']; if (empty($issue_id)) { $issue_id = 0; } if (empty($customer_id)) { $customer_id = 'NULL'; } $sql = "UPDATE\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "support_email\n SET\n sup_ema_id = " . Misc::escapeInteger($new_ema_id) . ",\n sup_iss_id = " . Misc::escapeInteger($issue_id) . ",\n sup_customer_id = " . Misc::escapeInteger($customer_id) . "\n WHERE\n sup_id = " . Misc::escapeInteger($sup_id) . " AND\n sup_ema_id = " . Misc::escapeInteger($current_ema_id); $res = $GLOBALS["db_api"]->dbh->query($sql); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return -1; } $row = array('customer_id' => $customer_id, 'issue_id' => $issue_id, 'ema_id' => $new_ema_id, 'message_id' => $email['sup_message_id'], 'date' => $email['timestamp'], 'from' => $email['sup_from'], 'to' => $email['sup_to'], 'cc' => $email['sup_cc'], 'subject' => $email['sup_subject'], 'body' => $email['seb_body'], 'full_email' => $email['seb_full_email'], 'has_attachment' => $email['sup_has_attachment']); Workflow::handleNewEmail(Support::getProjectByEmailAccount($new_ema_id), $issue_id, $structure, $row); return 1; }
$res = Support::getListDetails($item); $tpl->assign('emails', $res); $tpl->assign('attached_emails', @implode(',', $item)); if (CRM::hasCustomerIntegration($prj_id)) { $crm = CRM::getInstance($prj_id); // also need to guess the contact_id from any attached emails try { $info = $crm->getCustomerInfoFromEmails($prj_id, $item); $tpl->assign(array('customer_id' => $info['customer_id'], 'customer_name' => $info['customer_name'], 'contact_id' => $info['contact_id'], 'contact_name' => $info['contact_name'], 'contacts' => $info['contacts'])); } catch (CRMException $e) { } } // if we are dealing with just one message, use the subject line as the // summary for the issue, and the body as the description if (count($item) == 1) { $email_details = Support::getEmailDetails(Email_Account::getAccountByEmail($item[0]), $item[0]); $tpl->assign(array('issue_summary' => $email_details['sup_subject'], 'issue_description' => $email_details['seb_body'])); // also auto pre-fill the customer contact text fields if (CRM::hasCustomerIntegration($prj_id)) { $sender_email = Mail_Helper::getEmailAddress($email_details['sup_from']); try { $contact = $crm->getContactByEmail($sender_email); $tpl->assign('contact_details', $contact->getDetails()); } catch (CRMException $e) { } } } } } $tpl->assign(array('cats' => Category::getAssocList($prj_id), 'priorities' => Priority::getAssocList($prj_id), 'severities' => Severity::getList($prj_id), 'users' => Project::getUserAssocList($prj_id, 'active', User::getRoleID('Customer')), 'releases' => Release::getAssocList($prj_id), 'custom_fields' => Custom_Field::getListByProject($prj_id, 'report_form'), 'max_attachment_size' => Attachment::getMaxAttachmentSize(), 'max_attachment_bytes' => Attachment::getMaxAttachmentSize(true), 'field_display_settings' => Project::getFieldDisplaySettings($prj_id), 'groups' => Group::getAssocList($prj_id), 'products' => Product::getList(false))); $prefs = Prefs::get($usr_id);
/** * Converts an email to a draft and sends it. * * @param integer $draft_id The id of the draft to send. * @return int */ public static function send($draft_id) { $draft = self::getDetails($draft_id); $_POST['issue_id'] = $draft['emd_iss_id']; $_POST['subject'] = $draft['emd_subject']; $_POST['from'] = User::getFromHeader(Auth::getUserID()); $_POST['to'] = $draft['to']; $_POST['cc'] = @implode(';', $draft['cc']); $_POST['message'] = $draft['emd_body']; $_POST['ema_id'] = Email_Account::getEmailAccount(); $res = Support::sendEmailFromPost(); if ($res == 1) { self::remove($draft_id); } return $res; }
/** * Method used to get the project ID associated with a given email account. * * @access public * @param integer $ema_id The support email account ID * @return integer The project ID */ function getProjectID($ema_id) { $details = Email_Account::getDetails($ema_id); return $details['ema_prj_id']; }
/** * Routes an email to the correct issue. * * @param string $full_message The full email message, including headers * @param integer $email_account_id The ID of the email account this email should be routed too. If empty this method will try to figure it out */ function route_emails($full_message, $email_account_id = 0) { global $HTTP_POST_VARS; // save the full message for logging purposes Support::saveRoutedEmail($full_message); if (preg_match("/^(boundary=).*/m", $full_message)) { $pattern = "/(Content-Type: multipart\\/)(.+); ?\r?\n(boundary=)(.*)\$/im"; $replacement = '$1$2; $3$4'; $full_message = preg_replace($pattern, $replacement, $full_message); } // associate routed emails to the internal system account $sys_account = User::getNameEmail(APP_SYSTEM_USER_ID); $associated_user = $sys_account['usr_email']; // need some validation here if (empty($full_message)) { return array(66, "Error: The email message was empty.\n"); } if (empty($associated_user)) { return array(78, "Error: The associated user for the email routing interface needs to be set.\n"); } // // DON'T EDIT ANYTHING BELOW THIS LINE // // remove the reply-to: header if (preg_match("/^(reply-to:).*/im", $full_message)) { $full_message = preg_replace("/^(reply-to:).*\n/im", '', $full_message, 1); } // check for magic cookie if (Mail_API::hasMagicCookie($full_message)) { // strip the magic cookie $full_message = Mail_API::stripMagicCookie($full_message); $has_magic_cookie = true; } else { $has_magic_cookie = false; } Auth::createFakeCookie(APP_SYSTEM_USER_ID); // check if the email routing interface is even supposed to be enabled $setup = Setup::load(); if ($setup['email_routing']['status'] != 'enabled') { return array(78, "Error: The email routing interface is disabled.\n"); } $prefix = $setup['email_routing']['address_prefix']; // escape plus signs so '*****@*****.**' becomes a valid routing address $prefix = str_replace('+', '\\+', $prefix); $mail_domain = quotemeta($setup['email_routing']['address_host']); $mail_domain_alias = quotemeta(@$setup['email_routing']['host_alias']); if (!empty($mail_domain_alias)) { $mail_domain = "(?:" . $mail_domain . "|" . $mail_domain_alias . ")"; } if (empty($prefix)) { return array(78, "Error: Please configure the email address prefix.\n"); } if (empty($mail_domain)) { return array(78, "Error: Please configure the email address domain.\n"); } $structure = Mime_Helper::decode($full_message, true, true); // find which issue ID this email refers to @preg_match("/{$prefix}(\\d*)@{$mail_domain}/i", $structure->headers['to'], $matches); @($issue_id = $matches[1]); // validation is always a good idea if (empty($issue_id)) { // we need to try the Cc header as well @preg_match("/{$prefix}(\\d*)@{$mail_domain}/i", $structure->headers['cc'], $matches); if (!empty($matches[1])) { $issue_id = $matches[1]; } else { return array(65, "Error: The routed email had no associated Eventum issue ID or had an invalid recipient address.\n"); } } if (empty($email_account_id)) { $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; }