Read Receipt (#41)

This commit is contained in:
RainLoop Team 2014-01-04 04:20:07 +04:00
parent 1dc5a45564
commit b100560cd8
37 changed files with 883 additions and 461 deletions

View file

@ -3581,10 +3581,10 @@ class Actions
});
}
$oAccount = $this->initMailClientConnection();
$sForwardedFlag = $oAccount ? strtolower($oAccount->Domain()->ForwardFlag()) : '';
$this->initMailClientConnection();
$sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', '');
$sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
try
{
$aInboxInformation = $this->MailClient()->FolderInformation($sFolder, $sPrevUidNext, $aFlagsFilteredUids);
@ -3597,7 +3597,8 @@ class Actions
'IsSeen' => in_array('\\seen', $aLowerFlags),
'IsFlagged' => in_array('\\flagged', $aLowerFlags),
'IsAnswered' => in_array('\\answered', $aLowerFlags),
'IsForwarded' => 0 < strlen($sForwardedFlag) && in_array(strtolower($sForwardedFlag), $aLowerFlags)
'IsForwarded' => 0 < strlen($sForwardedFlag) && in_array(strtolower($sForwardedFlag), $aLowerFlags),
'IsReadReceipt' => 0 < strlen($sReadReceiptFlag) && in_array(strtolower($sReadReceiptFlag), $aLowerFlags)
);
}
}
@ -3763,6 +3764,7 @@ class Actions
$sBcc = $this->GetActionParam('Bcc', '');
$sSubject = $this->GetActionParam('Subject', '');
$bTextIsHtml = '1' === $this->GetActionParam('TextIsHtml', '0');
$bReadReceiptRequest = '1' === $this->GetActionParam('ReadReceiptRequest', '0');
$sText = $this->GetActionParam('Text', '');
$aAttachments = $this->GetActionParam('Attachments', null);
@ -3798,6 +3800,11 @@ class Actions
}
}
if ($bReadReceiptRequest)
{
$oMessage->SetReadReceipt($oAccount->Email());
}
$oMessage->SetSubject($sSubject);
$oToEmails = \MailSo\Mime\EmailCollection::NewInstance($sTo);
@ -3904,6 +3911,60 @@ class Actions
return $oMessage;
}
/**
* @param \RainLoop\Account $oAccount
*
* @return \MailSo\Mime\Message
*/
private function buildReadReceiptMessage($oAccount)
{
$sReadReceipt = $this->GetActionParam('ReadReceipt', '');
$sSubject = $this->GetActionParam('Subject', '');
$sText = $this->GetActionParam('Text', '');
if (empty($sReadReceipt) || empty($sSubject) || empty($sText))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::UnknownError);
}
$oMessage = \MailSo\Mime\Message::NewInstance();
$oMessage->RegenerateMessageId();
$oMessage->SetXMailer('RainLoop/'.APP_VERSION);
$oSettings = $this->SettingsProvider()->Load($oAccount);
$sDisplayName = \trim($oSettings->GetConf('DisplayName', ''));
$sReplyTo = \trim($oSettings->GetConf('ReplyTo', ''));
$oMessage->SetFrom(\MailSo\Mime\Email::NewInstance($oAccount->Email(), $sDisplayName));
if (!empty($sReplyTo))
{
$oReplyTo = \MailSo\Mime\EmailCollection::NewInstance($sReplyTo);
if ($oReplyTo && $oReplyTo->Count())
{
$oMessage->SetReplyTo($oReplyTo);
}
}
$oMessage->SetSubject($sSubject);
$oToEmails = \MailSo\Mime\EmailCollection::NewInstance($sReadReceipt);
if ($oToEmails && $oToEmails->Count())
{
$oMessage->SetTo($oToEmails);
}
$this->Plugins()->RunHook('filter.read-receipt-message-plain', array($oAccount, &$oMessage, &$sText));
$oMessage->AddText($sText, false);
$this->Plugins()->RunHook('filter.build-read-receipt-message', array(&$oMessage, $oAccount));
return $oMessage;
}
/**
* @return array
*/
@ -3972,6 +4033,108 @@ class Actions
return $this->DefaultResponse(__FUNCTION__, $mResult);
}
private function smptSendMessage($oAccount, $oMessage, $rMessageStream, $bAddHiddenRcpt = true)
{
$oRcpt = $oMessage->GetRcpt();
if ($oRcpt && 0 < $oRcpt->Count())
{
$this->Plugins()->RunHook('filter.message-rcpt', array($oAccount, &$oRcpt));
try
{
$oSmtpClient = \MailSo\Smtp\SmtpClient::NewInstance()->SetLogger($this->Logger());
$oFrom = $oMessage->GetFrom();
$sFrom = $oFrom instanceof \MailSo\Mime\Email ? $oFrom->GetEmail() : '';
$aSmtpCredentials = array(
'Ehlo' => \MailSo\Smtp\SmtpClient::EhloHelper(),
'Host' => $oAccount->Domain()->OutHost(),
'Port' => $oAccount->Domain()->OutPort(),
'Secure' => $oAccount->Domain()->OutSecure(),
'UseAuth' => $oAccount->Domain()->OutAuth(),
'From' => empty($sFrom) ? $oAccount->Email() : $sFrom,
'Login' => $oAccount->OutLogin(),
'Password' => $oAccount->Password(),
'HiddenRcpt' => array()
);
$this->Plugins()->RunHook('filter.smtp-credentials', array($oAccount, &$aSmtpCredentials));
if (!$bAddHiddenRcpt)
{
$aSmtpCredentials[] = array();
}
$bHookConnect = $bHookAuth = $bHookFrom = $bHookFrom = $bHookTo = $bHookData = $bHookLogoutAndDisconnect = false;
$this->Plugins()->RunHook('filter.smtp-connect', array($oAccount, $aSmtpCredentials,
&$oSmtpClient, $oMessage, &$oRcpt,
&$bHookConnect, &$bHookAuth, &$bHookFrom, &$bHookTo, &$bHookData, &$bHookLogoutAndDisconnect));
if (!$bHookConnect)
{
$oSmtpClient->Connect($aSmtpCredentials['Host'], $aSmtpCredentials['Port'],
$aSmtpCredentials['Ehlo'], $aSmtpCredentials['Secure']);
}
if (!$bHookAuth)
{
if ($aSmtpCredentials['UseAuth'])
{
$oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password']);
}
}
if (!$bHookFrom)
{
$oSmtpClient->MailFrom($aSmtpCredentials['From']);
}
if (!$bHookTo)
{
$aRcpt =& $oRcpt->GetAsArray();
foreach ($aRcpt as /* @var $oEmail \MailSo\Mime\Email */ $oEmail)
{
$oSmtpClient->Rcpt($oEmail->GetEmail());
}
if (isset($aSmtpCredentials['HiddenRcpt']) && is_array($aSmtpCredentials['HiddenRcpt']))
{
foreach ($aSmtpCredentials['HiddenRcpt'] as $sEmail)
{
if (\preg_match('/^[^@\s]+@[^@\s]+$/', $sEmail))
{
$oSmtpClient->Rcpt($sEmail);
}
}
}
}
if (!$bHookData)
{
$oSmtpClient->DataWithStream($rMessageStream);
}
if (!$bHookLogoutAndDisconnect)
{
$oSmtpClient->LogoutAndDisconnect();
}
}
catch (\MailSo\Net\Exceptions\ConnectionException $oException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ConnectionError, $oException);
}
catch (\MailSo\Smtp\Exceptions\LoginException $oException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError, $oException);
}
}
else
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::InvalidRecipients);
}
}
/**
* @return array
*/
@ -4003,189 +4166,97 @@ class Actions
if (false !== $iMessageStreamSize)
{
$oRcpt = $oMessage->GetRcpt();
if ($oRcpt && 0 < $oRcpt->Count())
$this->smptSendMessage($oAccount, $oMessage, $rMessageStream);
if (is_array($aDraftInfo) && 3 === count($aDraftInfo))
{
$this->Plugins()->RunHook('filter.message-rcpt', array($oAccount, &$oRcpt));
$sDraftInfoType = $aDraftInfo[0];
$sDraftInfoUid = $aDraftInfo[1];
$sDraftInfoFolder = $aDraftInfo[2];
try
{
$oSmtpClient = \MailSo\Smtp\SmtpClient::NewInstance()->SetLogger($this->Logger());
$oFrom = $oMessage->GetFrom();
$sFrom = $oFrom instanceof \MailSo\Mime\Email ? $oFrom->GetEmail() : '';
$aSmtpCredentials = array(
'Ehlo' => \MailSo\Smtp\SmtpClient::EhloHelper(),
'Host' => $oAccount->Domain()->OutHost(),
'Port' => $oAccount->Domain()->OutPort(),
'Secure' => $oAccount->Domain()->OutSecure(),
'UseAuth' => $oAccount->Domain()->OutAuth(),
'From' => empty($sFrom) ? $oAccount->Email() : $sFrom,
'Login' => $oAccount->OutLogin(),
'Password' => $oAccount->Password(),
'HiddenRcpt' => array()
);
$this->Plugins()->RunHook('filter.smtp-credentials', array($oAccount, &$aSmtpCredentials));
$bHookConnect = $bHookAuth = $bHookFrom = $bHookFrom = $bHookTo = $bHookData = $bHookLogoutAndDisconnect = false;
$this->Plugins()->RunHook('filter.smtp-connect', array($oAccount, $aSmtpCredentials,
&$oSmtpClient, $oMessage, &$oRcpt,
&$bHookConnect, &$bHookAuth, &$bHookFrom, &$bHookTo, &$bHookData, &$bHookLogoutAndDisconnect));
if (!$bHookConnect)
switch (strtolower($sDraftInfoType))
{
$oSmtpClient->Connect($aSmtpCredentials['Host'], $aSmtpCredentials['Port'],
$aSmtpCredentials['Ehlo'], $aSmtpCredentials['Secure']);
}
if (!$bHookAuth)
{
if ($aSmtpCredentials['UseAuth'])
{
$oSmtpClient->Login($aSmtpCredentials['Login'], $aSmtpCredentials['Password']);
}
}
if (!$bHookFrom)
{
$oSmtpClient->MailFrom($aSmtpCredentials['From']);
}
if (!$bHookTo)
{
$aRcpt =& $oRcpt->GetAsArray();
foreach ($aRcpt as /* @var $oEmail \MailSo\Mime\Email */ $oEmail)
{
$oSmtpClient->Rcpt($oEmail->GetEmail());
}
if (isset($aSmtpCredentials['HiddenRcpt']) && is_array($aSmtpCredentials['HiddenRcpt']))
{
foreach ($aSmtpCredentials['HiddenRcpt'] as $sEmail)
case 'reply':
case 'reply-all':
$this->MailClient()->MessageSetFlag($sDraftInfoFolder, array($sDraftInfoUid), true,
\MailSo\Imap\Enumerations\MessageFlag::ANSWERED, true);
break;
case 'forward':
$sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', '');
if (0 < strlen($sForwardedFlag))
{
if (\preg_match('/^[^@\s]+@[^@\s]+$/', $sEmail))
{
$oSmtpClient->Rcpt($sEmail);
}
}
}
}
if (!$bHookData)
{
$oSmtpClient->DataWithStream($rMessageStream);
}
if (!$bHookLogoutAndDisconnect)
{
$oSmtpClient->LogoutAndDisconnect();
}
}
catch (\MailSo\Net\Exceptions\ConnectionException $oException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ConnectionError, $oException);
}
catch (\MailSo\Smtp\Exceptions\LoginException $oException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError, $oException);
}
if (is_array($aDraftInfo) && 3 === count($aDraftInfo))
{
$sDraftInfoType = $aDraftInfo[0];
$sDraftInfoUid = $aDraftInfo[1];
$sDraftInfoFolder = $aDraftInfo[2];
try
{
switch (strtolower($sDraftInfoType))
{
case 'reply':
case 'reply-all':
$this->MailClient()->MessageSetFlag($sDraftInfoFolder, array($sDraftInfoUid), true,
\MailSo\Imap\Enumerations\MessageFlag::ANSWERED, true);
break;
case 'forward':
$sForwardFlag = $oAccount->Domain()->ForwardFlag();
if (0 < strlen($sForwardFlag))
{
$this->MailClient()->MessageSetFlag($sDraftInfoFolder, array($sDraftInfoUid), true,
$sForwardFlag, true);
}
break;
}
}
catch (\Exception $oException)
{
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR);
}
}
if (0 < strlen($sSentFolder))
{
try
{
if (!$oMessage->GetBcc())
{
if (\is_resource($rMessageStream))
{
\rewind($rMessageStream);
$sForwardedFlag, true);
}
$this->MailClient()->MessageAppendStream(
$rMessageStream, $iMessageStreamSize, $sSentFolder, array(
\MailSo\Imap\Enumerations\MessageFlag::SEEN
));
}
else
{
$rAppendMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$iAppendMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
$oMessage->ToStream(false), array($rAppendMessageStream), 8192, true, true, true);
$this->MailClient()->MessageAppendStream(
$rAppendMessageStream, $iAppendMessageStreamSize, $sSentFolder, array(
\MailSo\Imap\Enumerations\MessageFlag::SEEN
));
if (is_resource($rAppendMessageStream))
{
@fclose($rAppendMessageStream);
}
}
}
catch (\Exception $oException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSaveMessage, $oException);
break;
}
}
if (\is_resource($rMessageStream))
catch (\Exception $oException)
{
@\fclose($rMessageStream);
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR);
}
if (0 < strlen($sDraftFolder) && 0 < strlen($sDraftUid))
{
try
{
$this->MailClient()->MessageDelete($sDraftFolder, array($sDraftUid), true, true);
}
catch (\Exception $oException)
{
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR);
}
}
$mResult = true;
}
else
if (0 < strlen($sSentFolder))
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::InvalidRecipients);
try
{
if (!$oMessage->GetBcc())
{
if (\is_resource($rMessageStream))
{
\rewind($rMessageStream);
}
$this->MailClient()->MessageAppendStream(
$rMessageStream, $iMessageStreamSize, $sSentFolder, array(
\MailSo\Imap\Enumerations\MessageFlag::SEEN
));
}
else
{
$rAppendMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$iAppendMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
$oMessage->ToStream(false), array($rAppendMessageStream), 8192, true, true, true);
$this->MailClient()->MessageAppendStream(
$rAppendMessageStream, $iAppendMessageStreamSize, $sSentFolder, array(
\MailSo\Imap\Enumerations\MessageFlag::SEEN
));
if (is_resource($rAppendMessageStream))
{
@fclose($rAppendMessageStream);
}
}
}
catch (\Exception $oException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSaveMessage, $oException);
}
}
if (\is_resource($rMessageStream))
{
@\fclose($rMessageStream);
}
if (0 < strlen($sDraftFolder) && 0 < strlen($sDraftUid))
{
try
{
$this->MailClient()->MessageDelete($sDraftFolder, array($sDraftUid), true, true);
}
catch (\Exception $oException)
{
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR);
}
}
$mResult = true;
}
}
}
@ -4228,6 +4299,75 @@ class Actions
return $this->TrueResponse(__FUNCTION__);
}
/**
* @return array
*/
public function DoSendReadReceiptMessage()
{
$oAccount = $this->initMailClientConnection();
$oMessage = $this->buildReadReceiptMessage($oAccount);
$this->Plugins()->RunHook('filter.send-read-receipt-message', array(&$oMessage, $oAccount));
$mResult = false;
try
{
if ($oMessage)
{
$rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
$oMessage->ToStream(true), array($rMessageStream), 8192, true, true, true);
if (false !== $iMessageStreamSize)
{
$this->smptSendMessage($oAccount, $oMessage, $rMessageStream);
if (\is_resource($rMessageStream))
{
@\fclose($rMessageStream);
}
$mResult = true;
$sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
if (!empty($sReadReceiptFlag))
{
$sFolderFullName = $this->GetActionParam('MessageFolder', '');
$sUid = $this->GetActionParam('MessageUid', '');
$this->Cacher()->Set($oAccount->Email().'/'.$sFolderFullName.'/'.$sUid, '1');
if (0 < \strlen($sFolderFullName) && 0 < \strlen($sUid))
{
try
{
$this->MailClient()->MessageSetFlag($sFolderFullName, array($sUid), true, $sReadReceiptFlag, true, true);
}
catch (\Exception $oException) {}
}
}
}
}
}
catch (\RainLoop\Exceptions\ClientException $oException)
{
throw $oException;
}
catch (\Exception $oException)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSendMessage, $oException);
}
if (false === $mResult)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantSendMessage);
}
return $this->TrueResponse(__FUNCTION__);
}
/**
* @return array
*/
@ -5893,7 +6033,7 @@ class Actions
'ThreadsLen' => $mResponse->ThreadsLen(),
'ParentThread' => $mResponse->ParentThread(),
'Sensitivity' => $mResponse->Sensitivity(),
'ReadingConfirmation' => $mResponse->ReadingConfirmation()
'ReadReceipt' => ''
));
$oAttachments = $mResponse->Attachments();
@ -5932,12 +6072,15 @@ class Actions
// Flags
$aFlags = $mResponse->FlagsLowerCase();
$mResult['IsSeen'] = in_array('\\seen', $aFlags);
$mResult['IsFlagged'] = in_array('\\flagged', $aFlags);
$mResult['IsAnswered'] = in_array('\\answered', $aFlags);
$mResult['IsSeen'] = \in_array('\\seen', $aFlags);
$mResult['IsFlagged'] = \in_array('\\flagged', $aFlags);
$mResult['IsAnswered'] = \in_array('\\answered', $aFlags);
$sForwardedFlag = $oAccount ? strtolower($oAccount->Domain()->ForwardFlag()) : '';
$mResult['IsForwarded'] = 0 < strlen($sForwardedFlag) && in_array(strtolower($sForwardedFlag), $aFlags);
$sForwardedFlag = $this->Config()->Get('labs', 'imap_forwarded_flag', '');
$sReadReceiptFlag = $this->Config()->Get('labs', 'imap_read_receipt_flag', '');
$mResult['IsForwarded'] = 0 < \strlen($sForwardedFlag) && \in_array(\strtolower($sForwardedFlag), $aFlags);
$mResult['IsReadReceipt'] = 0 < \strlen($sReadReceiptFlag) && \in_array(\strtolower($sReadReceiptFlag), $aFlags);
if ('Message' === $sParent)
{
@ -5997,6 +6140,28 @@ class Actions
'FoundedCIDs' => $mFoundedCIDs,
'FoundedContentLocationUrls' => $mFoundedContentLocationUrls
)));
$mResult['ReadReceipt'] = $mResponse->ReadReceipt();
if (0 < \strlen($mResult['ReadReceipt']) && !$mResult['IsReadReceipt'])
{
if (0 < \strlen($mResult['ReadReceipt']))
{
try
{
$oReadReceipt = \MailSo\Mime\Email::Parse($mResult['ReadReceipt']);
if ($oReadReceipt && \strtolower($oAccount->Email()) === \strtolower($oReadReceipt->GetEmail()))
{
$mResult['ReadReceipt'] = '';
}
}
catch (\Exception $oException) {}
}
if (0 < \strlen($mResult['ReadReceipt']) && '1' === $this->Cacher()->Get($oAccount->Email().'/'.$mResult['Folder'].'/'.$mResult['Uid'], '0'))
{
$mResult['ReadReceipt'] = '';
}
}
}
}
else if ('MailSo\Mime\Email' === $sClassName)

