This commit is contained in:
the-djmaze 2024-01-22 11:07:07 +01:00
parent 8749d189df
commit 9558456bcf

View file

@ -156,7 +156,7 @@ trait Messages
$oConfig = $this->Config(); $oConfig = $this->Config();
$sSentFolder = $this->GetActionParam('saveFolder', ''); $sSaveFolder = $this->GetActionParam('saveFolder', '');
$aDraftInfo = $this->GetActionParam('draftInfo', null); $aDraftInfo = $this->GetActionParam('draftInfo', null);
$oMessage = $this->buildMessage($oAccount, false); $oMessage = $this->buildMessage($oAccount, false);
@ -174,9 +174,10 @@ trait Messages
); );
if (false !== $iMessageStreamSize) { if (false !== $iMessageStreamSize) {
$bDsn = !empty($this->GetActionParam('dsn', 0)); $this->smtpSendMessage($oAccount, $oMessage, $rMessageStream, $iMessageStreamSize, true,
$bRequireTLS = !empty($this->GetActionParam('requireTLS', 0)); !empty($this->GetActionParam('dsn', 0)),
$this->smtpSendMessage($oAccount, $oMessage, $rMessageStream, $iMessageStreamSize, true, $bDsn, $bRequireTLS); !empty($this->GetActionParam('requireTLS', 0))
);
if (\is_array($aDraftInfo) && 3 === \count($aDraftInfo)) { if (\is_array($aDraftInfo) && 3 === \count($aDraftInfo)) {
$sDraftInfoType = $aDraftInfo[0]; $sDraftInfoType = $aDraftInfo[0];
@ -202,43 +203,74 @@ trait Messages
} }
} }
if (\strlen($sSentFolder)) { if (\strlen($sSaveFolder)) {
$rAppendMessageStream = $rMessageStream;
$iAppendMessageStreamSize = $iMessageStreamSize;
try try
{ {
if (!$oMessage->GetBcc()) { if ($oMessage->GetBcc()) {
if (\is_resource($rMessageStream)) {
\rewind($rMessageStream);
}
$this->Plugins()->RunHook('filter.send-message-stream',
array($oAccount, &$rMessageStream, &$iMessageStreamSize));
$this->ImapClient()->MessageAppendStream(
$sSentFolder, $rMessageStream, $iMessageStreamSize, array(MessageFlag::SEEN)
);
} else {
$rAppendMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource(); $rAppendMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$iAppendMessageStreamSize = \MailSo\Base\Utils::WriteStream( $iAppendMessageStreamSize = \MailSo\Base\Utils::WriteStream(
$oMessage->ToStream(false), $rAppendMessageStream, 8192, true, true $oMessage->ToStream(false), $rAppendMessageStream, 8192, true, true
); );
} else {
$this->Plugins()->RunHook('filter.send-message-stream', if (\is_resource($rMessageStream)) {
array($oAccount, &$rAppendMessageStream, &$iAppendMessageStreamSize)); \rewind($rMessageStream);
$this->ImapClient()->MessageAppendStream(
$sSentFolder, $rAppendMessageStream, $iAppendMessageStreamSize, array(MessageFlag::SEEN)
);
if (\is_resource($rAppendMessageStream)) {
fclose($rAppendMessageStream);
} }
} }
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->logException($oException, \LOG_ERR);
throw new ClientException(Notifications::CantSaveMessage, $oException); throw new ClientException(Notifications::CantSaveMessage, $oException);
} }
try
{
$this->Plugins()->RunHook('filter.send-message-stream',
array($oAccount, &$rAppendMessageStream, &$iAppendMessageStreamSize));
}
catch (\Throwable $oException)
{
$this->logException($oException, \LOG_ERR);
}
try
{
$this->ImapClient()->MessageAppendStream(
$sSaveFolder, $rAppendMessageStream, $iAppendMessageStreamSize,
array(MessageFlag::SEEN)
);
}
catch (\Throwable $oException)
{
// Save folder not the same as default Sent folder, so try again
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
if ($oSettingsLocal instanceof \RainLoop\Settings) {
$sSentFolder = (string) $oSettingsLocal->GetConf('SentFolder', '');
if (\strlen($sSentFolder) && $sSentFolder !== $sSaveFolder) {
$oException = null;
try
{
$this->ImapClient()->MessageAppendStream(
$sSentFolder, $rAppendMessageStream, $iAppendMessageStreamSize,
array(MessageFlag::SEEN)
);
}
catch (\Throwable $oException)
{
}
}
}
if ($oException) {
$this->logException($oException, \LOG_ERR);
throw new ClientException(Notifications::CantSaveMessage, $oException);
}
}
if (\is_resource($rAppendMessageStream) && $rAppendMessageStream !== $rMessageStream) {
\fclose($rAppendMessageStream);
}
} }
if (\is_resource($rMessageStream)) { if (\is_resource($rMessageStream)) {