zangtumb/handler.go

52 lines
1.0 KiB
Go
Raw Normal View History

2020-10-08 22:36:17 +02:00
package main
import (
"bytes"
"log"
"net"
2021-07-30 23:20:49 +02:00
"time"
2020-10-08 22:36:17 +02:00
)
2021-07-30 23:20:49 +02:00
2020-10-08 22:36:17 +02:00
func mailHandler(origin net.Addr, from string, to []string, data []byte) {
SmtpSession := new(Session)
log.Printf("Received mail from %s for %q from %s", from, to, origin.String())
log.Println(" Recipients: ", to)
for _, rcptTo := range to {
SmtpSession.Reset()
if rcptErr := SmtpSession.Rcpt(rcptTo); rcptErr == nil {
SmtpSession.MailFrom = from
if dataErr := SmtpSession.Data(bytes.NewReader(data)); dataErr != nil {
log.Println("Problem Saving Message: ", dataErr.Error())
}
2020-10-08 22:36:17 +02:00
} else {
log.Println(rcptErr)
}
}
}
2021-07-30 23:20:49 +02:00
func handlerRcpt(remoteAddr net.Addr, from string, to string) bool {
log.Println("CHECK #2 Rcpt to:", to)
if !SmtpBackend.CheckValidRcpt(to) {
log.Printf("%s [ %s -> %s ] %s BAD!!!!", "YU NO MAIL!!! WE NU RELAY!!! ", from, to, remoteAddr.String() )
2021-07-30 23:20:49 +02:00
time.Sleep(10 * time.Second)
return false
}else{
log.Printf("%s [ %s -> %s ] %s GOOD!!!!", "WE DO!!!", from, to, remoteAddr.String() )
2021-07-30 23:20:49 +02:00
}
return true
}