From 2656d362d63dcd4bc3fff00afc3e17e511602d88 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 23 Apr 2024 15:10:45 +0200 Subject: [PATCH] Added idea to ask SMTP credentials on AUTH failure --- dev/View/Popup/Compose.js | 141 ++++++++++-------- .../libraries/RainLoop/Actions/Messages.php | 17 ++- 2 files changed, 97 insertions(+), 61 deletions(-) diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index 6b43fd6e8..6335ecd02 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -489,70 +489,91 @@ export class ComposePopupView extends AbstractViewPopup { if (!sSentFolder) { showScreenPopup(FolderSystemPopupView, [FolderType.Sent]); - } else try { - this.sendError(false); - this.sending(true); - - sSentFolder = UNUSED_OPTION_VALUE === sSentFolder ? '' : sSentFolder; - - this.getMessageRequestParams(sSentFolder).then(params => { - Remote.request('SendMessage', - (iError, data) => { - this.sending(false); - if (iError) { - if (Notifications.CantSaveMessage === iError) { - this.sendSuccessButSaveError(true); - let msg = i18n('COMPOSE/SAVED_ERROR_ON_SEND'); - if (data?.ErrorMessageAdditional) { - msg = msg + "\n" + data?.ErrorMessageAdditional; - } - this.savedErrorDesc(msg); - } else { - params.signPassphrase && Passphrases.delete(identity); - this.sendError(true); - this.sendErrorDesc( - getNotification(iError, data?.ErrorMessage, Notifications.CantSendMessage) - + "\n" + data?.ErrorMessageAdditional - ); - } - } else { - if (arrayLength(this.aDraftInfo) > 0) { - const flag = { - 'reply': '\\answered', - 'forward': '$forwarded' - }[this.aDraftInfo[0]]; - if (flag) { - const aFlags = oLastMessage.flags(); - if (aFlags.indexOf(flag) === -1) { - aFlags.push(flag); - oLastMessage.flags(aFlags); - } - } - } - this.close(); - } - setFolderETag(this.draftsFolder(), ''); - setFolderETag(sSentFolder, ''); - if (3 === arrayLength(this.aDraftInfo)) { - const folder = this.aDraftInfo[2]; - setFolderETag(folder, ''); - } - reloadDraftFolder(); - }, - params, - 30000 - ); - }).catch(e => { + } else { + const sendError = e => { console.error(e); this.sendError(true); this.sendErrorDesc(e); this.sending(false); - }); - } catch (e) { - console.error(e); - this.sendError(true); - this.sendErrorDesc(e); - this.sending(false); + }; + const sendFailed = (iError, data) => { + this.sendError(true); + this.sendErrorDesc( + getNotification(iError, data?.ErrorMessage, Notifications.CantSendMessage) + + "\n" + data?.ErrorMessageAdditional + ); + }; + try { + this.sendError(false); + this.sending(true); + + sSentFolder = UNUSED_OPTION_VALUE === sSentFolder ? '' : sSentFolder; + + const sendMessage = params => { + Remote.request('SendMessage', + (iError, data) => { + this.sending(false); + if (iError) { +/* + if (Notifications.AuthError === iError && !params.auth) { + AskPopupView.password('SMTP login', 'retry', 3).then(result => { + if (result) { + this.sending(true); + params.auth = result; + sendMessage(params); + } else { + sendFailed(iError, data); + } + }); + } else +*/ + if (Notifications.CantSaveMessage === iError) { + this.sendSuccessButSaveError(true); + let msg = i18n('COMPOSE/SAVED_ERROR_ON_SEND'); + if (data?.ErrorMessageAdditional) { + msg = msg + "\n" + data?.ErrorMessageAdditional; + } + this.savedErrorDesc(msg); + } else { + params.signPassphrase && Passphrases.delete(identity); + this.sendError(true); + sendFailed(iError, data); + } + } else { + if (arrayLength(this.aDraftInfo) > 0) { + const flag = { + 'reply': '\\answered', + 'forward': '$forwarded' + }[this.aDraftInfo[0]]; + if (flag) { + const aFlags = oLastMessage.flags(); + if (aFlags.indexOf(flag) === -1) { + aFlags.push(flag); + oLastMessage.flags(aFlags); + } + } + } + this.close(); + } + setFolderETag(this.draftsFolder(), ''); + setFolderETag(sSentFolder, ''); + if (3 === arrayLength(this.aDraftInfo)) { + const folder = this.aDraftInfo[2]; + setFolderETag(folder, ''); + } + reloadDraftFolder(); + }, + params, + 30000 + ); + }; + + this.getMessageRequestParams(sSentFolder) + .then(sendMessage) + .catch(sendError); + } catch (e) { + sendError(e); + } } } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php index 9215c1760..b630d8ba0 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php @@ -157,7 +157,18 @@ trait Messages public function DoSendMessage() : array { $oAccount = $this->initMailClientConnection(); - +/* + $aAuth = $this->GetActionParam('auth', null); + if ($aAuth) { + $oAccount->setSmtpUser($aAuth['username']); + $oAccount->setSmtpPass(new \SnappyMail\SensitiveString($aAuth['password'])); +// if ($oAccount instanceof AdditionalAccount && !empty($aAuth['remember'])) { +// $oMainAccount = $this->getMainAccountFromToken(); +// $aAccounts = $this->GetAccounts($oMainAccount); +// $this->SetAccounts($oMainAccount, $aAccounts); +// } + } +*/ $oConfig = $this->Config(); $sSaveFolder = $this->GetActionParam('saveFolder', ''); @@ -300,6 +311,10 @@ trait Messages } } } + catch (\MailSo\Smtp\Exceptions\LoginBadCredentialsException $oException) + { + throw new ClientException(Notifications::AuthError, $oException); + } catch (ClientException $oException) { throw $oException;