add automatic greylisting

This commit is contained in:
Aine
2022-11-16 18:47:24 +02:00
parent 15b90e9e4c
commit 8ebe80bc4f
10 changed files with 207 additions and 78 deletions

View File

@@ -40,6 +40,7 @@ type Manager struct {
type matrixbot interface {
AllowAuth(string, string) bool
IsGreylisted(net.Addr) bool
IsBanned(net.Addr) bool
Ban(net.Addr)
GetMapping(string) (id.RoomID, bool)

View File

@@ -59,6 +59,8 @@ func (m *mailServer) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session,
getRoomID: m.bot.GetMapping,
getFilters: m.bot.GetIFOptions,
receiveEmail: m.ReceiveEmail,
ban: m.bot.Ban,
greylisted: m.bot.IsGreylisted,
log: m.log,
domains: m.domains,
addr: state.RemoteAddr,

View File

@@ -22,6 +22,7 @@ type incomingSession struct {
getRoomID func(string) (id.RoomID, bool)
getFilters func(id.RoomID) utils.IncomingFilteringOptions
receiveEmail func(context.Context, *utils.Email) error
greylisted func(net.Addr) bool
ban func(net.Addr)
domains []string
@@ -76,6 +77,13 @@ func (s *incomingSession) Rcpt(to string) error {
}
func (s *incomingSession) Data(r io.Reader) error {
if s.greylisted(s.addr) {
return &smtp.SMTPError{
Code: 451,
EnhancedCode: smtp.EnhancedCode{4, 5, 1},
Message: "You have been greylisted, try again a bit later.",
}
}
parser := enmime.NewParser()
eml, err := parser.ReadEnvelope(r)
if err != nil {