Check SMTP SIZE #779

This commit is contained in:
the-djmaze 2022-12-18 13:55:22 +01:00
parent 2793dae547
commit f5beeb9ca1

View file

@ -781,8 +781,10 @@ trait Messages
/*resource*/ &$rMessageStream, int &$iMessageStreamSize, bool $bDsn = false, bool $bAddHiddenRcpt = true) /*resource*/ &$rMessageStream, int &$iMessageStreamSize, bool $bDsn = false, bool $bAddHiddenRcpt = true)
{ {
$oRcpt = $oMessage->GetRcpt(); $oRcpt = $oMessage->GetRcpt();
if ($oRcpt && 0 < $oRcpt->Count()) if (!$oRcpt || !$oRcpt->count()) {
{ throw new ClientException(Notifications::InvalidRecipients);
}
$this->Plugins()->RunHook('filter.smtp-message-stream', $this->Plugins()->RunHook('filter.smtp-message-stream',
array($oAccount, &$rMessageStream, &$iMessageStreamSize)); array($oAccount, &$rMessageStream, &$iMessageStreamSize));
@ -857,22 +859,21 @@ trait Messages
} }
else if ($oSmtpClient->IsConnected()) else if ($oSmtpClient->IsConnected())
{ {
if (!empty($sFrom)) if ($iMessageStreamSize && $oSmtpClient->maxSize() && $iMessageStreamSize * 1.33 > $oSmtpClient->maxSize()) {
{ throw new ClientException(Notifications::ClientViewError, 'Message size '. ($iMessageStreamSize * 1.33) . ' bigger then max ' . $oSmtpClient->maxSize());
}
if (!empty($sFrom)) {
$oSmtpClient->MailFrom($sFrom, '', $bDsn); $oSmtpClient->MailFrom($sFrom, '', $bDsn);
} }
foreach ($oRcpt as /* @var $oEmail \MailSo\Mime\Email */ $oEmail) foreach ($oRcpt as /* @var $oEmail \MailSo\Mime\Email */ $oEmail) {
{
$oSmtpClient->Rcpt($oEmail->GetEmail(), $bDsn); $oSmtpClient->Rcpt($oEmail->GetEmail(), $bDsn);
} }
if ($bAddHiddenRcpt && \is_array($aHiddenRcpt) && \count($aHiddenRcpt)) if ($bAddHiddenRcpt && \is_array($aHiddenRcpt) && \count($aHiddenRcpt)) {
{ foreach ($aHiddenRcpt as $sEmail) {
foreach ($aHiddenRcpt as $sEmail) if (\preg_match('/^[^@\s]+@[^@\s]+$/', $sEmail)) {
{
if (\preg_match('/^[^@\s]+@[^@\s]+$/', $sEmail))
{
$oSmtpClient->Rcpt($sEmail); $oSmtpClient->Rcpt($sEmail);
} }
} }
@ -885,36 +886,23 @@ trait Messages
} }
catch (\MailSo\Net\Exceptions\ConnectionException $oException) catch (\MailSo\Net\Exceptions\ConnectionException $oException)
{ {
if ($this->Config()->Get('labs', 'smtp_show_server_errors')) if ($this->Config()->Get('labs', 'smtp_show_server_errors')) {
{
throw new ClientException(Notifications::ClientViewError, $oException); throw new ClientException(Notifications::ClientViewError, $oException);
} }
else
{
throw new ClientException(Notifications::ConnectionError, $oException); throw new ClientException(Notifications::ConnectionError, $oException);
} }
}
catch (\MailSo\Smtp\Exceptions\LoginException $oException) catch (\MailSo\Smtp\Exceptions\LoginException $oException)
{ {
throw new ClientException(Notifications::AuthError, $oException); throw new ClientException(Notifications::AuthError, $oException);
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
if ($this->Config()->Get('labs', 'smtp_show_server_errors')) if ($this->Config()->Get('labs', 'smtp_show_server_errors')) {
{
throw new ClientException(Notifications::ClientViewError, $oException); throw new ClientException(Notifications::ClientViewError, $oException);
} }
else
{
throw $oException; throw $oException;
} }
} }
}
else
{
throw new ClientException(Notifications::InvalidRecipients);
}
}
private function messageSetFlag(string $sMessageFlag, string $sResponseFunction, bool $bSkipUnsupportedFlag = false) : array private function messageSetFlag(string $sMessageFlag, string $sResponseFunction, bool $bSkipUnsupportedFlag = false) : array
{ {
@ -981,8 +969,7 @@ trait Messages
$oIdentity = $this->GetIdentityByID($oAccount, '', true); $oIdentity = $this->GetIdentityByID($oAccount, '', true);
if (empty($sReadReceipt) || empty($sSubject) || empty($sText) || !$oIdentity) if (empty($sReadReceipt) || empty($sSubject) || empty($sText) || !$oIdentity) {
{
throw new ClientException(Notifications::UnknownError); throw new ClientException(Notifications::UnknownError);
} }
@ -1000,11 +987,9 @@ trait Messages
$oMessage->RegenerateMessageId($oFrom ? $oFrom->GetDomain() : ''); $oMessage->RegenerateMessageId($oFrom ? $oFrom->GetDomain() : '');
$sReplyTo = $oIdentity->ReplyTo(); $sReplyTo = $oIdentity->ReplyTo();
if (!empty($sReplyTo)) if (!empty($sReplyTo)) {
{
$oReplyTo = new \MailSo\Mime\EmailCollection($sReplyTo); $oReplyTo = new \MailSo\Mime\EmailCollection($sReplyTo);
if ($oReplyTo && $oReplyTo->Count()) if ($oReplyTo && $oReplyTo->count()) {
{
$oMessage->SetReplyTo($oReplyTo); $oMessage->SetReplyTo($oReplyTo);
} }
} }
@ -1012,8 +997,7 @@ trait Messages
$oMessage->SetSubject($sSubject); $oMessage->SetSubject($sSubject);
$oToEmails = new \MailSo\Mime\EmailCollection($sReadReceipt); $oToEmails = new \MailSo\Mime\EmailCollection($sReadReceipt);
if ($oToEmails && $oToEmails->Count()) if ($oToEmails && $oToEmails->count()) {
{
$oMessage->SetTo($oToEmails); $oMessage->SetTo($oToEmails);
} }