/**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sQuery
  * @param int $iLimit = 20
  *
  * @return array
  */
 public function Process($oAccount, $sQuery, $iLimit = 20)
 {
     $aResult = array();
     try {
         if (!$oAccount || !\RainLoop\Utils::IsOwnCloud() || !\class_exists('\\OCP\\Contacts') || !\OCP\Contacts::isEnabled() || !\class_exists('\\OCP\\User') || !\OCP\User::isLoggedIn()) {
             return $aResult;
         }
         $aSearchResult = \OCP\Contacts::search($sQuery, array('FN', 'EMAIL'));
         //$this->oLogger->WriteDump($aSearchResult);
         $aPreResult = array();
         if (\is_array($aSearchResult) && 0 < \count($aSearchResult)) {
             foreach ($aSearchResult as $aContact) {
                 if (0 >= $iLimit) {
                     break;
                 }
                 $sUid = empty($aContact['UID']) ? '' : $aContact['UID'];
                 if (!empty($sUid)) {
                     $sFullName = isset($aContact['FN']) ? \trim($aContact['FN']) : '';
                     $mEmails = isset($aContact['EMAIL']) ? $aContact['EMAIL'] : '';
                     if (!\is_array($mEmails)) {
                         $mEmails = array($mEmails);
                     }
                     if (!isset($aPreResult[$sUid])) {
                         $aPreResult[$sUid] = array();
                     }
                     foreach ($mEmails as $sEmail) {
                         $sEmail = \trim($sEmail);
                         if (!empty($sEmail)) {
                             $iLimit--;
                             $aPreResult[$sUid][] = array($sEmail, $sFullName);
                         }
                     }
                 }
             }
             $aPreResult = \array_values($aPreResult);
             //				$this->oLogger->WriteDump($aPreResult);
             foreach ($aPreResult as $aData) {
                 foreach ($aData as $aSubData) {
                     $aResult[] = $aSubData;
                 }
             }
         }
         unset($aSearchResult, $aPreResult);
     } catch (\Exception $oException) {
         if ($this->oLogger) {
             $this->oLogger->WriteException($oException);
         }
     }
     return $aResult;
 }
 /**
  * @return string
  */
 public function ServiceOwnCloudAuth()
 {
     if (!\RainLoop\Utils::IsOwnCloud() || !isset($_ENV['___rainloop_owncloud_email']) || !isset($_ENV['___rainloop_owncloud_password']) || empty($_ENV['___rainloop_owncloud_email'])) {
         $this->oActions->SetAuthLogoutToken();
         $this->oActions->Location('./');
         return '';
     }
     $bLogout = true;
     $sEmail = $_ENV['___rainloop_owncloud_email'];
     $sPassword = $_ENV['___rainloop_owncloud_password'];
     try {
         $oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
         $this->oActions->AuthToken($oAccount);
         $bLogout = !$oAccount instanceof \RainLoop\Model\Account;
     } catch (\Exception $oException) {
         $this->oActions->Logger()->WriteException($oException);
     }
     if ($bLogout) {
         $this->oActions->SetAuthLogoutToken();
     }
     $this->oActions->Location('./');
     return '';
 }
