mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 08:06:59 +00:00
fix(GODT-2802): Consolidate Address Mode
This commit is contained in:
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/ProtonMail/proton-bridge/v3/internal/services/sendrecorder"
|
"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/userevents"
|
||||||
"github.com/ProtonMail/proton-bridge/v3/internal/services/useridentity"
|
"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/ProtonMail/proton-bridge/v3/pkg/cpc"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -41,13 +42,6 @@ type Telemetry interface {
|
|||||||
ReportSMTPAuthFailed(username string)
|
ReportSMTPAuthFailed(username string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddressMode int
|
|
||||||
|
|
||||||
const (
|
|
||||||
AddressModeCombined AddressMode = iota
|
|
||||||
AddressModeSplit
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
userID string
|
userID string
|
||||||
panicHandler async.PanicHandler
|
panicHandler async.PanicHandler
|
||||||
@ -67,7 +61,7 @@ type Service struct {
|
|||||||
addressSubscriber *userevents.AddressChanneledSubscriber
|
addressSubscriber *userevents.AddressChanneledSubscriber
|
||||||
userSubscriber *userevents.UserChanneledSubscriber
|
userSubscriber *userevents.UserChanneledSubscriber
|
||||||
|
|
||||||
addressMode AddressMode
|
addressMode usertypes.AddressMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(
|
func NewService(
|
||||||
@ -80,7 +74,7 @@ func NewService(
|
|||||||
keyPassProvider useridentity.KeyPassProvider,
|
keyPassProvider useridentity.KeyPassProvider,
|
||||||
telemetry Telemetry,
|
telemetry Telemetry,
|
||||||
eventService userevents.Subscribable,
|
eventService userevents.Subscribable,
|
||||||
mode AddressMode,
|
mode usertypes.AddressMode,
|
||||||
identityState *useridentity.State,
|
identityState *useridentity.State,
|
||||||
) *Service {
|
) *Service {
|
||||||
subscriberName := fmt.Sprintf("smpt-%v", userID)
|
subscriberName := fmt.Sprintf("smpt-%v", userID)
|
||||||
@ -122,7 +116,7 @@ func (s *Service) SendMail(ctx context.Context, authID string, from string, to [
|
|||||||
return err
|
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})
|
_, err := s.cpc.Send(ctx, &setAddressModeReq{mode: mode})
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@ -248,7 +242,7 @@ func (s *Service) sendMail(ctx context.Context, req *sendMailReq) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type setAddressModeReq struct {
|
type setAddressModeReq struct {
|
||||||
mode AddressMode
|
mode usertypes.AddressMode
|
||||||
}
|
}
|
||||||
|
|
||||||
type checkAuthReq struct {
|
type checkAuthReq struct {
|
||||||
|
|||||||
@ -160,7 +160,7 @@ func (s *Service) smtpSendMail(ctx context.Context, authID string, from string,
|
|||||||
func (s *Service) sendWithKey(
|
func (s *Service) sendWithKey(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
authAddrID string,
|
authAddrID string,
|
||||||
addrMode AddressMode,
|
addrMode usertypes.AddressMode,
|
||||||
settings proton.MailSettings,
|
settings proton.MailSettings,
|
||||||
userKR, addrKR *crypto.KeyRing,
|
userKR, addrKR *crypto.KeyRing,
|
||||||
emails []string,
|
emails []string,
|
||||||
@ -241,7 +241,7 @@ func getParentID(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
client *proton.Client,
|
client *proton.Client,
|
||||||
authAddrID string,
|
authAddrID string,
|
||||||
addrMode AddressMode,
|
addrMode usertypes.AddressMode,
|
||||||
references []string,
|
references []string,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
var (
|
var (
|
||||||
@ -263,7 +263,7 @@ func getParentID(
|
|||||||
for _, internal := range internal {
|
for _, internal := range internal {
|
||||||
var addrID string
|
var addrID string
|
||||||
|
|
||||||
if addrMode == AddressModeSplit {
|
if addrMode == usertypes.AddressModeSplit {
|
||||||
addrID = authAddrID
|
addrID = authAddrID
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +291,7 @@ func getParentID(
|
|||||||
if parentID == "" && len(external) > 0 {
|
if parentID == "" && len(external) > 0 {
|
||||||
var addrID string
|
var addrID string
|
||||||
|
|
||||||
if addrMode == AddressModeSplit {
|
if addrMode == usertypes.AddressModeSplit {
|
||||||
addrID = authAddrID
|
addrID = authAddrID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -224,7 +224,7 @@ func New(
|
|||||||
encVault,
|
encVault,
|
||||||
user,
|
user,
|
||||||
eventService,
|
eventService,
|
||||||
vaultToSMTPAddressMode(encVault.AddressMode()),
|
usertypes.VaultToAddressMode(encVault.AddressMode()),
|
||||||
identityState.Clone(),
|
identityState.Clone(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -402,7 +402,7 @@ func (user *User) SetAddressMode(ctx context.Context, mode vault.AddressMode) er
|
|||||||
return fmt.Errorf("failed to set address mode: %w", err)
|
return fmt.Errorf("failed to set address mode: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user.smtpService.SetAddressMode(ctx, vaultToSMTPAddressMode(mode)); err != nil {
|
if err := user.smtpService.SetAddressMode(ctx, usertypes.VaultToAddressMode(mode)); err != nil {
|
||||||
return fmt.Errorf("failed to set smtp address mode: %w", err)
|
return fmt.Errorf("failed to set smtp address mode: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -917,15 +917,3 @@ func sleepCtx(ctx context.Context, d time.Duration) {
|
|||||||
case <-time.After(d):
|
case <-time.After(d):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func vaultToSMTPAddressMode(mode vault.AddressMode) smtp.AddressMode {
|
|
||||||
var smtpAddressMode smtp.AddressMode
|
|
||||||
|
|
||||||
if mode == vault.SplitMode {
|
|
||||||
smtpAddressMode = smtp.AddressModeSplit
|
|
||||||
} else {
|
|
||||||
smtpAddressMode = smtp.AddressModeCombined
|
|
||||||
}
|
|
||||||
|
|
||||||
return smtpAddressMode
|
|
||||||
}
|
|
||||||
|
|||||||
47
internal/usertypes/addressmode.go
Normal file
47
internal/usertypes/addressmode.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (c) 2023 Proton AG
|
||||||
|
//
|
||||||
|
// This file is part of Proton Mail Bridge.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Proton Mail Bridge is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package usertypes
|
||||||
|
|
||||||
|
import "github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
||||||
|
|
||||||
|
type AddressMode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
AddressModeCombined AddressMode = iota
|
||||||
|
AddressModeSplit
|
||||||
|
)
|
||||||
|
|
||||||
|
func VaultToAddressMode(mode vault.AddressMode) AddressMode {
|
||||||
|
var smtpAddressMode AddressMode
|
||||||
|
|
||||||
|
if mode == vault.SplitMode {
|
||||||
|
smtpAddressMode = AddressModeSplit
|
||||||
|
} else {
|
||||||
|
smtpAddressMode = AddressModeCombined
|
||||||
|
}
|
||||||
|
|
||||||
|
return smtpAddressMode
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddressModeToVault(mode AddressMode) vault.AddressMode {
|
||||||
|
if mode == AddressModeCombined {
|
||||||
|
return vault.CombinedMode
|
||||||
|
}
|
||||||
|
|
||||||
|
return vault.SplitMode
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user