1
0

chore(GODT-2799): Move Identifier interface to separate module

Required so we can move the smtp backend into the smtp service module.
This commit is contained in:
Leander Beernaert
2023-07-18 15:14:30 +02:00
parent d120bbeffc
commit 8d028966c7
6 changed files with 64 additions and 20 deletions

View File

@ -38,6 +38,7 @@ import (
"github.com/ProtonMail/proton-bridge/v3/internal/constants" "github.com/ProtonMail/proton-bridge/v3/internal/constants"
"github.com/ProtonMail/proton-bridge/v3/internal/events" "github.com/ProtonMail/proton-bridge/v3/internal/events"
"github.com/ProtonMail/proton-bridge/v3/internal/focus" "github.com/ProtonMail/proton-bridge/v3/internal/focus"
"github.com/ProtonMail/proton-bridge/v3/internal/identifier"
"github.com/ProtonMail/proton-bridge/v3/internal/safe" "github.com/ProtonMail/proton-bridge/v3/internal/safe"
"github.com/ProtonMail/proton-bridge/v3/internal/sentry" "github.com/ProtonMail/proton-bridge/v3/internal/sentry"
"github.com/ProtonMail/proton-bridge/v3/internal/telemetry" "github.com/ProtonMail/proton-bridge/v3/internal/telemetry"
@ -59,7 +60,7 @@ type Bridge struct {
// api manages user API clients. // api manages user API clients.
api *proton.Manager api *proton.Manager
proxyCtl ProxyController proxyCtl ProxyController
identifier Identifier identifier identifier.Identifier
// tlsConfig holds the bridge TLS config used by the IMAP and SMTP servers. // tlsConfig holds the bridge TLS config used by the IMAP and SMTP servers.
tlsConfig *tls.Config tlsConfig *tls.Config
@ -140,7 +141,7 @@ func New(
apiURL string, // the URL of the API to use apiURL string, // the URL of the API to use
cookieJar http.CookieJar, // the cookie jar to use cookieJar http.CookieJar, // the cookie jar to use
identifier Identifier, // the identifier to keep track of the user agent identifier identifier.Identifier, // the identifier to keep track of the user agent
tlsReporter TLSReporter, // the TLS reporter to report TLS errors tlsReporter TLSReporter, // the TLS reporter to report TLS errors
roundTripper http.RoundTripper, // the round tripper to use for API requests roundTripper http.RoundTripper, // the round tripper to use for API requests
proxyCtl ProxyController, // the DoH controller proxyCtl ProxyController, // the DoH controller
@ -207,7 +208,7 @@ func newBridge(
reporter reporter.Reporter, reporter reporter.Reporter,
api *proton.Manager, api *proton.Manager,
identifier Identifier, identifier identifier.Identifier,
proxyCtl ProxyController, proxyCtl ProxyController,
uidValidityGenerator imap.UIDValidityGenerator, uidValidityGenerator imap.UIDValidityGenerator,

View File

@ -45,6 +45,30 @@ type bridgeUserAgentUpdater struct {
*Bridge *Bridge
} }
func (b *bridgeUserAgentUpdater) GetUserAgent() string {
return b.identifier.GetUserAgent()
}
func (b *bridgeUserAgentUpdater) HasClient() bool {
return b.identifier.HasClient()
}
func (b *bridgeUserAgentUpdater) SetClient(name, version string) {
b.identifier.SetClient(name, version)
}
func (b *bridgeUserAgentUpdater) SetPlatform(platform string) {
b.identifier.SetPlatform(platform)
}
func (b *bridgeUserAgentUpdater) SetClientString(client string) {
b.identifier.SetClientString(client)
}
func (b *bridgeUserAgentUpdater) GetClientString() string {
return b.identifier.GetClientString()
}
func (b *bridgeUserAgentUpdater) SetUserAgent(name, version string) { func (b *bridgeUserAgentUpdater) SetUserAgent(name, version string) {
b.setUserAgent(name, version) b.setUserAgent(name, version)
} }

View File

@ -36,7 +36,7 @@ func (bridge *Bridge) restartSMTP(ctx context.Context) error {
func newSMTPServer(bridge *Bridge, accounts *bridgesmtp.Accounts, tlsConfig *tls.Config, logSMTP bool) *smtp.Server { func newSMTPServer(bridge *Bridge, accounts *bridgesmtp.Accounts, tlsConfig *tls.Config, logSMTP bool) *smtp.Server {
logrus.WithField("logSMTP", logSMTP).Info("Creating SMTP server") logrus.WithField("logSMTP", logSMTP).Info("Creating SMTP server")
smtpServer := smtp.NewServer(&smtpBackend{bridge: bridge, accounts: accounts}) smtpServer := smtp.NewServer(&smtpBackend{userAgent: &bridgeUserAgentUpdater{Bridge: bridge}, accounts: accounts})
smtpServer.TLSConfig = tlsConfig smtpServer.TLSConfig = tlsConfig
smtpServer.Domain = constants.Host smtpServer.Domain = constants.Host

View File

@ -24,6 +24,7 @@ import (
"io" "io"
"strings" "strings"
"github.com/ProtonMail/proton-bridge/v3/internal/identifier"
smtpservice "github.com/ProtonMail/proton-bridge/v3/internal/services/smtp" smtpservice "github.com/ProtonMail/proton-bridge/v3/internal/services/smtp"
"github.com/ProtonMail/proton-bridge/v3/internal/useragent" "github.com/ProtonMail/proton-bridge/v3/internal/useragent"
"github.com/emersion/go-smtp" "github.com/emersion/go-smtp"
@ -32,12 +33,12 @@ import (
type smtpBackend struct { type smtpBackend struct {
accounts *smtpservice.Accounts accounts *smtpservice.Accounts
userAgent UserAgentUpdater userAgent identifier.UserAgentUpdater
} }
type smtpSession struct { type smtpSession struct {
accounts *smtpservice.Accounts accounts *smtpservice.Accounts
userAgent UserAgentUpdater userAgent identifier.UserAgentUpdater
userID string userID string
authID string authID string

View File

@ -34,20 +34,6 @@ type Locator interface {
Clear(...string) error Clear(...string) error
} }
type Identifier interface {
GetUserAgent() string
HasClient() bool
SetClient(name, version string)
SetPlatform(platform string)
SetClientString(client string)
GetClientString() string
}
type UserAgentUpdater interface {
Identifier
SetUserAgent(name, version string)
}
type ProxyController interface { type ProxyController interface {
AllowProxy() AllowProxy()
DisallowProxy() DisallowProxy()

View File

@ -0,0 +1,32 @@
// 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 identifier
type Identifier interface {
GetUserAgent() string
HasClient() bool
SetClient(name, version string)
SetPlatform(platform string)
SetClientString(client string)
GetClientString() string
}
type UserAgentUpdater interface {
Identifier
SetUserAgent(name, version string)
}