refactor: Reorganize SMTP2Shoutrrr code into separate files
This commit is contained in:
parent
9625807106
commit
31f2102031
4 changed files with 232 additions and 222 deletions
50
server.go
Normal file
50
server.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package smtp2shoutrrr
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"git.nakama.town/fmartingr/gotoolkit/model"
|
||||
"github.com/emersion/go-smtp"
|
||||
)
|
||||
|
||||
var _ model.Server = (*smtpServer)(nil)
|
||||
|
||||
type smtpServer struct {
|
||||
backend *smtp.Server
|
||||
config Config
|
||||
}
|
||||
|
||||
func (s *smtpServer) IsEnabled() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *smtpServer) Start(_ context.Context) error {
|
||||
slog.Info("Started SMTP server", slog.String("addr", s.backend.Addr))
|
||||
return s.backend.ListenAndServe()
|
||||
}
|
||||
|
||||
func (s *smtpServer) Stop(ctx context.Context) error {
|
||||
slog.Info("Stopping SMTP server")
|
||||
return s.backend.Shutdown(ctx)
|
||||
}
|
||||
|
||||
func NewSMTPServer(config *Config) model.Server {
|
||||
be := &Backend{
|
||||
config: config,
|
||||
}
|
||||
|
||||
smtpBackend := smtp.NewServer(be)
|
||||
smtpBackend.Addr = fmt.Sprintf(":%d", config.Port)
|
||||
smtpBackend.WriteTimeout = 10 * time.Second
|
||||
smtpBackend.ReadTimeout = 10 * time.Second
|
||||
smtpBackend.MaxMessageBytes = 1024 * 1024
|
||||
smtpBackend.MaxRecipients = 50
|
||||
smtpBackend.AllowInsecureAuth = true
|
||||
|
||||
return &smtpServer{
|
||||
backend: smtpBackend,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue