Example #1
0
 function _createInboundAccount()
 {
     global $inbound_account_id, $current_user;
     $stored_options = array();
     $stored_options['from_name'] = "UnitTest";
     $stored_options['from_addr'] = "*****@*****.**";
     $stored_options['reply_to_name'] = "UnitTest";
     $stored_options['reply_to_addr'] = "*****@*****.**";
     $stored_options['only_since'] = false;
     $stored_options['filter_domain'] = "";
     $stored_options['trashFolder'] = "INBOX.Trash";
     $stored_options['leaveMessagesOnMailServer'] = 1;
     $useSsl = false;
     $focus = new InboundEmail();
     $focus->name = "Ajay Sales Personal Unittest";
     $focus->email_user = "******";
     $focus->email_password = "******";
     $focus->server_url = "mail.sugarcrm.com";
     $focus->protocol = "imap";
     $focus->mailbox = "INBOX";
     $focus->port = "143";
     $optimum = $focus->findOptimumSettings($useSsl);
     $focus->service = $optimum['serial'];
     $focus->is_personal = 1;
     $focus->status = "Active";
     $focus->mailbox_type = 'pick';
     $focus->group_id = $current_user->id;
     $teamId = User::getPrivateTeam($current_user->id);
     $focus->team_id = $teamId;
     $focus->team_set_id = $focus->getTeamSetIdForTeams($teamId);
     $focus->stored_options = base64_encode(serialize($stored_options));
     $inbound_account_id = $focus->save();
 }
Example #2
0
 /**
  * Saves Personal Inbox settings for Users
  * @param string userId ID of user to assign all emails for this account
  * @param strings userName Name of account, for Sugar purposes
  * @param bool forceSave Default true.  Flag to save errored settings.
  * @return boolean true on success, false on fail
  */
 function savePersonalEmailAccount($userId = '', $userName = '', $forceSave = true)
 {
     $groupId = $userId;
     $accountExists = false;
     if (isset($_REQUEST['ie_id']) && !empty($_REQUEST['ie_id'])) {
         $this->retrieve($_REQUEST['ie_id']);
         $accountExists = true;
     }
     $ie_name = $_REQUEST['ie_name'];
     $this->is_personal = 1;
     $this->name = $ie_name;
     $this->group_id = $groupId;
     $this->status = $_REQUEST['ie_status'];
     $this->server_url = trim($_REQUEST['server_url']);
     $this->email_user = trim($_REQUEST['email_user']);
     if (!empty($_REQUEST['email_password'])) {
         $this->email_password = html_entity_decode($_REQUEST['email_password'], ENT_QUOTES);
     }
     $this->port = trim($_REQUEST['port']);
     $this->protocol = $_REQUEST['protocol'];
     if ($this->protocol == "pop3") {
         $_REQUEST['mailbox'] = "INBOX";
     }
     $this->mailbox = $_REQUEST['mailbox'];
     $this->mailbox_type = 'pick';
     // forcing this
     if (!empty($userId)) {
         $teamId = $_REQUEST['ie_team'] == '-1' ? User::getPrivateTeam($userId) : $_REQUEST['ie_team'];
         $this->team_id = $teamId;
         $this->team_set_id = $this->getTeamSetIdForTeams($teamId);
     }
     if (isset($_REQUEST['ssl']) && $_REQUEST['ssl'] == 1) {
         $useSsl = true;
     } else {
         $useSsl = false;
     }
     $this->service = '::::::::::';
     if ($forceSave) {
         $id = $this->save();
         // saving here to prevent user from having to re-enter all the info in case of error
         $this->retrieve($id);
     }
     $this->protocol = $_REQUEST['protocol'];
     // need to set this again since we safe the "service" string to empty explode values
     $opts = $this->getSessionConnectionString($this->server_url, $this->email_user, $this->port, $this->protocol);
     $detectedOpts = $this->findOptimumSettings($useSsl);
     //If $detectedOpts is empty, there was an error connecting, so clear $opts. If $opts was empty, use $detectedOpts
     if (empty($opts) || empty($detectedOpts) || empty($detectedOpts['good']) && empty($detectedOpts['serial'])) {
         $opts = $detectedOpts;
     }
     $delimiter = $this->getSessionInboundDelimiterString($this->server_url, $this->email_user, $this->port, $this->protocol);
     if (isset($opts['serial']) && !empty($opts['serial'])) {
         $this->service = $opts['serial'];
         if (isset($_REQUEST['mark_read']) && $_REQUEST['mark_read'] == 1) {
             $this->delete_seen = 0;
         } else {
             $this->delete_seen = 1;
         }
         // handle stored_options serialization
         if (isset($_REQUEST['only_since']) && $_REQUEST['only_since'] == 1) {
             $onlySince = true;
         } else {
             $onlySince = false;
         }
         $focusUser = BeanFactory::getBean('Users', $groupId);
         $mailerId = isset($_REQUEST['outbound_email']) ? $_REQUEST['outbound_email'] : "";
         $oe = new OutboundEmail();
         $oe->getSystemMailerSettings($focusUser, $mailerId);
         $stored_options = array();
         $stored_options['from_name'] = trim($_REQUEST['from_name']);
         $stored_options['from_addr'] = trim($_REQUEST['from_addr']);
         $stored_options['reply_to_addr'] = trim($_REQUEST['reply_to_addr']);
         if (!$this->isPop3Protocol()) {
             $stored_options['trashFolder'] = isset($_REQUEST['trashFolder']) ? trim($_REQUEST['trashFolder']) : "";
             $stored_options['sentFolder'] = isset($_REQUEST['sentFolder']) ? trim($_REQUEST['sentFolder']) : "";
         }
         // if
         $stored_options['only_since'] = $onlySince;
         $stored_options['filter_domain'] = '';
         $storedOptions['folderDelimiter'] = $delimiter;
         $stored_options['outbound_email'] = isset($_REQUEST['outbound_email']) ? $_REQUEST['outbound_email'] : $oe->id;
         $this->stored_options = base64_encode(serialize($stored_options));
         $ieId = $this->save();
         //If this is the first personal account the user has setup mark it as default for them.
         $currentIECount = $this->getUserPersonalAccountCount($focusUser);
         if ($currentIECount == 1) {
             $this->setUsersDefaultOutboundServerId($focusUser, $ieId);
         }
         return true;
     } else {
         // could not find opts, no save
         $GLOBALS['log']->debug('-----> InboundEmail could not find optimums for User: ' . $ie_name);
         return false;
     }
 }