diff --git a/protocol/messenger_mailserver_cycle.go b/protocol/messenger_mailserver_cycle.go index 53861757a..a23cc4c4f 100644 --- a/protocol/messenger_mailserver_cycle.go +++ b/protocol/messenger_mailserver_cycle.go @@ -151,7 +151,18 @@ func (m *Messenger) cycleMailservers() { m.disconnectActiveMailserver() } - err := m.findNewMailserver() + useMailserver, err := m.settings.CanUseMailservers() + if err != nil { + m.logger.Error("failed to get use mailservers", zap.Error(err)) + return + } + + if !useMailserver { + m.logger.Info("Skipping mailserver search due to useMailserver being false") + return + } + + err = m.findNewMailserver() if err != nil { m.logger.Error("Error getting new mailserver", zap.Error(err)) } diff --git a/protocol/messenger_storenode_comunity_test.go b/protocol/messenger_storenode_comunity_test.go index ad0e2f921..8216fdbde 100644 --- a/protocol/messenger_storenode_comunity_test.go +++ b/protocol/messenger_storenode_comunity_test.go @@ -342,3 +342,15 @@ func (s *MessengerStoreNodeCommunitySuite) TestSetStorenodeForCommunity_fetchMes }) s.Require().NoError(err) } + +func (s *MessengerStoreNodeCommunitySuite) TestToggleUseMailservers() { + // Enable use of mailservers + err := s.owner.ToggleUseMailservers(true) + s.Require().NoError(err) + s.Require().NotNil(s.owner.mailserverCycle.activeMailserver) + + // Disable use of mailservers + err = s.owner.ToggleUseMailservers(false) + s.Require().NoError(err) + s.Require().Nil(s.owner.mailserverCycle.activeMailserver) +}