Exemplo n.º 1
0
 /**
  * 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;
 }
 /**
  * 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'];
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
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();
Exemplo n.º 5
0
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);
Exemplo n.º 6
0
 *
 * @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();
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
0
// | Free Software Foundation, Inc.                                       |
// | 51 Franklin Street, Suite 330                                          |
// | Boston, MA 02110-1301, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: João Prado Maia <*****@*****.**>                             |
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('manage/issue_auto_creation.tpl.html');
Auth::checkAuthentication(APP_COOKIE);
@($ema_id = $_POST['ema_id'] ? $_POST['ema_id'] : $_GET['ema_id']);
$role_id = Auth::getCurrentRole();
if ($role_id < User::getRoleID('administrator')) {
    Misc::setMessage('Sorry, you are not allowed to access this page.', Misc::MSG_ERROR);
    $tpl->displayTemplate();
    exit;
}
$prj_id = Email_Account::getProjectID($ema_id);
if (@$_POST['cat'] == 'update') {
    @Email_Account::updateIssueAutoCreation($ema_id, $_POST['issue_auto_creation'], $_POST['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', CRM::hasCustomerIntegration($prj_id));
$tpl->displayTemplate();
Exemplo n.º 9
0
//
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();