mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2026-02-12 11:58:33 +00:00
feat(GODT-2585): Server Manager
Add a dedicated go-routine whose sole responsibility is to manage the life time of the IMAP and SMTP servers and their listeners. The current implementation behaves the same way as the previous state. The new behavior will be implemented in a follow MR.
This commit is contained in:
@ -297,7 +297,7 @@ func (f *frontendCLI) configureAppleMail(c *ishell.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := f.bridge.ConfigureAppleMail(user.UserID, user.Addresses[0]); err != nil {
|
||||
if err := f.bridge.ConfigureAppleMail(context.Background(), user.UserID, user.Addresses[0]); err != nil {
|
||||
f.printAndLogError(err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ func (f *frontendCLI) changeIMAPSecurity(_ *ishell.Context) {
|
||||
msg := fmt.Sprintf("Are you sure you want to change IMAP setting to %q", newSecurity)
|
||||
|
||||
if f.yesNoQuestion(msg) {
|
||||
if err := f.bridge.SetIMAPSSL(!f.bridge.GetIMAPSSL()); err != nil {
|
||||
if err := f.bridge.SetIMAPSSL(context.Background(), !f.bridge.GetIMAPSSL()); err != nil {
|
||||
f.printAndLogError(err)
|
||||
return
|
||||
}
|
||||
@ -80,7 +80,7 @@ func (f *frontendCLI) changeSMTPSecurity(_ *ishell.Context) {
|
||||
msg := fmt.Sprintf("Are you sure you want to change SMTP setting to %q", newSecurity)
|
||||
|
||||
if f.yesNoQuestion(msg) {
|
||||
if err := f.bridge.SetSMTPSSL(!f.bridge.GetSMTPSSL()); err != nil {
|
||||
if err := f.bridge.SetSMTPSSL(context.Background(), !f.bridge.GetSMTPSSL()); err != nil {
|
||||
f.printAndLogError(err)
|
||||
return
|
||||
}
|
||||
@ -103,7 +103,7 @@ func (f *frontendCLI) changeIMAPPort(c *ishell.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := f.bridge.SetIMAPPort(newIMAPPortInt); err != nil {
|
||||
if err := f.bridge.SetIMAPPort(context.Background(), newIMAPPortInt); err != nil {
|
||||
f.printAndLogError(err)
|
||||
return
|
||||
}
|
||||
@ -125,7 +125,7 @@ func (f *frontendCLI) changeSMTPPort(c *ishell.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := f.bridge.SetSMTPPort(newSMTPPortInt); err != nil {
|
||||
if err := f.bridge.SetSMTPPort(context.Background(), newSMTPPortInt); err != nil {
|
||||
f.printAndLogError(err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -668,7 +668,7 @@ func (s *Service) MailServerSettings(_ context.Context, _ *emptypb.Empty) (*Imap
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) SetMailServerSettings(_ context.Context, settings *ImapSmtpSettings) (*emptypb.Empty, error) {
|
||||
func (s *Service) SetMailServerSettings(ctx context.Context, settings *ImapSmtpSettings) (*emptypb.Empty, error) {
|
||||
s.log.
|
||||
WithField("ImapPort", settings.ImapPort).
|
||||
WithField("SmtpPort", settings.SmtpPort).
|
||||
@ -682,28 +682,28 @@ func (s *Service) SetMailServerSettings(_ context.Context, settings *ImapSmtpSet
|
||||
defer func() { _ = s.SendEvent(NewChangeMailServerSettingsFinishedEvent()) }()
|
||||
|
||||
if s.bridge.GetIMAPSSL() != settings.UseSSLForImap {
|
||||
if err := s.bridge.SetIMAPSSL(settings.UseSSLForImap); err != nil {
|
||||
if err := s.bridge.SetIMAPSSL(ctx, settings.UseSSLForImap); err != nil {
|
||||
s.log.WithError(err).Error("Failed to set IMAP SSL")
|
||||
_ = s.SendEvent(NewMailServerSettingsErrorEvent(MailServerSettingsErrorType_IMAP_CONNECTION_MODE_CHANGE_ERROR))
|
||||
}
|
||||
}
|
||||
|
||||
if s.bridge.GetSMTPSSL() != settings.UseSSLForSmtp {
|
||||
if err := s.bridge.SetSMTPSSL(settings.UseSSLForSmtp); err != nil {
|
||||
if err := s.bridge.SetSMTPSSL(ctx, settings.UseSSLForSmtp); err != nil {
|
||||
s.log.WithError(err).Error("Failed to set SMTP SSL")
|
||||
_ = s.SendEvent(NewMailServerSettingsErrorEvent(MailServerSettingsErrorType_SMTP_CONNECTION_MODE_CHANGE_ERROR))
|
||||
}
|
||||
}
|
||||
|
||||
if s.bridge.GetIMAPPort() != int(settings.ImapPort) {
|
||||
if err := s.bridge.SetIMAPPort(int(settings.ImapPort)); err != nil {
|
||||
if err := s.bridge.SetIMAPPort(ctx, int(settings.ImapPort)); err != nil {
|
||||
s.log.WithError(err).Error("Failed to set IMAP port")
|
||||
_ = s.SendEvent(NewMailServerSettingsErrorEvent(MailServerSettingsErrorType_IMAP_PORT_CHANGE_ERROR))
|
||||
}
|
||||
}
|
||||
|
||||
if s.bridge.GetSMTPPort() != int(settings.SmtpPort) {
|
||||
if err := s.bridge.SetSMTPPort(int(settings.SmtpPort)); err != nil {
|
||||
if err := s.bridge.SetSMTPPort(ctx, int(settings.SmtpPort)); err != nil {
|
||||
s.log.WithError(err).Error("Failed to set SMTP port")
|
||||
_ = s.SendEvent(NewMailServerSettingsErrorEvent(MailServerSettingsErrorType_SMTP_PORT_CHANGE_ERROR))
|
||||
}
|
||||
|
||||
@ -147,12 +147,12 @@ func (s *Service) RemoveUser(_ context.Context, userID *wrapperspb.StringValue)
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func (s *Service) ConfigureUserAppleMail(_ context.Context, request *ConfigureAppleMailRequest) (*emptypb.Empty, error) {
|
||||
func (s *Service) ConfigureUserAppleMail(ctx context.Context, request *ConfigureAppleMailRequest) (*emptypb.Empty, error) {
|
||||
s.log.WithField("UserID", request.UserID).WithField("Address", request.Address).Debug("ConfigureUserAppleMail")
|
||||
|
||||
sslWasEnabled := s.bridge.GetSMTPSSL()
|
||||
|
||||
if err := s.bridge.ConfigureAppleMail(request.UserID, request.Address); err != nil {
|
||||
if err := s.bridge.ConfigureAppleMail(ctx, request.UserID, request.Address); err != nil {
|
||||
s.log.WithField("userID", request.UserID).Error("Cannot configure AppleMail for user")
|
||||
return nil, status.Error(codes.Internal, "Apple Mail config failed")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user