mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 12:46:46 +00:00
fix(GODT-3122): use display name as 'Email Account Name' in macOS profile.
This commit is contained in:
@ -19,19 +19,22 @@ package bridge
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/clientconfig"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/logging"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/safe"
|
||||
userpkg "github.com/ProtonMail/proton-bridge/v3/internal/user"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/useragent"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
// ConfigureAppleMail configures apple mail for the given userID and address.
|
||||
// If configuring apple mail for Catalina or newer, it ensures Bridge is using SSL.
|
||||
// ConfigureAppleMail configures Apple Mail for the given userID and address.
|
||||
// If configuring Apple Mail for Catalina or newer, it ensures Bridge is using SSL.
|
||||
func (bridge *Bridge) ConfigureAppleMail(ctx context.Context, userID, address string) error {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"userID": userID,
|
||||
@ -44,16 +47,31 @@ func (bridge *Bridge) ConfigureAppleMail(ctx context.Context, userID, address st
|
||||
return ErrNoSuchUser
|
||||
}
|
||||
|
||||
if address == "" {
|
||||
address = user.Emails()[0]
|
||||
identities := user.Identities()
|
||||
if len(identities) == 0 {
|
||||
return errors.New("could not retrieve user identities")
|
||||
}
|
||||
|
||||
username := address
|
||||
addresses := address
|
||||
if address == "" {
|
||||
address = identities[0].Email
|
||||
}
|
||||
|
||||
var username, displayName, addresses string
|
||||
if user.GetAddressMode() == vault.CombinedMode {
|
||||
username = user.Emails()[0]
|
||||
username = identities[0].Email
|
||||
displayName = identities[0].DisplayName
|
||||
addresses = strings.Join(user.Emails(), ",")
|
||||
} else {
|
||||
username = address
|
||||
addresses = address
|
||||
index := slices.IndexFunc(identities, func(identity userpkg.Identity) bool {
|
||||
return strings.EqualFold(identity.Email, address)
|
||||
})
|
||||
if index >= 0 {
|
||||
displayName = identities[index].DisplayName
|
||||
} else {
|
||||
displayName = address
|
||||
}
|
||||
}
|
||||
|
||||
if useragent.IsCatalinaOrNewer() && !bridge.vault.GetSMTPSSL() {
|
||||
@ -69,6 +87,7 @@ func (bridge *Bridge) ConfigureAppleMail(ctx context.Context, userID, address st
|
||||
bridge.vault.GetIMAPSSL(),
|
||||
bridge.vault.GetSMTPSSL(),
|
||||
username,
|
||||
displayName,
|
||||
addresses,
|
||||
user.BridgePass(),
|
||||
)
|
||||
|
||||
@ -39,10 +39,10 @@ func (c *AppleMail) Configure(
|
||||
hostname string,
|
||||
imapPort, smtpPort int,
|
||||
imapSSL, smtpSSL bool,
|
||||
username, addresses string,
|
||||
username, displayName, addresses string,
|
||||
password []byte,
|
||||
) error {
|
||||
mc := prepareMobileConfig(hostname, imapPort, smtpPort, imapSSL, smtpSSL, username, addresses, password)
|
||||
mc := prepareMobileConfig(hostname, imapPort, smtpPort, imapSSL, smtpSSL, username, displayName, addresses, password)
|
||||
|
||||
confPath, err := saveConfigTemporarily(mc)
|
||||
if err != nil {
|
||||
@ -66,13 +66,13 @@ func prepareMobileConfig(
|
||||
hostname string,
|
||||
imapPort, smtpPort int,
|
||||
imapSSL, smtpSSL bool,
|
||||
username, addresses string,
|
||||
username, displayName, addresses string,
|
||||
password []byte,
|
||||
) *mobileconfig.Config {
|
||||
return &mobileconfig.Config{
|
||||
DisplayName: username,
|
||||
EmailAddress: addresses,
|
||||
AccountName: username,
|
||||
AccountName: displayName,
|
||||
AccountDescription: username,
|
||||
Identifier: "protonmail " + username + strconv.FormatInt(time.Now().Unix(), 10),
|
||||
IMAP: &mobileconfig.IMAP{
|
||||
|
||||
@ -58,6 +58,11 @@ const (
|
||||
SyncRetryCooldown = 20 * time.Second
|
||||
)
|
||||
|
||||
type Identity struct {
|
||||
DisplayName string
|
||||
Email string
|
||||
}
|
||||
|
||||
type User struct {
|
||||
id string
|
||||
log *logrus.Entry
|
||||
@ -378,19 +383,16 @@ func (user *User) Match(query string) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Emails returns all the user's active email addresses.
|
||||
// It returns them in sorted order; the user's primary address is first.
|
||||
func (user *User) Emails() []string {
|
||||
func (user *User) Identities() []Identity {
|
||||
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Minute))
|
||||
defer cancel()
|
||||
|
||||
apiAddrs, err := user.identityService.GetAddresses(ctx)
|
||||
apiAddresses, err := user.identityService.GetAddresses(ctx)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
addresses := xslices.Filter(maps.Values(apiAddrs), func(addr proton.Address) bool {
|
||||
addresses := xslices.Filter(maps.Values(apiAddresses), func(addr proton.Address) bool {
|
||||
return addr.Status == proton.AddressStatusEnabled && addr.Type != proton.AddressTypeExternal
|
||||
})
|
||||
|
||||
@ -398,8 +400,24 @@ func (user *User) Emails() []string {
|
||||
return a.Order < b.Order
|
||||
})
|
||||
|
||||
return xslices.Map(addresses, func(addr proton.Address) string {
|
||||
return addr.Email
|
||||
return xslices.Map(addresses, func(addr proton.Address) Identity {
|
||||
return Identity{
|
||||
DisplayName: addr.DisplayName,
|
||||
Email: addr.Email,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Emails returns all the user's active email addresses.
|
||||
// It returns them in sorted order; the user's primary address is first.
|
||||
func (user *User) Emails() []string {
|
||||
identities := user.Identities()
|
||||
if identities == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return xslices.Map(identities, func(identity Identity) string {
|
||||
return identity.Email
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user