<?php if (!defined('sugarEntry') || !sugarEntry) { die('Not A Valid Entry Point'); } /* * Your installation or use of this SugarCRM file is subject to the applicable * terms available at * http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/. * If you do not agree to all of the applicable terms or do not have the * authority to bind the entity as an authorized representative, then do not * install or use this SugarCRM file. * * Copyright (C) SugarCRM Inc. All rights reserved. */ global $app_strings; // coming from an include in a method call global $current_user; require_once "include/SugarRouting/SugarRouting.php"; $ie = BeanFactory::getBean('InboundEmail'); $rules = new SugarRouting($ie, $current_user); $actions = $rules->getActionsDOM(); $strings = array(); foreach ($app_strings as $k => $v) { if (strpos($k, "LBL_ROUTING_") !== false) { $strings[$k] = $v; } } $sugarDependentDropdown = array('debugMode' => false, 'actions' => array('always_merge' => array('force_render' => false, 'actionType' => 'actions', 'onchange' => ''), 'elements' => array('element0' => array('name' => 'action0', 'id' => 'action0', 'type' => 'select', 'grouping' => 'actionGroup', 'values' => $actions, 'selected' => '', 'onchange' => 'SUGAR.routing.handleDependentDropdown(this, \'actions\');', 'label' => ' ', 'label_pos' => 'left'), 'element1' => array('name' => 'action1', 'id' => 'action1', 'label' => '', 'label_pos' => 'none', 'grouping' => 'actionGroup', 'handlers' => array('mark_read' => array(), 'mark_unread' => array(), 'mark_flagged' => array(), 'move_mail' => array('type' => 'select', 'values' => 'SUGAR.routing.ui.getElementValues("move_mail");', 'label' => $strings['LBL_ROUTING_TO'], 'label_pos' => 'left'), 'copy_mail' => array('type' => 'select', 'values' => 'SUGAR.routing.ui.getElementValues("move_mail");', 'label' => $strings['LBL_ROUTING_TO'], 'label_pos' => 'left'), 'forward' => array('type' => 'input', 'label' => $strings['LBL_ROUTING_TO_ADDRESS'], 'label_pos' => 'left'), 'reply' => array('type' => 'select', 'label' => $strings['LBL_ROUTING_WITH_TEMPLATE'], 'label_pos' => 'left', 'values' => 'SUGAR.routing.ui.getElementValues("email_templates");'), 'delete_mail' => array('onchange' => 'SUGAR.routing.handleDependentDropdown(this, \'actions\');', 'type' => 'none'))))), 'criteria' => array('always_merge' => array('force_render' => false, 'grouping' => 'criteriaGroup', 'onchange' => 'SUGAR.routing.handleDependentDropdown(this, \'criteria\');', 'label' => ' ', 'label_pos' => 'left', 'actionType' => 'criteria'), 'elements' => array('element0' => array('name' => 'crit0', 'id' => 'crit0id', 'type' => 'select', 'values' => 'SUGAR.routing.matchDom;', 'selected' => ''), 'element1' => array('name' => 'crit1', 'id' => 'crit1id', 'type' => 'select', 'values' => 'SUGAR.routing.matchTypeDom;', 'handlers' => array('from_addr' => array(), 'to_addr' => array(), 'cc_addr' => array(), 'name' => array(), 'description' => array(), 'priority_high' => array('type' => 'none', 'label' => $app_strings['LBL_ROUTING_FLAGGED']), 'priority_normal' => array('type' => 'none', 'label' => $app_strings['LBL_ROUTING_FLAGGED']), 'priority_low' => array('type' => 'none', 'label' => $app_strings['LBL_ROUTING_FLAGGED']))), 'element2' => array('name' => 'crit2', 'id' => 'crit2id', 'type' => 'input', 'values' => ''))), 'criteriaSimple' => array('always_merge' => array('force_render' => true, 'grouping' => 'criteriaGroup', 'onchange' => '', 'label' => ' ', 'label_pos' => 'left'), 'elements' => array('element0' => array('name' => 'crit0', 'id' => 'crit0id', 'type' => 'select', 'values' => 'SUGAR.routing.matchDom;', 'selected' => ''), 'element1' => array('name' => 'crit1', 'id' => 'crit1id', 'type' => 'select', 'values' => 'SUGAR.routing.matchTypeDom;'), 'element2' => array('name' => 'crit2', 'id' => 'crit2id', 'type' => 'input', 'values' => ''))));
/** * Applies rules where applicable * @param array $searchResults * @param object $user User in focus, default to $current_user * @return array */ function processRules($searchResults, $user = null) { global $current_user; require_once "include/SugarRouting/SugarRouting.php"; if (empty($user)) { global $current_user; $user = $current_user; } $routing = new SugarRouting($this); if (!isset($routing->rules) || empty($routing->rules)) { // No point of going through results if there is no rule defined. return $searchResults; } $newSearchResults = array(); foreach ($searchResults as $k => $result) { // special assignment for rules /*stdClass Object ( [subject] => aaa [from] => Some Name [to] => Some Name [date] => Mon, 22 Jan 2007 17:32:57 -0800 [message_id] => [size] => 718 [uid] => 191 [msgno] => 141 [recent] => 0 [flagged] => 0 [answered] => 0 [deleted] => 0 [seen] => 1 [draft] => 0 )*/ $arr = imap_fetch_overview($this->conn, $result, FT_UID); $overview = $arr[0]; $this->email = BeanFactory::getBean('Emails'); $this->email->uid = $result; $this->email->imap_uid = $result; $this->email->mailbox_id = $this->id; $this->email->name = $overview->subject; $this->email->from_addr = $overview->from; // not in vardefs $this->email->to = $overview->to; // not in vardefs $this->email->date_sent = $overview->date; $this->email->flagged = $overview->flagged; $this->email->answered = $overview->answered; $this->email->deleted = $overview->deleted; $this->email->seen = $overview->seen; $this->email->draft = $overview->draft; if (!$routing->processRules($this->email, $this)) { $GLOBALS['log']->info("INBOUNDEMAIL: Rules not processed, adding to \$newSearchResults array"); $newSearchResults[$k] = $result; } else { $GLOBALS['log']->info("INBOUNDEMAIL: Rule processed, NOT adding to \$newSearchResults array"); } } return $newSearchResults; }
* * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". ********************************************************************************/ /********************************************************************************* * Description: * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. All Rights * Reserved. Contributor(s): ______________________________________.. *********************************************************************************/ require_once "include/SugarRouting/SugarRouting.php"; $ie = new InboundEmail(); $json = getJSONobj(); $rules = new SugarRouting($ie, $current_user); switch ($_REQUEST['routingAction']) { case "setRuleStatus": $rules->setRuleStatus($_REQUEST['rule_id'], $_REQUEST['status']); break; case "saveRule": $rules->save($_REQUEST); break; case "deleteRule": $rules->deleteRule($_REQUEST['rule_id']); break; /* returns metadata to construct actions */ /* returns metadata to construct actions */ case "getActions": require_once "include/SugarDependentDropdown/SugarDependentDropdown.php"; $sdd = new SugarDependentDropdown();
if (ini_get('max_execution_time') > 0 && ini_get('max_execution_time') < 300) { ini_set('max_execution_time', 300); } //ajaxInit(); require_once "include/OutboundEmail/OutboundEmail.php"; require_once "vendor/ytree/Tree.php"; require_once "vendor/ytree/ExtNode.php"; global $mod_strings; $email = BeanFactory::getBean('Emails'); $email->email2init(); $ie = BeanFactory::getBean('InboundEmail'); $ie->disable_row_level_security = true; $ie->email = $email; $json = getJSONobj(); require_once "include/SugarRouting/SugarRouting.php"; $rules = new SugarRouting($ie, $current_user); $showFolders = unserialize(base64_decode($current_user->getPreference('showFolders', 'Emails'))); if (isset($_REQUEST['emailUIAction'])) { switch ($_REQUEST['emailUIAction']) { /////////////////////////////////////////////////////////////////////////// //// RULES & ROUTING case "loadRulesForSettings": $out = $rules->getRulesList($ie); echo $out; // returns RAW HTML break; case "getOneRuleset": $id = isset($_REQUEST['rule_id']) ? $_REQUEST['rule_id'] : ''; $rule = $rules->getRule($id, $ie); $out = $json->encode($rule, true); echo $out;