View file

@ -219,6 +219,8 @@ Enables caching in the system'),
'use_imap_thread' => array(true),
'use_imap_move' => array(true),
'use_imap_auth_plain' => array(false),
'imap_forwarded_flag' => array('$Forwarded'),
'imap_read_receipt_flag' => array('$ReadReceipt'),
'autocreate_system_folders' => array(true),
'repo_type' => array('stable'),
'custom_repo' => array(''),

View file

@ -58,11 +58,6 @@ class Domain
*/
private $bOutAuth;
/**
* @var string
*/
private $sForwardFlag;
/**
* @var string
*/
@ -84,12 +79,10 @@ class Domain
* @param int $iOutSecure
* @param bool $bOutShortLogin
* @param bool $bOutAuth
* @param string $sForwardFlag = \RainLoop\Domain::DEFAULT_FORWARDED_FLAG
* @param string $sWhiteList = ''
*/
private function __construct($sName, $sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sForwardFlag = \RainLoop\Domain::DEFAULT_FORWARDED_FLAG, $sWhiteList = '')
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth, $sWhiteList = '')
{
$this->sName = $sName;
$this->sIncHost = $sIncHost;
@ -101,7 +94,6 @@ class Domain
$this->iOutSecure = $iOutSecure;
$this->bOutShortLogin = $bOutShortLogin;
$this->bOutAuth = $bOutAuth;
$this->sForwardFlag = $sForwardFlag;
$this->sWhiteList = \trim($sWhiteList);
$this->bDisabled = false;
}
@ -117,7 +109,6 @@ class Domain
* @param int $iOutSecure
* @param bool $bOutShortLogin
* @param bool $bOutAuth
* @param string $sForwardFlag = \RainLoop\Domain::DEFAULT_FORWARDED_FLAG
* @param string $sWhiteList = ''
*
* @return \RainLoop\Domain
@ -125,13 +116,12 @@ class Domain
public static function NewInstance($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sForwardFlag = \RainLoop\Domain::DEFAULT_FORWARDED_FLAG, $sWhiteList = '')
$sWhiteList = '')
{
return new self(
$sName,
return new self($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sForwardFlag, $sWhiteList);
$sWhiteList);
}
/**
@ -157,9 +147,6 @@ class Domain
!empty($aDomain['smpt_secure']) ? $aDomain['smpt_secure'] : '');
$bOutAuth = isset($aDomain['smpt_auth']) ? (bool) $aDomain['smpt_auth'] : true;
$sForwardFlag = isset($aDomain['imap_custom_forward_flag']) ?
(string) $aDomain['imap_custom_forward_flag'] : '';
$sWhiteList = (string) (isset($aDomain['white_list']) ? $aDomain['white_list'] : '');
$bIncShortLogin = isset($aDomain['imap_short_login']) ? (bool) $aDomain['imap_short_login'] : false;
@ -168,7 +155,7 @@ class Domain
$oDomain = self::NewInstance($sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
empty($sForwardFlag) ? \RainLoop\Domain::DEFAULT_FORWARDED_FLAG : $sForwardFlag, $sWhiteList);
$sWhiteList);
}
return $oDomain;
@ -262,7 +249,6 @@ class Domain
* @param int $iOutSecure
* @param bool $bOutShortLogin
* @param bool $bOutAuth
* @param string $sForwardFlag = \RainLoop\Domain::DEFAULT_FORWARDED_FLAG
* @param string $sWhiteList = ''
*
* @return \RainLoop\Domain
@ -270,7 +256,7 @@ class Domain
public function UpdateInstance(
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sForwardFlag = \RainLoop\Domain::DEFAULT_FORWARDED_FLAG, $sWhiteList = '')
$sWhiteList = '')
{
$this->sIncHost = $sIncHost;
$this->iIncPort = $iIncPort;
@ -281,7 +267,6 @@ class Domain
$this->iOutSecure = $iOutSecure;
$this->bOutShortLogin = $bOutShortLogin;
$this->bOutAuth = $bOutAuth;
$this->sForwardFlag = $sForwardFlag;
$this->sWhiteList = \trim($sWhiteList);
return $this;
@ -367,14 +352,6 @@ class Domain
return $this->bOutAuth;
}
/**
* @return string
*/
public function ForwardFlag()
{
return $this->sForwardFlag;
}
/**
* @return string
*/

