/** * @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; }
/** * @param \RainLoop\Plugins\Manager $oPlugins * @param \MailSo\Sieve\ManageSieveClient $oSieveClient * @param \RainLoop\Application $oConfig */ public function SieveConnectAndLoginHelper($oPlugins, $oSieveClient, $oConfig) { $bLogin = false; $aSieveCredentials = array('UseConnect' => true, 'UseAuth' => true, 'Host' => $this->DomainSieveHost(), 'Port' => $this->DomainSievePort(), 'Secure' => $this->DomainSieveSecure(), 'Login' => $this->IncLogin(), 'Password' => $this->Password(), 'VerifySsl' => !!$oConfig->Get('ssl', 'verify_certificate', false), 'AllowSelfSigned' => !!$oConfig->Get('ssl', 'allow_self_signed', true)); $oPlugins->RunHook('filter.sieve-credentials', array($this, &$aSieveCredentials)); $oPlugins->RunHook('event.sieve-pre-connect', array($this, $aSieveCredentials['UseConnect'], $aSieveCredentials)); if ($aSieveCredentials['UseConnect'] && $oSieveClient) { $oSieveClient->Connect($aSieveCredentials['Host'], $aSieveCredentials['Port'], $aSieveCredentials['Secure'], $aSieveCredentials['VerifySsl'], $aSieveCredentials['AllowSelfSigned']); } $oPlugins->RunHook('event.sieve-post-connect', array($this, $aSieveCredentials['UseConnect'], $aSieveCredentials)); $oPlugins->RunHook('event.sieve-pre-login', array($this, $aSieveCredentials['UseAuth'], $aSieveCredentials)); if ($aSieveCredentials['UseAuth']) { $oSieveClient->Login($aSieveCredentials['Login'], $aSieveCredentials['Password']); $bLogin = true; } $oPlugins->RunHook('event.sieve-post-login', array($this, $aSieveCredentials['UseAuth'], $bLogin, $aSieveCredentials)); return $bLogin; }
/** * @param CAccount $oAccount * @return \MailSo\Sieve\ManageSieveClient|false */ protected function _getSieveDriver(CAccount $oAccount) { $oSieve = false; if ($oAccount instanceof CAccount) { if (!isset($this->aSieves[$oAccount->Email])) { $oSieve = \MailSo\Sieve\ManageSieveClient::NewInstance(); $oSieve->SetLogger(\CApi::MailSoLogger()); $this->aSieves[$oAccount->Email] = $oSieve; } else { $oSieve = $this->aSieves[$oAccount->Email]; } } return $oSieve; }
/** * @return array */ public function DoAdminDomainTest() { $this->IsAdminLoggined(); $bImapResult = false; $sImapErrorDesc = ''; $bSmtpResult = false; $sSmtpErrorDesc = ''; $bSieveResult = false; $sSieveErrorDesc = ''; $iImapTime = 0; $iSmtpTime = 0; $iSieveTime = 0; $iConnectionTimeout = 5; $oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this, 'domain-test-connection.de'); if ($oDomain) { try { $oImapClient = \MailSo\Imap\ImapClient::NewInstance()->SetLogger($this->Logger()); $oImapClient->SetTimeOuts($iConnectionTimeout); $iTime = \microtime(true); $oImapClient->Connect($oDomain->IncHost(), $oDomain->IncPort(), $oDomain->IncSecure(), !!$this->Config()->Get('ssl', 'verify_certificate', false), !!$this->Config()->Get('ssl', 'allow_self_signed', true)); $iImapTime = \microtime(true) - $iTime; $oImapClient->Disconnect(); $bImapResult = true; } catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) { $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $sImapErrorDesc = $oException->getSocketMessage(); if (empty($sImapErrorDesc)) { $sImapErrorDesc = $oException->getMessage(); } } catch (\Exception $oException) { $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $sImapErrorDesc = $oException->getMessage(); } if ($oDomain->OutUsePhpMail()) { $bSmtpResult = \MailSo\Base\Utils::FunctionExistsAndEnabled('mail'); if (!$bSmtpResult) { $sSmtpErrorDesc = 'PHP: mail() function is undefined'; } } else { try { $oSmtpClient = \MailSo\Smtp\SmtpClient::NewInstance()->SetLogger($this->Logger()); $oSmtpClient->SetTimeOuts($iConnectionTimeout); $iTime = \microtime(true); $oSmtpClient->Connect($oDomain->OutHost(), $oDomain->OutPort(), \MailSo\Smtp\SmtpClient::EhloHelper(), $oDomain->OutSecure(), !!$this->Config()->Get('ssl', 'verify_certificate', false), !!$this->Config()->Get('ssl', 'allow_self_signed', true)); $iSmtpTime = \microtime(true) - $iTime; $oSmtpClient->Disconnect(); $bSmtpResult = true; } catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) { $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $sSmtpErrorDesc = $oException->getSocketMessage(); if (empty($sSmtpErrorDesc)) { $sSmtpErrorDesc = $oException->getMessage(); } } catch (\Exception $oException) { $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $sSmtpErrorDesc = $oException->getMessage(); } } if ($oDomain->UseSieve()) { try { $oSieveClient = \MailSo\Sieve\ManageSieveClient::NewInstance()->SetLogger($this->Logger()); $oSieveClient->SetTimeOuts($iConnectionTimeout); $iTime = \microtime(true); $oSieveClient->Connect($oDomain->SieveHost(), $oDomain->SievePort(), $oDomain->SieveSecure(), !!$this->Config()->Get('ssl', 'verify_certificate', false), !!$this->Config()->Get('ssl', 'allow_self_signed', true)); $iSieveTime = \microtime(true) - $iTime; $oSieveClient->Disconnect(); $bSieveResult = true; } catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) { $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $sSieveErrorDesc = $oException->getSocketMessage(); if (empty($sSieveErrorDesc)) { $sSieveErrorDesc = $oException->getMessage(); } } catch (\Exception $oException) { $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $sSieveErrorDesc = $oException->getMessage(); } } else { $bSieveResult = true; } } return $this->DefaultResponse(__FUNCTION__, array('Imap' => $bImapResult ? true : $sImapErrorDesc, 'Smtp' => $bSmtpResult ? true : $sSmtpErrorDesc, 'Sieve' => $bSieveResult ? true : $sSieveErrorDesc)); }