Example #1
0
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * 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".
 ********************************************************************************/
global $current_user;
if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'personal') {
    if ($current_user->hasPersonalEmail()) {
        $ie = new InboundEmail();
        $beans = $ie->retrieveByGroupId($current_user->id);
        if (!empty($beans)) {
            foreach ($beans as $bean) {
                $bean->connectMailserver();
                $newMsgs = array();
                if ($bean->isPop3Protocol()) {
                    $newMsgs = $bean->getPop3NewMessagesToDownload();
                } else {
                    $newMsgs = $bean->getNewMessageIds();
                }
                //$newMsgs = $bean->getNewMessageIds();
                if (is_array($newMsgs)) {
                    foreach ($newMsgs as $k => $msgNo) {
                        $uid = $msgNo;
                        if ($bean->isPop3Protocol()) {
                            $uid = $bean->getUIDLForMessage($msgNo);
Example #2
0
 /**
  * returns an array of nodes that correspond to IMAP mailboxes.
  * @param bool $forceRefresh
  * @return object TreeView object
  */
 function getMailboxNodes()
 {
     global $sugar_config;
     global $current_user;
     global $app_strings;
     $tree = new Tree("frameFolders");
     $tree->tree_style = 'include/ytree/TreeView/css/check/tree.css';
     $nodes = array();
     $ie = new InboundEmail();
     $refreshOffset = $this->cacheTimeouts['folders'];
     // 5 mins.  this will be set via user prefs
     $rootNode = new ExtNode($app_strings['LBL_EMAIL_HOME_FOLDER'], $app_strings['LBL_EMAIL_HOME_FOLDER']);
     $rootNode->dynamicloadfunction = '';
     $rootNode->expanded = true;
     $rootNode->dynamic_load = true;
     $showFolders = unserialize(base64_decode($current_user->getPreference('showFolders', 'Emails')));
     if (empty($showFolders)) {
         $showFolders = array();
     }
     // INBOX NODES
     if ($current_user->hasPersonalEmail()) {
         $personals = $ie->retrieveByGroupId($current_user->id);
         foreach ($personals as $k => $personalAccount) {
             if (in_array($personalAccount->id, $showFolders)) {
                 // check for cache value
                 $cacheRoot = sugar_cached("modules/Emails/{$personalAccount->id}");
                 $this->preflightEmailCache($cacheRoot);
                 if ($this->validCacheFileExists($personalAccount->id, 'folders', "folders.php")) {
                     $mailboxes = $this->getMailBoxesFromCacheValue($personalAccount);
                 } else {
                     $mailboxes = $personalAccount->getMailboxes();
                 }
                 $acctNode = new ExtNode('Home::' . $personalAccount->name, $personalAccount->name);
                 $acctNode->dynamicloadfunction = '';
                 $acctNode->expanded = false;
                 $acctNode->set_property('cls', 'ieFolder');
                 $acctNode->set_property('ieId', $personalAccount->id);
                 $acctNode->set_property('protocol', $personalAccount->protocol);
                 if (array_key_exists('Home::' . $personalAccount->name, $this->folderStates)) {
                     if ($this->folderStates['Home::' . $personalAccount->name] == 'open') {
                         $acctNode->expanded = true;
                     }
                 }
                 $acctNode->dynamic_load = true;
                 $nodePath = $acctNode->_properties['id'];
                 foreach ($mailboxes as $k => $mbox) {
                     $acctNode->add_node($this->buildTreeNode($k, $k, $mbox, $personalAccount->id, $nodePath, false, $personalAccount));
                 }
                 $rootNode->add_node($acctNode);
             }
         }
     }
     // GROUP INBOX NODES
     $beans = $ie->retrieveAllByGroupId($current_user->id, false);
     foreach ($beans as $k => $groupAccount) {
         if (in_array($groupAccount->id, $showFolders)) {
             // check for cache value
             $cacheRoot = sugar_cached("modules/Emails/{$groupAccount->id}");
             $this->preflightEmailCache($cacheRoot);
             //$groupAccount->connectMailserver();
             if ($this->validCacheFileExists($groupAccount->id, 'folders', "folders.php")) {
                 $mailboxes = $this->getMailBoxesFromCacheValue($groupAccount);
             } else {
                 $mailboxes = $groupAccount->getMailBoxesForGroupAccount();
             }
             $acctNode = new ExtNode($groupAccount->name, "group.{$groupAccount->name}");
             $acctNode->dynamicloadfunction = '';
             $acctNode->expanded = false;
             $acctNode->set_property('isGroup', 'true');
             $acctNode->set_property('ieId', $groupAccount->id);
             $acctNode->set_property('protocol', $groupAccount->protocol);
             if (array_key_exists('Home::' . $groupAccount->name, $this->folderStates)) {
                 if ($this->folderStates['Home::' . $groupAccount->name] == 'open') {
                     $acctNode->expanded = true;
                 }
             }
             $acctNode->dynamic_load = true;
             $nodePath = $rootNode->_properties['id'] . "::" . $acctNode->_properties['id'];
             foreach ($mailboxes as $k => $mbox) {
                 $acctNode->add_node($this->buildTreeNode($k, $k, $mbox, $groupAccount->id, $nodePath, true, $groupAccount));
             }
             $rootNode->add_node($acctNode);
         }
     }
     // SugarFolder nodes
     /* SugarFolders are built at onload when the UI renders */
     $tree->add_node($rootNode);
     return $tree;
 }
///////////////////////////////////////////////////////////////////////////////
////	INBOUND EMAIL SETUP
if (function_exists('imap_open')) {
    require_once 'modules/Emails/Email.php';
    require_once 'modules/InboundEmail/InboundEmail.php';
    $ie = new InboundEmail();
    $email = new Email();
    $xtpl->assign('ROLLOVER', $email->rolloverStyle);
    $xtpl->assign('IE_HIDE', '');
    $xtpl->assign('IE_NAME', $focus->user_name);
    $xtpl->assign('GROUP_ID', $focus->id);
    $xtpl->assign('THEME', $theme);
    $status = get_select_options_with_id($app_list_strings['user_status_dom'], '');
    $mailbox_type = get_select_options_with_id($app_list_strings['dom_email_server_type'], '');
    $mailbox = 'INBOX';
    $beans = $ie->retrieveByGroupId($focus->id);
    if (!empty($beans)) {
        foreach ($beans as $bean) {
            // default MAILBOX value
            if (!empty($bean->mailbox)) {
                $mailbox = $bean->mailbox;
            }
            if (!empty($bean->stored_options)) {
                $storedOptions = unserialize(base64_decode($bean->stored_options));
                $from_name = $storedOptions['from_name'];
                $from_addr = $storedOptions['from_addr'];
                if ($storedOptions['only_since']) {
                    $only_since = 'CHECKED';
                } else {
                    $only_since = '';
                }
 public function retrieveByGroupId($group_id)
 {
     $inboundEmail = new InboundEmail();
     $result = $inboundEmail->retrieveByGroupId($group_id);
     $this->assertTrue(is_array($result));
     foreach ($result as $ie) {
         $this->assertInstanceOf('InboundEmail', $ie);
     }
 }