/** * Selects the email from the table and returns the contents. Since jsrs only supports returning one value, * the string that is returned is in the format * of ec_id:id:email. If ec_id is not passed as a parameter, only the email is returned. * * @param string $id The sup_ema_id and sup_id seperated by a -. * @return A string containing the body of the email, optionally prefaced by the ec_id and $id. */ function getEmail($id) { $split = explode("-", $id); $info = Support::getEmailDetails($split[0], $split[1]); if (!empty($_GET["ec_id"])) { return Link_Filter::processText(Auth::getCurrentProject(), nl2br($_GET["ec_id"] . ":" . $id . ":" . Misc::highlightQuotedReply($info["message"]))); } else { return $info["seb_body"]; } }
/** * Selects the email from the table and returns the contents. * * @param string $id The sup_ema_id and sup_id seperated by a -. * @return A string containing the body of the email, */ function getEmail($id) { $split = explode('-', $id); $info = Support::getEmailDetails($split[0], $split[1]); if (!Issue::canAccess($info['sup_iss_id'], $GLOBALS['usr_id'])) { return ''; } if (empty($_GET['ec_id'])) { return $info['seb_body']; } return Link_Filter::processText(Auth::getCurrentProject(), nl2br(Misc::highlightQuotedReply($info['seb_body']))); }
public function getExcerpts() { if (count($this->matches) < 1) { return false; } $excerpt_options = array('query_mode' => $this->match_mode, 'before_match' => $this->excerpt_placeholder . '-before', 'after_match' => $this->excerpt_placeholder . '-after', 'allow_empty' => true); $excerpts = array(); foreach ($this->matches as $issue_id => $matches) { $excerpt = array('issue' => array(), 'email' => array(), 'phone' => array(), 'note' => array()); foreach ($matches as $match) { if ($match['index'] == 'issue') { $issue = Issue::getDetails($issue_id); $documents = array($issue['iss_summary']); $res = $this->sphinx->BuildExcerpts($documents, 'issue_stemmed', $this->keywords, $excerpt_options); if ($res[0] != $issue['iss_summary']) { $excerpt['issue']['summary'] = self::cleanUpExcerpt($res[0]); } $documents = array($issue['iss_original_description']); $res = $this->sphinx->BuildExcerpts($documents, 'issue_stemmed', $this->keywords, $excerpt_options); if ($res[0] != $issue['iss_original_description']) { $excerpt['issue']['description'] = self::cleanUpExcerpt($res[0]); error_log(print_r($excerpt['issue']['description'], 1)); } } elseif ($match['index'] == 'email') { $email = Support::getEmailDetails(null, $match['match_id']); $documents = array($email['sup_subject'] . "\n" . $email['message']); $res = $this->sphinx->BuildExcerpts($documents, 'email_stemmed', $this->keywords, $excerpt_options); $excerpt['email'][Support::getSequenceByID($match['match_id'])] = self::cleanUpExcerpt($res[0]); } elseif ($match['index'] == 'phone') { $phone_call = Phone_Support::getDetails($match['match_id']); $documents = array($phone_call['phs_description']); $res = $this->sphinx->BuildExcerpts($documents, 'phonesupport_stemmed', $this->keywords, $excerpt_options); $excerpt['phone'][] = self::cleanUpExcerpt($res[0]); } elseif ($match['index'] == 'note') { $note = Note::getDetails($match['match_id']); $documents = array($note['not_title'] . "\n" . $note['not_note']); $res = $this->sphinx->BuildExcerpts($documents, 'note_stemmed', $this->keywords, $excerpt_options); $note_seq = Note::getNoteSequenceNumber($issue_id, $match['match_id']); $excerpt['note'][$note_seq] = self::cleanUpExcerpt($res[0]); } } foreach ($excerpt as $key => $val) { if (count($val) < 1) { unset($excerpt[$key]); } } $excerpts[$issue_id] = $excerpt; } return $excerpts; }
$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);
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);
// 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'])); } } // special handling when someone tries to 'reply' to an issue if ($cat == 'reply') { $details = Issue::getReplyDetails($_GET['issue_id']); if ($details != '') { $header = Misc::formatReplyPreamble($details['created_date_ts'], $details['reporter']); $details['seb_body'] = $header . Misc::formatReply($details['description']); $details['sup_from'] = Mail_Helper::getFormattedName($details['reporter'], $details['reporter_email']); $tpl->assign(array('email' => $details, 'parent_email_id' => 0, 'extra_title' => 'Issue #' . $_GET['issue_id'] . ': Reply')); } }
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);
/** * 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; }
} } 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"]);
/** * 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; } }
// 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"])); } } // special handling when someone tries to 'reply' to an issue if (@$HTTP_GET_VARS["cat"] == 'reply') { $details = Issue::getReplyDetails($HTTP_GET_VARS['issue_id']); if ($details != '') { $date = Misc::formatReplyDate($details['created_date_ts']); $header = "To " . $details["reporter"] . ",\n\n\nThank you, \n" . Auth::getCurrentProjectName() . "\n\nOn {$date}, " . $details['reporter'] . " wrote:\n>\n"; $details['seb_body'] = $header . Misc::formatReply($details['description']); $details['sup_from'] = Mail_API::getFormattedName($details['reporter'], $details['reporter_email']); $tpl->bulkAssign(array("email" => $details, "parent_email_id" => 0, "extra_title" => "Issue #" . $HTTP_GET_VARS['issue_id'] . ": Reply"));
/** * 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; } }