add email rotation regarding a limit

This commit is contained in:
2025-03-13 13:33:51 +01:00
parent fcb56f9a7f
commit 0c23304d34
5 changed files with 66 additions and 2 deletions

View File

@ -43,6 +43,11 @@ func getServiceContainer(conf *config.Config) (*service.Container, error) {
cqrs.CommandHandlerFunc(command.HandleStoreEmail),
)
bus.RegisterCommand(
cqrs.MatchCommandRequest(&command.RotateEmailRequest{}),
cqrs.CommandHandlerFunc(command.HandleRotateEmail),
)
bus.RegisterCommand(
cqrs.MatchCommandRequest(&command.ClearInboxRequest{}),
cqrs.CommandHandlerFunc(command.HandleClearInbox),

View File

@ -92,6 +92,18 @@ func (s *Session) Data(r io.Reader) error {
}
}
if conf.Data.MaxEmail > 0 {
cmd := &command.RotateEmailRequest{
MaxEmail: conf.Data.MaxEmail,
}
if _, err := bus.Exec(s.ctx, cmd); err != nil {
logger.Error(s.ctx, "could not exec command", logger.E(err))
return errors.Wrapf(err, "could not exec '%T' command", cmd)
}
}
cmd := &command.StoreEmailRequest{
Envelope: env,
}