Move all imap config options to MailSo\Imap\Settings for per domain control

This commit is contained in:
the-djmaze 2022-12-13 09:54:19 +01:00
parent 780aa8759d
commit f98f1db441
20 changed files with 173 additions and 291 deletions

View file

@ -21,9 +21,4 @@ class Validator
{
return (null === $iMin || $iNumber >= $iMin) && (null === $iMax || $iNumber <= $iMax);
}
public static function PortInt(int $iPort) : bool
{
return static::RangeInt($iPort, 0, 65535);
}
}

View file

@ -16,53 +16,5 @@ namespace MailSo;
*/
class Config
{
/**
* @var int
*/
public static $MessageListFastSimpleSearch = true;
/**
* @var int
*/
public static $MessageListCountLimitTrigger = 0;
/**
* @var int
*/
public static $MessageListDateFilter = 0;
/**
* @var string
*/
public static $MessageListPermanentFilter = '';
/**
* @var int
*/
public static $LargeThreadLimit = 50;
/**
* @var bool
*/
public static $MessageAllHeaders = false;
/**
* @var bool
*/
public static $LogSimpleLiterals = false;
/**
* @var bool
*/
public static $CheckNewMessages = true;
/**
* @var string
*/
public static $BoundaryPrefix = '_Part_';
/**
* @var int
*/
public static $ImapTimeout = 300;
public static string $BoundaryPrefix = '_Part_';
}

View file

@ -312,7 +312,7 @@ trait Folders
*/
public function FolderExamine(string $sFolderName, bool $bReSelectSameFolders = false) : FolderInformation
{
return $this->selectOrExamineFolder($sFolderName, $this->__FORCE_SELECT_ON_EXAMINE, $bReSelectSameFolders);
return $this->selectOrExamineFolder($sFolderName, $this->Settings->force_select, $bReSelectSameFolders);
}
/**

View file

@ -26,13 +26,9 @@ class ImapClient extends \MailSo\Net\NetClient
use Commands\Metadata;
use Commands\Quota;
public
$TAG_PREFIX = 'TAG';
public string $TAG_PREFIX = 'TAG';
/**
* @var int
*/
private $iTagCount = 0;
private int $iTagCount = 0;
/**
* @var array
@ -46,35 +42,16 @@ class ImapClient extends \MailSo\Net\NetClient
/**
* Used by \MailSo\Mail\MailClient::MessageMimeStream
* @var array
*/
private $aFetchCallbacks;
private array $aFetchCallbacks = array();
/**
* @var array
*/
private $aTagTimeouts = array();
private array $aTagTimeouts = array();
/**
* @var bool
*/
private $bIsLoggined = false;
private bool $bIsLoggined = false;
/**
* @var string
*/
private $sLogginedUser = '';
private string $sLogginedUser = '';
/**
* @var bool
*/
public $__FORCE_SELECT_ON_EXAMINE = false;
public $__DISABLE_METADATA = false;
/**
* @var bool
*/
private $UTF8 = false;
private bool $UTF8 = false;
public function GetLogginedUser() : string
{
@ -87,16 +64,19 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\*
*/
// public function Connect(Settings $oSettings) : void
public function Connect(\MailSo\Net\ConnectSettings $oSettings) : void
{
$this->aTagTimeouts['*'] = \microtime(true);
$this->SetTimeOuts(10, $oSettings->timeout);
parent::Connect($oSettings);
$this->setCapabilities($this->getResponse('*'));
if (ConnectionSecurityType::STARTTLS === $this->iSecurityType
|| (ConnectionSecurityType::AUTO_DETECT === $this->iSecurityType && $this->IsSupported('STARTTLS'))) {
if (ConnectionSecurityType::STARTTLS === $this->Settings->type
|| (ConnectionSecurityType::AUTO_DETECT === $this->Settings->type && $this->IsSupported('STARTTLS'))) {
$this->StartTLS();
}
}
@ -305,9 +285,23 @@ class ImapClient extends \MailSo\Net\NetClient
private function setCapabilities(ResponseCollection $oResponseCollection) : void
{
$aList = $oResponseCollection->getCapabilityResult();
if ($aList && $this->__DISABLE_METADATA) {
// Issue #365: Many folders on Cyrus IMAP breaks login
$aList = \array_diff($aList, ['METADATA']);
if ($aList) {
if ($this->Settings->disable_metadata) {
// Issue #365: Many folders on Cyrus IMAP breaks login
$aList = \array_diff($aList, ['METADATA']);
}
if ($this->Settings->disable_move) {
$aList = \array_diff($aList, ['MOVE']);
}
if ($this->Settings->disable_sort) {
$aList = \array_diff($aList, ['SORT','ESORT']);
}
if ($this->Settings->disable_thread) {
$aList = \array_filter($aList, function ($item) { \str_starts_with($item, 'THREAD='); });
}
if ($this->Settings->disable_list_status) {
$aList = \array_diff($aList, ['LIST-STATUS']);
}
}
$this->aCapabilityItems = $aList;
}

View file

@ -132,11 +132,6 @@ abstract class SearchCriterias
$iTimeFilter = 0;
$aCriteriasResult = array();
if (0 < \MailSo\Config::$MessageListDateFilter) {
$iD = \time() - 3600 * 24 * 30 * \MailSo\Config::$MessageListDateFilter;
$iTimeFilter = \gmmktime(1, 1, 1, \gmdate('n', $iD), 1, \gmdate('Y', $iD));
}
$sSearch = \trim($sSearch);
if (\strlen($sSearch)) {
$aLines = \preg_match('/^('.static::RegEx.'):/i', $sSearch)
@ -146,7 +141,7 @@ abstract class SearchCriterias
if (!$aLines) {
$sValue = static::escapeSearchString($oImapClient, $sSearch);
if (\MailSo\Config::$MessageListFastSimpleSearch) {
if ($oImapClient->Settings->fast_simple_search) {
$aCriteriasResult[] = 'OR OR OR';
$aCriteriasResult[] = 'FROM';
$aCriteriasResult[] = $sValue;
@ -307,8 +302,8 @@ abstract class SearchCriterias
$aCriteriasResult[] = 'UNDELETED';
}
if (\MailSo\Config::$MessageListPermanentFilter) {
$aCriteriasResult[] = \MailSo\Config::$MessageListPermanentFilter;
if ($oImapClient->Settings->search_filter) {
$aCriteriasResult[] = $oImapClient->Settings->search_filter;
}
$sCriteriasResult = \trim(\implode(' ', $aCriteriasResult));

View file

@ -17,9 +17,31 @@ namespace MailSo\Imap;
*/
class Settings extends \MailSo\Net\ConnectSettings
{
public int $port = 143;
public int
$port = 143,
$timeout = 300;
public bool
$disable_list_status = false,
$disable_metadata = false,
$disable_move = false,
$disable_sort = false,
$disable_thread = false,
$expunge_all_on_delete = false,
$fast_simple_search = true,
$fetch_new_messages = true,
$force_select = false,
$message_all_headers = false;
public int
// $body_text_limit = 555000,
$message_list_limit = 0,
$folder_list_limit = 200,
$thread_limit = 50;
public string
$search_filter = '';
/*
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
@ -27,8 +49,21 @@ class Settings extends \MailSo\Net\ConnectSettings
parent::jsonSerialize(),
[
// '@Object' => 'Object/ImapSettings',
'disable_list_status' => $this->disable_list_status,
'disable_metadata' => $this->disable_metadata,
'disable_move' => $this->disable_move,
'disable_sort' => $this->disable_sort,
'disable_thread' => $this->disable_thread,
'use_expunge_all_on_delete' => $this->expunge_all_on_delete,
// 'body_text_limit' => $this->body_text_limit,
'fast_simple_search' => $this->fast_simple_search,
'folder_list_limit' => $this->folder_list_limit,
'force_select' => $this->force_select,
'message_all_headers' => $this->message_all_headers,
'message_list_limit' => $this->message_list_limit,
'search_filter' => $this->message_list_filter,
'timeout' => $this->timeout
]
);
}
*/
}

View file

@ -185,9 +185,7 @@ trait ResponseParser
if (null !== $sLiteral) {
if (!$bTreatAsAtom) {
$aList[] = $sLiteral;
if (\MailSo\Config::$LogSimpleLiterals) {
$this->writeLog('{'.$iLiteralLen.'} '.$sLiteral, \LOG_INFO);
}
// $this->writeLog('{'.$iLiteralLen.'} '.$sLiteral, \LOG_INFO);
} else {
\SnappyMail\Log::notice('IMAP', 'Literal treated as atom and skipped');
}

View file

@ -106,8 +106,7 @@ trait Status
$this->UIDVALIDITY,
// $this->UNSEEN, // undefined when SELECT/EXAMINE
$this->HIGHESTMODSEQ,
$sClientHash,
\MailSo\Config::$MessageListPermanentFilter
$sClientHash
]));
}

View file

@ -38,7 +38,6 @@ class MailClient
function __construct()
{
$this->oImapClient = new \MailSo\Imap\ImapClient;
$this->oImapClient->SetTimeOuts(10, \MailSo\Config::$ImapTimeout);
}
public function ImapClient() : \MailSo\Imap\ImapClient
@ -48,8 +47,7 @@ class MailClient
private function getEnvelopeOrHeadersRequestString() : string
{
if (\MailSo\Config::$MessageAllHeaders)
{
if ($this->oImapClient->Settings->message_all_headers) {
return FetchType::BODY_HEADER_PEEK;
}
@ -299,7 +297,7 @@ class MailClient
StoreAction::ADD_FLAGS_SILENT
);
if ($bExpungeAll) {
if ($bExpungeAll && $this->oImapClient->Settings->expunge_all_on_delete) {
$this->oImapClient->FolderExpunge();
} else {
$this->oImapClient->FolderExpunge($oRange);
@ -314,24 +312,19 @@ class MailClient
* @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\*
*/
public function MessageMove(string $sFromFolder, string $sToFolder, SequenceSet $oRange, bool $bUseMoveSupported = true, bool $bExpungeAll = false) : self
public function MessageMove(string $sFromFolder, string $sToFolder, SequenceSet $oRange) : self
{
if (!$sFromFolder || !$sToFolder || !\count($oRange))
{
if (!$sFromFolder || !$sToFolder || !\count($oRange)) {
throw new \InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFromFolder);
if ($bUseMoveSupported && $this->oImapClient->IsSupported('MOVE'))
{
if ($this->oImapClient->IsSupported('MOVE')) {
$this->oImapClient->MessageMove($sToFolder, $oRange);
}
else
{
} else {
$this->oImapClient->MessageCopy($sToFolder, $oRange);
$this->MessageDelete($sFromFolder, $oRange, $bExpungeAll);
$this->MessageDelete($sFromFolder, $oRange, true);
}
return $this;
@ -410,8 +403,8 @@ class MailClient
public function GenerateImapClientHash() : string
{
return \md5('ImapClientHash/'.
$this->oImapClient->GetLogginedUser().'@'.
$this->oImapClient->GetConnectedHost().':'.
$this->oImapClient->GetLogginedUser() . '@' .
$this->oImapClient->GetConnectedHost() . ':' .
$this->oImapClient->GetConnectedPort()
);
}
@ -424,8 +417,7 @@ class MailClient
{
$aNewMessages = array();
if ($iPrevUidNext && $iPrevUidNext != $iCurrentUidNext && 'INBOX' === $sFolderName && \MailSo\Config::$CheckNewMessages)
{
if ($iPrevUidNext && $iPrevUidNext != $iCurrentUidNext && 'INBOX' === $sFolderName && $this->oImapClient->Settings->fetch_new_messages) {
$this->oImapClient->FolderExamine($sFolderName);
$aFetchResponse = $this->oImapClient->Fetch(array(
@ -438,12 +430,10 @@ class MailClient
))
), $iPrevUidNext.':*', true);
foreach ($aFetchResponse as /* @var $oFetchResponse \MailSo\Imap\FetchResponse */ $oFetchResponse)
{
foreach ($aFetchResponse as /* @var $oFetchResponse \MailSo\Imap\FetchResponse */ $oFetchResponse) {
$aFlags = \array_map('strtolower', $oFetchResponse->GetFetchValue(FetchType::FLAGS));
if (!\in_array(\strtolower(MessageFlag::SEEN), $aFlags))
{
if (!\in_array(\strtolower(MessageFlag::SEEN), $aFlags)) {
$iUid = (int) $oFetchResponse->GetFetchValue(FetchType::UID);
$oHeaders = new \MailSo\Mime\HeaderCollection($oFetchResponse->GetHeaderFieldsValue());
@ -535,41 +525,30 @@ class MailClient
*/
public function MessageListThreadsMap(string $sFolderName, string $sFolderHash, ?\MailSo\Cache\CacheClient $oCacher) : array
{
// $iThreadLimit = $this->oImapClient->Settings->thread_limit;
$sSearchHash = '';
if (0 < \MailSo\Config::$MessageListDateFilter)
{
$iD = \time() - 3600 * 24 * 30 * \MailSo\Config::$MessageListDateFilter;
$iTimeFilter = \gmmktime(1, 1, 1, \gmdate('n', $iD), 1, \gmdate('Y', $iD));
$sSearchHash .= ' SINCE '.\gmdate('j-M-Y', $iTimeFilter);
}
if ('' === \trim($sSearchHash))
{
if ('' === \trim($sSearchHash)) {
$sSearchHash = 'ALL';
}
if ($oCacher && $oCacher->IsInited())
{
if ($oCacher && $oCacher->IsInited()) {
$sSerializedHashKey =
'ThreadsMapSorted/'.$sSearchHash.'/'.$sFolderName.'/'.$sFolderHash;
"ThreadsMapSorted/{$sSearchHash}/{$sFolderName}/{$sFolderHash}";
// "ThreadsMapSorted/{$sSearchHash}/{$iThreadLimit}/{$sFolderName}/{$sFolderHash}";
if ($this->oLogger)
{
if ($this->oLogger) {
$this->oLogger->Write($sSerializedHashKey);
}
$sSerializedUids = $oCacher->Get($sSerializedHashKey);
if (!empty($sSerializedUids))
{
if (!empty($sSerializedUids)) {
$aSerializedUids = \json_decode($sSerializedUids, true);
if (isset($aSerializedUids['ThreadsUids']) && \is_array($aSerializedUids['ThreadsUids']))
{
if ($this->oLogger)
{
if (isset($aSerializedUids['ThreadsUids']) && \is_array($aSerializedUids['ThreadsUids'])) {
if ($this->oLogger) {
$this->oLogger->Write('Get Serialized Thread UIDS from cache ("'.$sFolderName.'" / '.$sSearchHash.') [count:'.\count($aSerializedUids['ThreadsUids']).']');
}
return $aSerializedUids['ThreadsUids'];
}
}
@ -788,15 +767,15 @@ class MailClient
$oMessageCollection->Limit = $oParams->iLimit;
$oMessageCollection->Search = $sSearch;
$oMessageCollection->ThreadUid = $oParams->iThreadUid;
$oMessageCollection->Filtered = '' !== \MailSo\Config::$MessageListPermanentFilter;
// $oMessageCollection->Filtered = '' !== $this->oImapClient->Settings->search_filter;
$oInfo = $this->oImapClient->FolderStatusAndSelect($oParams->sFolderName);
$oMessageCollection->FolderInfo = $oInfo;
$aAllThreads = [];
$bUseThreads = $oParams->bUseThreads ?
($this->oImapClient->IsSupported('THREAD=REFS') || $this->oImapClient->IsSupported('THREAD=REFERENCES') || $this->oImapClient->IsSupported('THREAD=ORDEREDSUBJECT')) : false;
$bUseThreads = $oParams->bUseThreads
&& ($this->oImapClient->IsSupported('THREAD=REFS') || $this->oImapClient->IsSupported('THREAD=REFERENCES') || $this->oImapClient->IsSupported('THREAD=ORDEREDSUBJECT'));
if ($oParams->iThreadUid && !$bUseThreads) {
throw new \InvalidArgumentException('THREAD not supported');
}
@ -814,10 +793,10 @@ class MailClient
}
if ($oInfo->MESSAGES) {
if (0 < \MailSo\Config::$MessageListCountLimitTrigger && \MailSo\Config::$MessageListCountLimitTrigger < $oInfo->MESSAGES) {
if (0 < $this->oImapClient->Settings->message_list_limit && $this->oImapClient->Settings->message_list_limit < $oInfo->MESSAGES) {
if ($this->oLogger) {
$this->oLogger->Write('List optimization (count: '.$oInfo->MESSAGES.
', limit:'.\MailSo\Config::$MessageListCountLimitTrigger.')');
', limit:'.$this->oImapClient->Settings->message_list_limit.')');
}
if (\strlen($sSearch)) {
$aUids = $this->GetUids($oParams, $sSearch,
@ -846,7 +825,7 @@ class MailClient
$bUseSortIfSupported = $oParams->bUseSortIfSupported && $this->oImapClient->IsSupported('SORT');
if ($bUseThreads) {
$aAllThreads = $this->MessageListThreadsMap($oMessageCollection->FolderName, $oMessageCollection->FolderHash, $oParams->oCacher);
// $iThreadLimit = \MailSo\Config::$LargeThreadLimit;
// $iThreadLimit = $this->oImapClient->Settings->thread_limit;
if ($oParams->iThreadUid) {
$aUids = [$oParams->iThreadUid];
// Only show the selected thread messages
@ -936,7 +915,7 @@ class MailClient
return 1 === \count($aUids) && \is_numeric($aUids[0]) ? (int) $aUids[0] : null;
}
public function Folders(string $sParent, string $sListPattern, bool $bUseListSubscribeStatus, int $iOptimizationLimit, bool $bUseListStatus) : ?FolderCollection
public function Folders(string $sParent, string $sListPattern, bool $bUseListSubscribeStatus) : ?FolderCollection
{
$aImapSubscribedFoldersHelper = null;
if ($this->oImapClient->IsSupported('LIST-EXTENDED')) {
@ -958,13 +937,15 @@ class MailClient
}
}
$aFolders = $bUseListStatus
// $this->oImapClient->Settings->disable_list_status
$aFolders = $this->oImapClient->IsSupported('LIST-STATUS')
? $this->oImapClient->FolderStatusList($sParent, $sListPattern)
: $this->oImapClient->FolderList($sParent, $sListPattern);
if (!$aFolders) {
return null;
}
$iOptimizationLimit = $this->oImapClient->Settings->message_list_limit;
$oFolderCollection = new FolderCollection;
$oFolderCollection->Optimized = 10 < $iOptimizationLimit && \count($aFolders) > $iOptimizationLimit;

View file

@ -39,7 +39,7 @@ class MessageCollection extends \MailSo\Base\Collection
public array $NewMessages = array();
public bool $Filtered = false;
// public bool $Filtered = false;
public function append($oMessage, bool $bToTop = false) : void
{
@ -62,7 +62,7 @@ class MessageCollection extends \MailSo\Base\Collection
'FolderInfo' => $this->FolderInfo,
'ThreadUid' => $this->ThreadUid,
'NewMessages' => $this->NewMessages,
'Filtered' => $this->Filtered,
// 'Filtered' => $this->Filtered,
'Offset' => $this->Offset,
'Limit' => $this->Limit,
'Search' => $this->Search

View file

@ -23,6 +23,7 @@ class ConnectSettings implements \JsonSerializable
// none, TLS, STARTTLS
public int $type = Enumerations\ConnectionSecurityType::AUTO_DETECT;
// public int $type = Enumerations\ConnectionSecurityType::NONE;
public SSLContext $ssl;

View file

@ -22,61 +22,29 @@ abstract class NetClient
*/
private $rConnect = null;
/**
* @var bool
*/
private $bUnreadBuffer = false;
private bool $bUnreadBuffer = false;
/**
* @var bool
*/
protected $bRunningCallback = false;
protected bool $bRunningCallback = false;
/**
* @var string
*/
protected $sResponseBuffer = '';
private string $sConnectedHost = '';
/**
* @var int
*/
protected $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::NONE;
protected string $sResponseBuffer = '';
/**
* @var string
*/
private $sConnectedHost = '';
private bool $ssl = false;
/**
* @var int
*/
private $iConnectedPort = 0;
private int $iConnectTimeOut = 10;
/**
* @var bool
*/
private $bSecure = false;
private int $iSocketTimeOut = 10;
/**
* @var int
*/
private $iConnectTimeOut = 10;
/**
* @var int
*/
private $iSocketTimeOut = 10;
/**
* @var int
*/
private $iStartConnectTime = 0;
private float $iStartConnectTime = 0;
/**
* @var \MailSo\Log\Logger
*/
protected $oLogger = null;
public ConnectSettings $Settings;
public function __destruct()
{
try
@ -93,7 +61,7 @@ abstract class NetClient
public function GetConnectedPort() : int
{
return $this->iConnectedPort;
return $this->Settings->port;
}
public function SetTimeOuts(int $iConnectTimeOut = 10, int $iSocketTimeOut = 10) : void
@ -124,43 +92,40 @@ abstract class NetClient
public function Connect(ConnectSettings $oSettings) : void
{
$oSettings->host = \trim($oSettings->host);
if (!\strlen($oSettings->host) || !\MailSo\Base\Validator::PortInt($oSettings->port)) {
if (!\strlen($oSettings->host) || !\MailSo\Base\Validator::RangeInt($oSettings->port, 0, 65535)) {
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException,
\LOG_ERR, true);
}
if ($this->IsConnected())
{
if ($this->IsConnected()) {
$this->writeLogException(
new Exceptions\SocketAlreadyConnectedException,
\LOG_ERR, true);
}
$this->Settings = $oSettings;
$sErrorStr = '';
$iErrorNo = 0;
$this->sConnectedHost = $oSettings->host;
$this->iConnectedPort = $oSettings->port;
$this->iSecurityType = $oSettings->type;
$this->bSecure = \MailSo\Net\Enumerations\ConnectionSecurityType::UseSSL(
$this->iConnectedPort, $this->iSecurityType);
if (!\preg_match('/^[a-z0-9._]{2,8}:\/\//i', $this->sConnectedHost))
{
$this->sConnectedHost = ($this->bSecure ? 'ssl://' : 'tcp://').$this->sConnectedHost;
// $this->sConnectedHost = ($this->bSecure ? 'ssl://' : '').$this->sConnectedHost;
$this->ssl = \MailSo\Net\Enumerations\ConnectionSecurityType::UseSSL($this->Settings->port, $this->Settings->type);
if (!\preg_match('/^[a-z0-9._]{2,8}:\/\//i', $this->sConnectedHost)) {
$this->sConnectedHost = ($this->ssl ? 'ssl://' : 'tcp://') . $this->sConnectedHost;
// $this->sConnectedHost = ($this->ssl ? 'ssl://' : '') . $this->sConnectedHost;
}
if (!$this->bSecure && \MailSo\Net\Enumerations\ConnectionSecurityType::SSL === $this->iSecurityType)
{
if (!$this->ssl && \MailSo\Net\Enumerations\ConnectionSecurityType::SSL === $this->Settings->type) {
$this->writeLogException(
new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('SSL isn\'t supported: ('.\implode(', ', \stream_get_transports()).')'),
\LOG_ERR, true);
}
$this->iStartConnectTime = \microtime(true);
$this->writeLog('Start connection to "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"');
$this->writeLog('Start connection to "'.$this->sConnectedHost.':'.$this->Settings->port.'"');
$rStreamContext = \stream_context_create(array(
'ssl' => $oSettings->ssl->jsonSerialize()
@ -170,7 +135,7 @@ abstract class NetClient
try
{
$this->rConnect = \stream_socket_client($this->sConnectedHost.':'.$this->iConnectedPort,
$this->rConnect = \stream_socket_client($this->sConnectedHost.':'.$this->Settings->port,
$iErrorNo, $sErrorStr, $this->iConnectTimeOut, STREAM_CLIENT_CONNECT, $rStreamContext);
}
catch (\Throwable $oExc)
@ -188,7 +153,7 @@ abstract class NetClient
$this->writeLogException(
new Exceptions\SocketCanNotConnectToHostException(
\MailSo\Base\Locale::ConvertSystemString($sErrorStr), (int) $iErrorNo,
'Can\'t connect to host "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"'
'Can\'t connect to host "'.$this->sConnectedHost.':'.$this->Settings->port.'"'
), \LOG_NOTICE, true);
}
@ -246,7 +211,7 @@ abstract class NetClient
$bResult = \fclose($this->rConnect);
$this->writeLog('Disconnected from "'.$this->sConnectedHost.':'.$this->iConnectedPort.'" ('.
$this->writeLog('Disconnected from "'.$this->sConnectedHost.':'.$this->Settings->port.'" ('.
(($bResult) ? 'success' : 'unsuccess').')');
if ($this->iStartConnectTime)

View file

@ -73,8 +73,8 @@ class SieveClient extends \MailSo\Net\NetClient
$this->validateResponse($aResponse);
$this->parseStartupResponse($aResponse);
if (ConnectionSecurityType::STARTTLS === $this->iSecurityType
|| (ConnectionSecurityType::AUTO_DETECT === $this->iSecurityType && $this->IsSupported('STARTTLS'))) {
if (ConnectionSecurityType::STARTTLS === $this->Settings->type
|| (ConnectionSecurityType::AUTO_DETECT === $this->Settings->type && $this->IsSupported('STARTTLS'))) {
$this->StartTLS();
}
}

View file

@ -112,8 +112,8 @@ class SmtpClient extends \MailSo\Net\NetClient
$this->ehloOrHelo($sEhloHost);
$this->sEhlo = $sEhloHost;
if (ConnectionSecurityType::STARTTLS === $this->iSecurityType
|| (ConnectionSecurityType::AUTO_DETECT === $this->iSecurityType && $this->IsSupported('STARTTLS'))) {
if (ConnectionSecurityType::STARTTLS === $this->Settings->type
|| (ConnectionSecurityType::AUTO_DETECT === $this->Settings->type && $this->IsSupported('STARTTLS'))) {
$this->StartTLS();
}
}

View file

@ -725,7 +725,7 @@ class Actions
$aResult['System'], array(
'allowHtmlEditorBitiButtons' => (bool)$oConfig->Get('labs', 'allow_html_editor_biti_buttons', false),
'allowCtrlEnterOnCompose' => (bool)$oConfig->Get('labs', 'allow_ctrl_enter_on_compose', false),
'useImapThread' => (bool)$oConfig->Get('imap', 'use_thread', false),
'useImapThread' => (bool)$oConfig->Get('imap', 'use_thread', true),
'allowAppendMessage' => (bool)$oConfig->Get('labs', 'allow_message_append', false),
'folderSpecLimit' => (int)$oConfig->Get('labs', 'folders_spec_limit', 50),
'listPermanentFiltered' => '' !== \trim($oConfig->Get('imap', 'message_list_permanent_filter', '')),

View file

@ -12,11 +12,7 @@ trait Folders
private function getFolderCollection(bool $HideUnsubscribed) : ?\MailSo\Mail\FolderCollection
{
return $this->MailClient()->Folders('', '*',
$HideUnsubscribed,
(int) $this->Config()->Get('imap', 'folder_list_limit', 200),
(bool) $this->Config()->Get('imap', 'use_list_status', true)
);
return $this->MailClient()->Folders('', '*', $HideUnsubscribed);
}
/**
@ -180,17 +176,9 @@ trait Folders
}
}
$bUseSort = $this->Config()->Get('imap', 'use_sort', true);
$aCapabilities = \array_filter($this->MailClient()->Capability(), function ($item) use ($bUseSort) {
return !\preg_match('/^(IMAP|AUTH|LOGIN|SASL)/', $item)
&& ($bUseSort || !\preg_match('/^E?SORT/', $item));
$aCapabilities = \array_filter($this->MailClient()->Capability(), function ($item) {
return !\preg_match('/^(IMAP|AUTH|LOGIN|SASL)/', $item);
});
if (!$this->Config()->Get('imap', 'use_list_status', true)) {
$key = \array_search('LIST-STATUS', $aCapabilities);
if (false !== $key) {
unset($aCapabilities[$key]);
}
}
$oFolderCollection = \array_merge(
$oFolderCollection->jsonSerialize(),

View file

@ -66,12 +66,12 @@ trait Messages
try
{
if (!$this->Config()->Get('imap', 'use_thread', false)) {
if (!$this->Config()->Get('imap', 'use_thread', true)) {
$oParams->bUseThreads = false;
}
$oParams->oCacher = $this->cacherForUids();
$oParams->bUseSortIfSupported = !!$this->Config()->Get('imap', 'use_sort', true);
$oParams->bUseSortIfSupported = true;
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
if ($oSettingsLocal instanceof \RainLoop\Settings) {
@ -482,8 +482,7 @@ trait Messages
try
{
$this->MailClient()->MessageDelete($sFolder, new SequenceSet($aUids),
!!$this->Config()->Get('imap', 'use_expunge_all_on_delete', false));
$this->MailClient()->MessageDelete($sFolder, new SequenceSet($aUids), true);
}
catch (\Throwable $oException)
{
@ -548,10 +547,7 @@ trait Messages
try
{
$this->MailClient()->MessageMove($sFromFolder, $sToFolder, $oUids,
!!$this->Config()->Get('imap', 'use_move', true),
!!$this->Config()->Get('imap', 'use_expunge_all_on_delete', false)
);
$this->MailClient()->MessageMove($sFromFolder, $sToFolder, $oUids);
}
catch (\Throwable $oException)
{
@ -978,7 +974,7 @@ trait Messages
private function cacherForThreads()
{
$oAccount = $this->getAccountFromToken(false);
return !!$this->Config()->Get('imap', 'use_thread', false) ? $this->Cacher($oAccount) : null;
return !!$this->Config()->Get('imap', 'use_thread', true) ? $this->Cacher($oAccount) : null;
}
private function buildReadReceiptMessage(Account $oAccount) : \MailSo\Mime\Message

View file

@ -8,9 +8,8 @@ abstract class Api
public static function Handle() : bool
{
static $bOne = false;
if (!$bOne)
{
static::SetupDefaultMailSoConfig();
if (!$bOne) {
static::SetupDefaultConfig();
$bOne = true;
}
return $bOne;
@ -84,42 +83,15 @@ abstract class Api
return $oLogger;
}
protected static function SetupDefaultMailSoConfig() : void
protected static function SetupDefaultConfig() : void
{
if (\class_exists('MailSo\Config'))
{
\MailSo\Config::$MessageListFastSimpleSearch =
!!static::Config()->Get('imap', 'message_list_fast_simple_search', true);
\MailSo\Config::$BoundaryPrefix = \trim(static::Config()->Get('labs', 'boundary_prefix', ''));
\MailSo\Config::$MessageListCountLimitTrigger =
(int) static::Config()->Get('imap', 'message_list_count_limit_trigger', 0);
\MailSo\Config::$MessageListDateFilter =
(int) static::Config()->Get('imap', 'message_list_date_filter', 0);
\MailSo\Config::$MessageListPermanentFilter =
\trim(static::Config()->Get('imap', 'message_list_permanent_filter', ''));
\MailSo\Config::$MessageAllHeaders =
!!static::Config()->Get('imap', 'message_all_headers', false);
\MailSo\Config::$LargeThreadLimit =
(int) static::Config()->Get('imap', 'large_thread_limit', 50);
\MailSo\Config::$ImapTimeout =
(int) static::Config()->Get('imap', 'timeout', 300);
\MailSo\Config::$BoundaryPrefix =
\trim(static::Config()->Get('labs', 'boundary_prefix', ''));
Utils::$CookieDefaultPath = static::Config()->Get('labs', 'cookie_default_path', '');
Utils::$CookieSameSite = static::Config()->Get('security', 'cookie_samesite', 'Strict');
Utils::$CookieSecure = isset($_SERVER['HTTPS'])
|| 'None' == Utils::$CookieSameSite
|| !!static::Config()->Get('labs', 'cookie_default_secure', false);
\MailSo\Config::$CheckNewMessages = !!static::Config()->Get('labs', 'check_new_messages', true);
}
Utils::$CookieDefaultPath = static::Config()->Get('labs', 'cookie_default_path', '');
Utils::$CookieSameSite = static::Config()->Get('security', 'cookie_samesite', 'Strict');
Utils::$CookieSecure = isset($_SERVER['HTTPS'])
|| 'None' == Utils::$CookieSameSite
|| !!static::Config()->Get('labs', 'cookie_default_secure', false);
}
public static function Version() : string

View file

@ -362,15 +362,13 @@ Enables caching in the system'),
'use_sort' => array(true),
'use_force_selection' => array(false),
'use_thread' => array(true),
'use_move' => array(false),
'use_move' => array(true),
'use_expunge_all_on_delete' => array(false),
'body_text_limit' => array(555000),
'message_list_fast_simple_search' => array(true),
'message_list_count_limit_trigger' => array(0),
'message_list_date_filter' => array(0),
'message_list_permanent_filter' => array(''),
'message_all_headers' => array(false),
'large_thread_limit' => array(50),
'folder_list_limit' => array(200),
'show_login_alert' => array(true),
'use_list_status' => array(true),

View file

@ -214,12 +214,25 @@ abstract class Account implements \JsonSerializable
public function ImapConnectAndLoginHelper(\RainLoop\Plugins\Manager $oPlugins, \MailSo\Imap\ImapClient $oImapClient, \RainLoop\Config\Application $oConfig) : bool
{
$oImapClient->__FORCE_SELECT_ON_EXAMINE = !!$oConfig->Get('imap', 'use_force_selection');
$oImapClient->__DISABLE_METADATA = !!$oConfig->Get('imap', 'disable_metadata');
$oSettings = $this->Domain()->ImapSettings();
$oSettings->Login = $this->IncLogin();
$oSettings->timeout = \max($oSettings->timeout, (int) $oConfig->Get('imap', 'timeout', $oSettings->timeout));
$oSettings->disable_list_status |= !$oConfig->Get('imap', 'use_list_status', true);
$oSettings->disable_metadata |= !!$oConfig->Get('imap', 'disable_metadata', false);
$oSettings->disable_move |= !$oConfig->Get('imap', 'use_move', true);
$oSettings->disable_sort |= !$oConfig->Get('imap', 'use_sort', true);
$oSettings->disable_thread |= !$oConfig->Get('imap', 'use_thread', true);
$oSettings->expunge_all_on_delete |= !!$oConfig->Get('imap', 'use_expunge_all_on_delete', false);
$oSettings->fast_simple_search = !(!$oSettings->fast_simple_search || !$oConfig->Get('imap', 'message_list_fast_simple_search', true));
$oSettings->fetch_new_messages = !(!$oSettings->fetch_new_messages || !$oConfig->Get('labs', 'check_new_messages', true));
$oSettings->force_select |= !!$oConfig->Get('imap', 'use_force_selection', false);
$oSettings->folder_list_limit = \min($oSettings->folder_list_limit, (int) $oConfig->Get('imap', 'folder_list_limit', 200));
$oSettings->message_all_headers |= !!$oConfig->Get('imap', 'message_all_headers', false);
$oSettings->message_list_limit = \min($oSettings->message_list_limit, (int) $oConfig->Get('imap', 'message_list_count_limit_trigger', 0));
$oSettings->search_filter = $oSettings->search_filter ?: \trim($oConfig->Get('imap', 'message_list_permanent_filter', ''));
// $oSettings->thread_limit = \min($oSettings->thread_limit, (int) $oConfig->Get('imap', 'large_thread_limit', 50));
$oPlugins->RunHook('imap.before-connect', array($this, $oImapClient, $oSettings));
$oImapClient->Connect($oSettings);
$oPlugins->RunHook('imap.after-connect', array($this, $oImapClient, $oSettings));