Example #3
0
 /**
  * @return \RainLoop\Service
  */
 private function localHandle()
 {
     if (!\class_exists('MailSo\\Version')) {
         return $this;
     }
     $this->oActions->BootStart();
     $sResult = '';
     $bCached = false;
     $sQuery = $this->oActions->ParseQueryAuthString();
     $this->oActions->Plugins()->RunHook('filter.http-query', array(&$sQuery));
     $aPaths = \explode('/', $sQuery);
     $this->oActions->Plugins()->RunHook('filter.http-paths', array(&$aPaths));
     $bAdmin = false;
     $sAdminPanelHost = $this->oActions->Config()->Get('security', 'admin_panel_host', '');
     if (empty($sAdminPanelHost)) {
         $bAdmin = !empty($aPaths[0]) && \in_array(\strtolower($aPaths[0]), array('admin', 'cp'));
     } else {
         if (empty($aPaths[0]) && \MailSo\Base\Utils::StrToLowerIfAscii($sAdminPanelHost) === \MailSo\Base\Utils::StrToLowerIfAscii($this->oHttp->GetHost())) {
             $bAdmin = true;
         }
     }
     if ($this->oHttp->IsPost()) {
         $this->oHttp->ServerNoCache();
     }
     if ($bAdmin && !$this->oActions->Config()->Get('security', 'allow_admin_panel', true)) {
         echo $this->oServiceActions->ErrorTemplates('Access Denied.', 'Access to the RainLoop Webmail Admin Panel is not allowed!', true);
         return $this;
     }
     $bIndex = true;
     if (0 < \count($aPaths) && !empty($aPaths[0]) && !$bAdmin && 'index' !== $aPaths[0]) {
         $bIndex = false;
         $sMethodName = 'Service' . $aPaths[0];
         if (\method_exists($this->oServiceActions, $sMethodName) && \is_callable(array($this->oServiceActions, $sMethodName))) {
             $this->oServiceActions->SetQuery($sQuery)->SetPaths($aPaths);
             $sResult = \call_user_func(array($this->oServiceActions, $sMethodName));
         } else {
             if (!$this->oActions->Plugins()->RunAdditionalPart($aPaths[0], $aPaths)) {
                 $bIndex = true;
             }
         }
     }
     if ($bIndex) {
         @\header('Content-Security-Policy:');
         @\header_remove('Content-Security-Policy');
         @header('Content-Type: text/html; charset=utf-8');
         $this->oHttp->ServerNoCache();
         if (!@\is_dir(APP_DATA_FOLDER_PATH) || !@\is_writable(APP_DATA_FOLDER_PATH)) {
             echo $this->oServiceActions->ErrorTemplates('Permission denied!', 'RainLoop Webmail cannot access to the data folder "' . APP_DATA_FOLDER_PATH . '"');
             return $this;
         }
         $aTemplateParameters = $this->indexTemplateParameters($bAdmin);
         $sCacheFileName = '';
         if ($this->oActions->Config()->Get('labs', 'cache_system_data', true)) {
             $sCacheFileName = 'TMPL:' . $aTemplateParameters['{{BaseHash}}'];
             $sResult = $this->oActions->Cacher()->Get($sCacheFileName);
         }
         if (0 === \strlen($sResult)) {
             //				$aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false);
             $sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH . 'app/templates/Index.html'), $aTemplateParameters);
             $sResult = \RainLoop\Utils::ClearHtmlOutput($sResult);
             if (0 < \strlen($sCacheFileName)) {
                 $this->oActions->Cacher()->Set($sCacheFileName, $sResult);
             }
         } else {
             $bCached = true;
         }
         $sResult .= '<!--';
         $sResult .= ' [time:' . \substr(\microtime(true) - APP_START, 0, 6);
         //			$sResult .= '][version:'.APP_VERSION;
         if ($this->oActions->IsOpen()) {
             $sResult .= '][AGPLv3';
         }
         $sResult .= '][cached:' . ($bCached ? 'true' : 'false');
         //			$sResult .= '][hash:'.$aTemplateParameters['{{BaseHash}}'];
         //			$sResult .= '][session:'.\md5(\RainLoop\Utils::GetShortToken());
         if (\RainLoop\Utils::IsOwnCloud()) {
             $sResult .= '][owncloud:true';
         }
         $sResult .= '] //-->';
     }
     // Output result
     echo $sResult;
     unset($sResult);
     $this->oActions->BootEnd();
     return $this;
 }
 /**
  * @param bool $bAdmin
  * @param \RainLoop\Model\Account $oAccount = null
  *
  * @return array
  */
 public function Capa($bAdmin, $oAccount = null)
 {
     $oConfig = $this->Config();
     $aResult = array();
     if ($oConfig->Get('capa', 'folders', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::FOLDERS;
         if ($oConfig->Get('capa', 'messagelist_actions', true)) {
             $aResult[] = \RainLoop\Enumerations\Capa::MESSAGELIST_ACTIONS;
             if ($oConfig->Get('capa', 'dangerous_actions', true)) {
                 $aResult[] = \RainLoop\Enumerations\Capa::DANGEROUS_ACTIONS;
             }
         }
     }
     if ($oConfig->Get('capa', 'reload', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::RELOAD;
     }
     if ($oConfig->Get('capa', 'quota', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::QUOTA;
     }
     if ($oConfig->Get('capa', 'settings', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::SETTINGS;
         if ($oConfig->Get('webmail', 'allow_additional_accounts', false)) {
             $aResult[] = \RainLoop\Enumerations\Capa::ADDITIONAL_ACCOUNTS;
         }
         if ($oConfig->Get('webmail', 'allow_additional_identities', false)) {
             $aResult[] = \RainLoop\Enumerations\Capa::IDENTITIES;
         }
         if ($oConfig->Get('capa', 'x-templates', true)) {
             $aResult[] = \RainLoop\Enumerations\Capa::TEMPLATES;
         }
         if ($oConfig->Get('webmail', 'allow_themes', false)) {
             $aResult[] = \RainLoop\Enumerations\Capa::THEMES;
         }
         if ($oConfig->Get('webmail', 'allow_user_background', false)) {
             $aResult[] = \RainLoop\Enumerations\Capa::USER_BACKGROUND;
         }
         if ($oConfig->Get('security', 'openpgp', false)) {
             $aResult[] = \RainLoop\Enumerations\Capa::OPEN_PGP;
         }
         if ($oConfig->Get('capa', 'filters', false)) {
             $aResult[] = \RainLoop\Enumerations\Capa::FILTERS;
             if ($bAdmin || $oAccount && $oAccount->Domain()->UseSieve()) {
                 $aResult[] = \RainLoop\Enumerations\Capa::SIEVE;
             }
         }
     }
     if ($oConfig->Get('security', 'allow_two_factor_auth', false) && ($bAdmin || $oAccount && !$oAccount->IsAdditionalAccount())) {
         $aResult[] = \RainLoop\Enumerations\Capa::TWO_FACTOR;
         if ($oConfig->Get('security', 'force_two_factor_auth', false) && ($bAdmin || $oAccount && !$oAccount->IsAdditionalAccount())) {
             $aResult[] = \RainLoop\Enumerations\Capa::TWO_FACTOR_FORCE;
         }
     }
     if ($oConfig->Get('capa', 'help', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::HELP;
     }
     if ($oConfig->Get('capa', 'attachments_actions', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::ATTACHMENTS_ACTIONS;
     }
     if ($oConfig->Get('capa', 'message_actions', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::MESSAGE_ACTIONS;
     }
     if ($oConfig->Get('capa', 'composer', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::COMPOSER;
         if ($oConfig->Get('capa', 'contacts', true)) {
             $aResult[] = \RainLoop\Enumerations\Capa::CONTACTS;
         }
     }
     if ($oConfig->Get('capa', 'search', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::SEARCH;
         if ($oConfig->Get('capa', 'search_adv', true)) {
             $aResult[] = \RainLoop\Enumerations\Capa::SEARCH_ADV;
         }
     }
     if ($oConfig->Get('labs', 'allow_gravatar', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::GRAVATAR;
     }
     if ($oConfig->Get('interface', 'show_attachment_thumbnail', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::ATTACHMENT_THUMBNAILS;
     }
     if ($oConfig->Get('labs', 'allow_prefetch', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::PREFETCH;
     }
     if (!\RainLoop\Utils::IsOwnCloud()) {
         $aResult[] = \RainLoop\Enumerations\Capa::AUTOLOGOUT;
     }
     return $aResult;
 }
Example #5
0
 /**
  * @return string
  */
 public static function WebPath()
 {
     $sAppPath = '';
     if (\RainLoop\Utils::IsOwnCloud()) {
         if (\class_exists('OC_App')) {
             $sAppPath = \rtrim(\trim(\OC_App::getAppWebPath('rainloop')), '\\/') . '/app/';
         }
         if (empty($sAppPath)) {
             $sUrl = \MailSo\Base\Http::SingletonInstance()->GetUrl();
             if ($sUrl && \preg_match('/\\/index\\.php\\/apps\\/rainloop/', $sUrl)) {
                 $sAppPath = \preg_replace('/\\/index\\.php\\/apps\\/rainloop.+$/', '/apps/rainloop/app/', $sUrl);
             }
         }
     }
     return $sAppPath;
 }
Example #6
0
 /**
  * @param bool $bAdmin
  * @param \RainLoop\Model\Account $oAccount = null
  *
  * @return array
  */
 public function Capa($bAdmin, $oAccount = null)
 {
     $oConfig = $this->Config();
     $aResult = array();
     if ($oConfig->Get('capa', 'filters', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::FILTERS;
         if ($bAdmin || $oAccount && $oAccount->Domain()->UseSieve()) {
             $aResult[] = \RainLoop\Enumerations\Capa::SIEVE;
         }
     }
     //		if ($oConfig->Get('capa', 'templates', true))
     //		{
     //			$aResult[] = \RainLoop\Enumerations\Capa::TEMPLATES;
     //		}
     if ($oConfig->Get('webmail', 'allow_additional_accounts', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::ADDITIONAL_ACCOUNTS;
     }
     if ($oConfig->Get('security', 'allow_two_factor_auth', false) && ($bAdmin || $oAccount && !$oAccount->IsAdditionalAccount())) {
         $aResult[] = \RainLoop\Enumerations\Capa::TWO_FACTOR;
     }
     if ($oConfig->Get('labs', 'allow_gravatar', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::GRAVATAR;
     }
     if ($oConfig->Get('interface', 'show_attachment_thumbnail', true)) {
         $aResult[] = \RainLoop\Enumerations\Capa::ATTACHMENT_THUMBNAILS;
     }
     if ($oConfig->Get('labs', 'allow_prefetch', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::PREFETCH;
     }
     if ($oConfig->Get('webmail', 'allow_themes', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::THEMES;
     }
     if ($oConfig->Get('webmail', 'allow_user_background', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::USER_BACKGROUND;
     }
     if ($oConfig->Get('security', 'openpgp', false)) {
         $aResult[] = \RainLoop\Enumerations\Capa::OPEN_PGP;
     }
     if (!\RainLoop\Utils::IsOwnCloud()) {
         $aResult[] = \RainLoop\Enumerations\Capa::AUTOLOGOUT;
     }
     return $aResult;
 }