mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-11 13:16:53 +00:00
65 lines
2.3 KiB
Go
65 lines
2.3 KiB
Go
// 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 bridge
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
|
|
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
|
|
"github.com/ProtonMail/proton-bridge/v3/internal/logging"
|
|
bridgesmtp "github.com/ProtonMail/proton-bridge/v3/internal/services/smtp"
|
|
"github.com/emersion/go-sasl"
|
|
"github.com/emersion/go-smtp"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (bridge *Bridge) restartSMTP(ctx context.Context) error {
|
|
return bridge.serverManager.RestartSMTP(ctx)
|
|
}
|
|
|
|
func newSMTPServer(bridge *Bridge, accounts *bridgesmtp.Accounts, tlsConfig *tls.Config, logSMTP bool) *smtp.Server {
|
|
logrus.WithField("logSMTP", logSMTP).Info("Creating SMTP server")
|
|
|
|
smtpServer := smtp.NewServer(&smtpBackend{userAgent: &bridgeUserAgentUpdater{Bridge: bridge}, accounts: accounts})
|
|
|
|
smtpServer.TLSConfig = tlsConfig
|
|
smtpServer.Domain = constants.Host
|
|
smtpServer.AllowInsecureAuth = true
|
|
smtpServer.MaxLineLength = 1 << 16
|
|
smtpServer.ErrorLog = logging.NewSMTPLogger()
|
|
|
|
// go-smtp suppors SASL PLAIN but not LOGIN. We need to add LOGIN support ourselves.
|
|
smtpServer.EnableAuth(sasl.Login, func(conn *smtp.Conn) sasl.Server {
|
|
return sasl.NewLoginServer(func(username, password string) error {
|
|
return conn.Session().AuthPlain(username, password)
|
|
})
|
|
})
|
|
|
|
if logSMTP {
|
|
log := logrus.WithField("protocol", "SMTP")
|
|
log.Warning("================================================")
|
|
log.Warning("THIS LOG WILL CONTAIN **DECRYPTED** MESSAGE DATA")
|
|
log.Warning("================================================")
|
|
|
|
smtpServer.Debug = logging.NewSMTPDebugLogger()
|
|
}
|
|
|
|
return smtpServer
|
|
}
|