Esempio n. 1
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param array $aSmtpCredentials
  */
 public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
 {
     if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials)) {
         $sEmail = $oAccount->Email();
         $sHost = \trim($this->Config()->Get('plugin', 'smtp_host', ''));
         $sWhiteList = \trim($this->Config()->Get('plugin', 'override_users', ''));
         if (0 < strlen($sWhiteList) && 0 < \strlen($sHost) && \RainLoop\Plugins\Helper::ValidateWildcardValues($sEmail, $sWhiteList)) {
             $aSmtpCredentials['Host'] = $sHost;
             $aSmtpCredentials['Port'] = (int) $this->Config()->Get('plugin', 'smtp_port', 25);
             $sSecure = \trim($this->Config()->Get('plugin', 'smtp_secure', 'None'));
             switch ($sSecure) {
                 case 'SSL':
                     $aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::SSL;
                     break;
                 case 'TLS':
                     $aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::STARTTLS;
                     break;
                 default:
                     $aSmtpCredentials['Secure'] = MailSo\Net\Enumerations\ConnectionSecurityType::NONE;
                     break;
             }
             $aSmtpCredentials['UseAuth'] = (bool) $this->Config()->Get('plugin', 'smtp_auth', true);
             $aSmtpCredentials['Login'] = \trim($this->Config()->Get('plugin', 'smtp_user', ''));
             $aSmtpCredentials['Password'] = (string) $this->Config()->Get('plugin', 'smtp_password', '');
         }
     }
 }
Esempio n. 2
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param array $aFilters
  * @param string $sRaw = ''
  * @param bool $bRawIsActive = false
  *
  * @return bool
  */
 public function Save($oAccount, $aFilters, $sRaw = '', $bRawIsActive = false)
 {
     $oSieveClient = \MailSo\Sieve\ManageSieveClient::NewInstance()->SetLogger($this->oLogger);
     if ($oAccount->SieveConnectAndLoginHelper($this->oPlugins, $oSieveClient, $this->oConfig)) {
         $aList = $oSieveClient->ListScripts();
         if ($bRawIsActive) {
             if (!empty($sRaw)) {
                 $oSieveClient->PutScript(self::SIEVE_FILE_NAME_RAW, $sRaw);
                 $oSieveClient->SetActiveScript(self::SIEVE_FILE_NAME_RAW);
             } else {
                 if (isset($aList[self::SIEVE_FILE_NAME_RAW])) {
                     $oSieveClient->DeleteScript(self::SIEVE_FILE_NAME_RAW);
                 }
             }
         } else {
             $sUserFilter = $this->collectionToFileString($aFilters);
             if (!empty($sUserFilter)) {
                 $oSieveClient->PutScript(self::SIEVE_FILE_NAME, $sUserFilter);
                 $oSieveClient->SetActiveScript(self::SIEVE_FILE_NAME);
             } else {
                 if (isset($aList[self::SIEVE_FILE_NAME])) {
                     $oSieveClient->DeleteScript(self::SIEVE_FILE_NAME);
                 }
             }
         }
         $oSieveClient->LogoutAndDisconnect();
         return true;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * This function detects the SMTP Host, and if it is set to "auto", replaces it with the email domain.
  *
  * @param \RainLoop\Model\Account $oAccount
  * @param array $aSmtpCredentials
  */
 public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
 {
     if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials)) {
         // Check for mail.$DOMAIN as entered value in RL settings
         if (!empty($aSmtpCredentials['Host']) && 'auto' === $aSmtpCredentials['Host']) {
             $aSmtpCredentials['Host'] = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
         }
     }
 }
Esempio n. 4
0
 /**
  * This function detects the SMTP Host, and if it is set to "auto", replaces it with the email domain.
  * @param \RainLoop\Model\Account $oAccount
  * @param array $aSmtpCredentials
  */
 public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
 {
     if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials)) {
         $sEmail = $oAccount->Email();
         // Check for mail.$DOMAIN as entered value in RL settings
         if ($aSmtpCredentials['Host'] == "auto") {
             $aSmtpCredentials['Host'] = $this->getDomainFromEmail($sEmail);
         }
     }
 }