View file

@ -1,161 +1,161 @@
<?php
namespace RainLoop\Providers;
class Domain extends \RainLoop\Providers\AbstractProvider
{
/**
* @var \RainLoop\Providers\Domain\DomainInterface
*/
private $oDriver;
/**
* @var bool
*/
private $bAdmin;
/**
* @param \RainLoop\Providers\Domain\DomainInterface $oDriver
*
* @return void
*/
public function __construct(\RainLoop\Providers\Domain\DomainInterface $oDriver)
{
$this->oDriver = $oDriver;
$this->bAdmin = $this->oDriver instanceof \RainLoop\Providers\Domain\DomainAdminInterface;
}
/**
* @return bool
*/
public function IsAdmin()
{
return $this->bAdmin;
}
/**
* @param string $sName
*
* @return \RainLoop\Domain | null
*/
public function Load($sName)
{
return $this->oDriver->Load($sName);
}
/**
* @param \RainLoop\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Domain $oDomain)
{
return $this->bAdmin ? $this->oDriver->Save($oDomain) : false;
}
/**
* @param string $sName
*
* @return bool
*/
public function Delete($sName)
{
return $this->bAdmin ? $this->oDriver->Delete($sName) : false;
}
/**
* @param string $sName
* @param bool $bDisabled
*
* @return bool
*/
public function Disable($sName, $bDisabled)
{
return $this->bAdmin ? $this->oDriver->Disable($sName, $bDisabled) : false;
}
/**
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param string $sSearch = ''
*
* @return array
*/
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '')
{
return $this->bAdmin ? $this->oDriver->GetList($iOffset, $iLimit, $sSearch) : array();
}
/**
* @param string $sSearch = ''
*
* @return int
*/
public function Count($sSearch = '')
{
return $this->oDriver->Count($sSearch);
}
/**
* @param \RainLoop\Actions $oActions
* @param string $sNameForTest = ''
*
* @return \RainLoop\Domain | null
*/
public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, $sNameForTest = '')
{
$oDomain = null;
if ($this->bAdmin)
{
$bCreate = '1' === (string) $oActions->GetActionParam('Create', '0');
$sName = (string) $oActions->GetActionParam('Name', '');
$sIncHost = (string) $oActions->GetActionParam('IncHost', '');
$iIncPort = (int) $oActions->GetActionParam('IncPort', 143);
$iIncSecure = (int) $oActions->GetActionParam('IncSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
$bIncShortLogin = '1' === (string) $oActions->GetActionParam('IncShortLogin', '0');
$sOutHost = (string) $oActions->GetActionParam('OutHost', '');
$iOutPort = (int) $oActions->GetActionParam('OutPort', 25);
$iOutSecure = (int) $oActions->GetActionParam('OutSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
$bOutShortLogin = '1' === (string) $oActions->GetActionParam('OutShortLogin', '0');
$bOutAuth = '1' === (string) $oActions->GetActionParam('OutAuth', '1');
$sWhiteList = (string) $oActions->GetActionParam('WhiteList', '');
if (0 < strlen($sName) || 0 < strlen($sNameForTest))
{
$oDomain = 0 < strlen($sNameForTest) ? null : $this->Load($sName);
if ($oDomain instanceof \RainLoop\Domain)
{
if ($bCreate)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
}
else
{
$oDomain->UpdateInstance(
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
\RainLoop\Domain::DEFAULT_FORWARDED_FLAG, $sWhiteList);
}
}
else
{
$oDomain = \RainLoop\Domain::NewInstance(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
\RainLoop\Domain::DEFAULT_FORWARDED_FLAG, $sWhiteList);
}
}
}
return $oDomain;
}
/**
* @return bool
*/
public function IsActive()
{
return $this->oDriver instanceof \RainLoop\Providers\Domain\DomainInterface;
}
<?php
namespace RainLoop\Providers;
class Domain extends \RainLoop\Providers\AbstractProvider
{
/**
* @var \RainLoop\Providers\Domain\DomainInterface
*/
private $oDriver;
/**
* @var bool
*/
private $bAdmin;
/**
* @param \RainLoop\Providers\Domain\DomainInterface $oDriver
*
* @return void
*/
public function __construct(\RainLoop\Providers\Domain\DomainInterface $oDriver)
{
$this->oDriver = $oDriver;
$this->bAdmin = $this->oDriver instanceof \RainLoop\Providers\Domain\DomainAdminInterface;
}
/**
* @return bool
*/
public function IsAdmin()
{
return $this->bAdmin;
}
/**
* @param string $sName
*
* @return \RainLoop\Domain | null
*/
public function Load($sName)
{
return $this->oDriver->Load($sName);
}
/**
* @param \RainLoop\Domain $oDomain
*
* @return bool
*/
public function Save(\RainLoop\Domain $oDomain)
{
return $this->bAdmin ? $this->oDriver->Save($oDomain) : false;
}
/**
* @param string $sName
*
* @return bool
*/
public function Delete($sName)
{
return $this->bAdmin ? $this->oDriver->Delete($sName) : false;
}
/**
* @param string $sName
* @param bool $bDisabled
*
* @return bool
*/
public function Disable($sName, $bDisabled)
{
return $this->bAdmin ? $this->oDriver->Disable($sName, $bDisabled) : false;
}
/**
* @param int $iOffset = 0
* @param int $iLimit = 20
* @param string $sSearch = ''
*
* @return array
*/
public function GetList($iOffset = 0, $iLimit = 20, $sSearch = '')
{
return $this->bAdmin ? $this->oDriver->GetList($iOffset, $iLimit, $sSearch) : array();
}
/**
* @param string $sSearch = ''
*
* @return int
*/
public function Count($sSearch = '')
{
return $this->oDriver->Count($sSearch);
}
/**
* @param \RainLoop\Actions $oActions
* @param string $sNameForTest = ''
*
* @return \RainLoop\Domain | null
*/
public function LoadOrCreateNewFromAction(\RainLoop\Actions $oActions, $sNameForTest = '')
{
$oDomain = null;
if ($this->bAdmin)
{
$bCreate = '1' === (string) $oActions->GetActionParam('Create', '0');
$sName = (string) $oActions->GetActionParam('Name', '');
$sIncHost = (string) $oActions->GetActionParam('IncHost', '');
$iIncPort = (int) $oActions->GetActionParam('IncPort', 143);
$iIncSecure = (int) $oActions->GetActionParam('IncSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
$bIncShortLogin = '1' === (string) $oActions->GetActionParam('IncShortLogin', '0');
$sOutHost = (string) $oActions->GetActionParam('OutHost', '');
$iOutPort = (int) $oActions->GetActionParam('OutPort', 25);
$iOutSecure = (int) $oActions->GetActionParam('OutSecure', \MailSo\Net\Enumerations\ConnectionSecurityType::NONE);
$bOutShortLogin = '1' === (string) $oActions->GetActionParam('OutShortLogin', '0');
$bOutAuth = '1' === (string) $oActions->GetActionParam('OutAuth', '1');
$sWhiteList = (string) $oActions->GetActionParam('WhiteList', '');
if (0 < strlen($sName) || 0 < strlen($sNameForTest))
{
$oDomain = 0 < strlen($sNameForTest) ? null : $this->Load($sName);
if ($oDomain instanceof \RainLoop\Domain)
{
if ($bCreate)
{
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainAlreadyExists);
}
else
{
$oDomain->UpdateInstance(
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList);
}
}
else
{
$oDomain = \RainLoop\Domain::NewInstance(0 < strlen($sNameForTest) ? $sNameForTest : $sName,
$sIncHost, $iIncPort, $iIncSecure, $bIncShortLogin,
$sOutHost, $iOutPort, $iOutSecure, $bOutShortLogin, $bOutAuth,
$sWhiteList);
}
}
}
return $oDomain;
}
/**
* @return bool
*/
public function IsActive()
{
return $this->oDriver instanceof \RainLoop\Providers\Domain\DomainInterface;
}
}