From 56f4f3d017034c23e61af3dfa4b1fd002037248a Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Wed, 19 Aug 2020 15:25:38 +0200 Subject: [PATCH] fix: better error handling when message is still in send queue --- internal/smtp/user.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/smtp/user.go b/internal/smtp/user.go index f0f55917..a17f93de 100644 --- a/internal/smtp/user.go +++ b/internal/smtp/user.go @@ -216,14 +216,16 @@ func (su *smtpUser) Send(from string, to []string, messageReader io.Reader) (err // nil to indicate it's OK. sendRecorderMessageHash := su.backend.sendRecorder.getMessageHash(message) isSending, wasSent := su.backend.sendRecorder.isSendingOrSent(su.client(), sendRecorderMessageHash) - if isSending { - log.Debug("Message is in send queue, waiting") - time.Sleep(60 * time.Second) + + startTime := time.Now() + for isSending && time.Since(startTime) < 90*time.Second { + log.Debug("Message is still in send queue, waiting for a bit") + time.Sleep(15 * time.Second) isSending, wasSent = su.backend.sendRecorder.isSendingOrSent(su.client(), sendRecorderMessageHash) } if isSending { - log.Debug("Message is still in send queue, returning error") - return errors.New("message is sending") + log.Debug("Message is still in send queue, returning error to prevent client from adding it to the sent folder prematurely") + return errors.New("original message is still being sent") } if wasSent { log.Debug("Message was already sent")