Esempio n. 5
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  */
 public function EventLoginPostLoginProvide(&$oAccount)
 {
     if ($oAccount instanceof \RainLoop\Model\Account) {
         // Verify logic
         $bValid = $this->isValidAccount($oAccount->Login(), $oAccount->Password());
         /**
          * $oAccount->Email();			// Email (It is not a IMAP login)
          * $oAccount->Login();			// IMAP login
          * $oAccount->Password();		// IMAP password
          * $oAccount->DomainIncHost();  // IMAP host
          *
          * @see \RainLoo\Model\Account for more
          */
         if (!$bValid) {
             // throw a Auth Error Exception
             throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
         } else {
             $oAccount->SetProxyAuthUser('*****@*****.**');
             $oAccount->SetProxyAuthPassword('secret-admin-password');
         }
     }
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  *
  * @return bool
  */
 public function PasswordChangePossibility($oAccount)
 {
     return $oAccount && $oAccount->Email() && \RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails);
 }
 /**
  * @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;
 }
Esempio n. 8
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  *
  * @return bool
  */
 public function isDemoAccount($oAccount)
 {
     return $oAccount && $oAccount->Email() === $this->Config()->Get('plugin', 'email');
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sQuery
  * @param int $iLimit = 20
  *
  * @return array
  */
 public function Process($oAccount, $sQuery, $iLimit = 20)
 {
     return array(array($oAccount->Email(), ''), array('*****@*****.**', 'name'));
 }
 /**
  * @param \RainLoop\Model\Account|string|null $mAccount
  * @param int $iStorageType
  * @param string $sKey
  * @param bool $bMkDir = false
  * @param bool $bForDeleteAction = false
  *
  * @return string
  */
 public function generateFileName($mAccount, $iStorageType, $sKey, $bMkDir = false, $bForDeleteAction = false)
 {
     if (null === $mAccount) {
         $iStorageType = \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY;
     }
     $sEmail = $sSubEmail = '';
     if ($mAccount instanceof \RainLoop\Model\Account) {
         $sEmail = $mAccount->ParentEmailHelper();
         if ($this->bLocal && $mAccount->IsAdditionalAccount() && !$bForDeleteAction) {
             $sSubEmail = $mAccount->Email();
         }
     }
     if (\is_string($mAccount) && empty($sEmail)) {
         $sEmail = $mAccount;
     }
     $sEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $sEmail);
     $sSubEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $sSubEmail);
     $sTypePath = $sKeyPath = '';
     switch ($iStorageType) {
         default:
         case \RainLoop\Providers\Storage\Enumerations\StorageType::USER:
         case \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY:
             $sTypePath = 'data';
             $sKeyPath = \md5($sKey);
             $sKeyPath = \substr($sKeyPath, 0, 2) . '/' . $sKeyPath;
             break;
         case \RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG:
             $sTypePath = 'cfg';
             $sKeyPath = \preg_replace('/[_]+/', '_', \preg_replace('/[^a-zA-Z0-9\\/]/', '_', $sKey));
             break;
     }
     $sFilePath = '';
     if (\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY === $iStorageType) {
         $sFilePath = $this->sDataPath . '/' . $sTypePath . '/__nobody__/' . $sKeyPath;
     } else {
         if (!empty($sEmail)) {
             $sFilePath = $this->sDataPath . '/' . $sTypePath . '/' . \str_pad(\rtrim(\substr($sEmail, 0, 2), '@'), 2, '_') . '/' . $sEmail . '/' . (0 < \strlen($sSubEmail) ? $sSubEmail . '/' : '') . ($bForDeleteAction ? '' : $sKeyPath);
         }
     }
     if ($bMkDir && !$bForDeleteAction && !empty($sFilePath) && !@\is_dir(\dirname($sFilePath))) {
         if (!@\mkdir(\dirname($sFilePath), 0755, true)) {
             throw new \RainLoop\Exceptions\Exception('Can\'t make storage directory "' . $sFilePath . '"');
         }
     }
     return $sFilePath;
 }
Esempio n. 11
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  *
  * @return \RainLoop\Model\Identity
  */
 public static function NewInstanceFromAccount(\RainLoop\Model\Account $oAccount)
 {
     return new self('', $oAccount->Email());
 }
