fix(GODT-2802): Consolidate Address Mode

This commit is contained in:
Leander Beernaert
2023-07-25 09:15:52 +02:00
parent 09c523e2d2
commit 1b0f930471
4 changed files with 58 additions and 29 deletions

View File

@ -31,6 +31,7 @@ import (
"github.com/ProtonMail/proton-bridge/v3/internal/services/sendrecorder"
"github.com/ProtonMail/proton-bridge/v3/internal/services/userevents"
"github.com/ProtonMail/proton-bridge/v3/internal/services/useridentity"
"github.com/ProtonMail/proton-bridge/v3/internal/usertypes"
"github.com/ProtonMail/proton-bridge/v3/pkg/cpc"
"github.com/sirupsen/logrus"
)
@ -41,13 +42,6 @@ type Telemetry interface {
ReportSMTPAuthFailed(username string)
}
type AddressMode int
const (
AddressModeCombined AddressMode = iota
AddressModeSplit
)
type Service struct {
userID string
panicHandler async.PanicHandler
@ -67,7 +61,7 @@ type Service struct {
addressSubscriber *userevents.AddressChanneledSubscriber
userSubscriber *userevents.UserChanneledSubscriber
addressMode AddressMode
addressMode usertypes.AddressMode
}
func NewService(
@ -80,7 +74,7 @@ func NewService(
keyPassProvider useridentity.KeyPassProvider,
telemetry Telemetry,
eventService userevents.Subscribable,
mode AddressMode,
mode usertypes.AddressMode,
identityState *useridentity.State,
) *Service {
subscriberName := fmt.Sprintf("smpt-%v", userID)
@ -122,7 +116,7 @@ func (s *Service) SendMail(ctx context.Context, authID string, from string, to [
return err
}
func (s *Service) SetAddressMode(ctx context.Context, mode AddressMode) error {
func (s *Service) SetAddressMode(ctx context.Context, mode usertypes.AddressMode) error {
_, err := s.cpc.Send(ctx, &setAddressModeReq{mode: mode})
return err
@ -248,7 +242,7 @@ func (s *Service) sendMail(ctx context.Context, req *sendMailReq) error {
}
type setAddressModeReq struct {
mode AddressMode
mode usertypes.AddressMode
}
type checkAuthReq struct {

View File

@ -160,7 +160,7 @@ func (s *Service) smtpSendMail(ctx context.Context, authID string, from string,
func (s *Service) sendWithKey(
ctx context.Context,
authAddrID string,
addrMode AddressMode,
addrMode usertypes.AddressMode,
settings proton.MailSettings,
userKR, addrKR *crypto.KeyRing,
emails []string,
@ -241,7 +241,7 @@ func getParentID(
ctx context.Context,
client *proton.Client,
authAddrID string,
addrMode AddressMode,
addrMode usertypes.AddressMode,
references []string,
) (string, error) {
var (
@ -263,7 +263,7 @@ func getParentID(
for _, internal := range internal {
var addrID string
if addrMode == AddressModeSplit {
if addrMode == usertypes.AddressModeSplit {
addrID = authAddrID
}
@ -291,7 +291,7 @@ func getParentID(
if parentID == "" && len(external) > 0 {
var addrID string
if addrMode == AddressModeSplit {
if addrMode == usertypes.AddressModeSplit {
addrID = authAddrID
}