mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-22 01:56:44 +00:00
Other(refactor): Remove unencrypted recipient confirmation
This commit is contained in:
@ -26,20 +26,17 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime"
|
||||
"net/mail"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/events"
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/listener"
|
||||
pkgMsg "github.com/ProtonMail/proton-bridge/v2/pkg/message"
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/message/parser"
|
||||
"github.com/ProtonMail/proton-bridge/v2/pkg/pmapi"
|
||||
goSMTPBackend "github.com/emersion/go-smtp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type smtpUser struct {
|
||||
@ -361,7 +358,6 @@ func (su *smtpUser) Send(returnPath string, to []string, messageReader io.Reader
|
||||
}
|
||||
|
||||
req := pmapi.NewSendMessageReq(kr, mimeBody, plainBody, richBody, attkeys)
|
||||
containsUnencryptedRecipients := false
|
||||
|
||||
for _, recipient := range message.Recipients() {
|
||||
email := recipient.Address
|
||||
@ -370,9 +366,6 @@ func (su *smtpUser) Send(returnPath string, to []string, messageReader io.Reader
|
||||
}
|
||||
|
||||
sendPreferences, err := su.getSendPreferences(email, message.MIMEType, mailSettings)
|
||||
if !sendPreferences.Encrypt {
|
||||
containsUnencryptedRecipients = true
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -389,20 +382,6 @@ func (su *smtpUser) Send(returnPath string, to []string, messageReader io.Reader
|
||||
}
|
||||
}
|
||||
|
||||
if containsUnencryptedRecipients {
|
||||
dec := new(mime.WordDecoder)
|
||||
subject, err := dec.DecodeHeader(message.Header.Get("Subject"))
|
||||
if err != nil {
|
||||
return errors.New("error decoding subject message " + message.Header.Get("Subject"))
|
||||
}
|
||||
if !su.continueSendingUnencryptedMail(subject) {
|
||||
if err := su.client().DeleteMessages(context.TODO(), []string{message.ID}); err != nil {
|
||||
log.WithError(err).Warn("Failed to delete canceled messages")
|
||||
}
|
||||
return errors.New("sending was canceled by user")
|
||||
}
|
||||
}
|
||||
|
||||
req.PreparePackages()
|
||||
|
||||
dumpMessageData(b.Bytes(), message.Subject)
|
||||
@ -511,27 +490,6 @@ func (su *smtpUser) handleSenderAndRecipients(m *pmapi.Message, returnPathAddr *
|
||||
return nil
|
||||
}
|
||||
|
||||
func (su *smtpUser) continueSendingUnencryptedMail(subject string) bool {
|
||||
if !su.backend.shouldReportOutgoingNoEnc() {
|
||||
return true
|
||||
}
|
||||
|
||||
// GUI should always respond in 10 seconds, but let's have safety timeout
|
||||
// in case GUI will not respond properly. If GUI didn't respond, we cannot
|
||||
// be sure if user even saw the notice: better to not send the e-mail.
|
||||
req := su.backend.confirmer.NewRequest(15 * time.Second)
|
||||
|
||||
su.eventListener.Emit(events.OutgoingNoEncEvent, req.ID()+":"+subject)
|
||||
|
||||
res, err := req.Result()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("Failed to determine whether to send unencrypted, assuming no")
|
||||
return false
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// Logout is called when this User will no longer be used.
|
||||
func (su *smtpUser) Logout() error {
|
||||
log.Debug("SMTP client logged out user ", su.addressID)
|
||||
|
||||
Reference in New Issue
Block a user