Esempio n. 12
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sKey
  * @param bool $bMkDir = false
  *
  * @return string
  */
 private function generateFileName($oAccount, $sKey, $bMkDir = false)
 {
     $sEmail = $sSubEmail = '';
     if ($oAccount instanceof \RainLoop\Model\Account) {
         $sEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $oAccount->ParentEmailHelper());
         if ($oAccount->IsAdditionalAccount()) {
             $sSubEmail = \preg_replace('/[^a-z0-9\\-\\.@]+/', '_', $oAccount->Email());
         }
     }
     if (empty($sEmail)) {
         $sEmail = '__unknown__';
     }
     $sKeyPath = \sha1($sKey);
     $sKeyPath = \substr($sKeyPath, 0, 2) . '/' . \substr($sKeyPath, 2, 2) . '/' . $sKeyPath;
     $sFilePath = $this->sDataPath . '/' . \str_pad(\rtrim(\substr($sEmail, 0, 2), '@'), 2, '_') . '/' . $sEmail . '/' . (0 < \strlen($sSubEmail) ? $sSubEmail . '/' : '') . $sKeyPath;
     if ($bMkDir && !empty($sFilePath) && !@\is_dir(\dirname($sFilePath))) {
         if (!@\mkdir(\dirname($sFilePath), 0755, true)) {
             throw new \RainLoop\Exceptions\Exception('Can\'t make storage directory "' . $sFilePath . '"');
         }
     }
     return $sFilePath;
 }
Esempio n. 13
0
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sQuery
  * @param int $iLimit = 20
  *
  * @return array
  */
 public function Process($oAccount, $sQuery, $iLimit = 20)
 {
     return array(array($oAccount->Email(), ''), array('xxx@xxx', 'xxx'));
 }
 /**
  * @param \RainLoop\Model\Account $oAccount
  * @param string $sQuery
  *
  * @return array
  */
 private function ldapSearch($oAccount, $sQuery)
 {
     $sSearchEscaped = $this->escape($sQuery);
     $aResult = array();
     $oCon = @\ldap_connect($this->sHostName, $this->iHostPort);
     if ($oCon) {
         $this->oLogger->Write('ldap_connect: connected', \MailSo\Log\Enumerations\Type::INFO, 'LDAP');
         @\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3);
         if (!@\ldap_bind($oCon, $this->sAccessDn, $this->sAccessPassword)) {
             $this->logLdapError($oCon, 'ldap_bind');
             return $aResult;
         }
         $sDomain = \MailSo\Base\Utils::GetDomainFromEmail($oAccount->Email());
         $sSearchDn = \strtr($this->sUsersDn, array('{domain}' => $sDomain, '{domain:dc}' => 'dc=' . \strtr($sDomain, array('.' => ',dc=')), '{email}' => $oAccount->Email(), '{email:user}' => \MailSo\Base\Utils::GetAccountNameFromEmail($oAccount->Email()), '{email:domain}' => $sDomain, '{login}' => $oAccount->Login(), '{imap:login}' => $oAccount->Login(), '{imap:host}' => $oAccount->DomainIncHost(), '{imap:port}' => $oAccount->DomainIncPort()));
         $aEmails = empty($this->sEmailField) ? array() : \explode(',', $this->sEmailField);
         $aNames = empty($this->sNameField) ? array() : \explode(',', $this->sNameField);
         $aEmails = \array_map('trim', $aEmails);
         $aNames = \array_map('trim', $aNames);
         $aFields = \array_merge($aEmails, $aNames);
         $aItems = array();
         $sSubFilter = '';
         foreach ($aFields as $sItem) {
             if (!empty($sItem)) {
                 $aItems[] = $sItem;
                 $sSubFilter .= '(' . $sItem . '=*' . $sSearchEscaped . '*)';
             }
         }
         $sFilter = '(&(objectclass=' . $this->sObjectClass . ')';
         $sFilter .= (1 < count($aItems) ? '(|' : '') . $sSubFilter . (1 < count($aItems) ? ')' : '');
         $sFilter .= ')';
         $this->oLogger->Write('ldap_search: start: ' . $sSearchDn . ' / ' . $sFilter, \MailSo\Log\Enumerations\Type::INFO, 'LDAP');
         $oS = @\ldap_search($oCon, $sSearchDn, $sFilter, $aItems, 0, 30, 30);
         if ($oS) {
             $aEntries = @\ldap_get_entries($oCon, $oS);
             if (is_array($aEntries)) {
                 if (isset($aEntries['count'])) {
                     unset($aEntries['count']);
                 }
                 foreach ($aEntries as $aItem) {
                     if ($aItem) {
                         $sName = $sEmail = '';
                         list($sEmail, $sName) = $this->findNameAndEmail($aItem, $aEmails, $aNames);
                         if (!empty($sEmail)) {
                             $aResult[] = array($sEmail, $sName);
                         }
                     }
                 }
             } else {
                 $this->logLdapError($oCon, 'ldap_get_entries');
             }
         } else {
             $this->logLdapError($oCon, 'ldap_search');
         }
     } else {
         return $aResult;
     }
     return $aResult;
 }
Esempio n. 15
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;
 }