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:
Leander Beernaert
2023-05-09 11:15:30 +02:00
parent edac2419f9
commit fb4a0e77af
15 changed files with 697 additions and 438 deletions

View File

@ -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))
}

View File

@ -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")
}