This commit is contained in:
Aine
2022-08-21 18:41:35 +03:00
commit c4b7a16e21
22 changed files with 1745 additions and 0 deletions

50
smtp/server.go Normal file
View File

@@ -0,0 +1,50 @@
package smtp
import (
"log"
"os"
"time"
"github.com/emersion/go-smtp"
"maunium.net/go/mautrix/id"
)
type backend struct {
domain string
rooms map[string]id.RoomID
}
func (b *backend) newSession() *session {
return &session{
domain: b.domain,
rooms: b.rooms,
}
}
func (b *backend) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error) {
return nil, smtp.ErrAuthUnsupported
}
func (b *backend) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error) {
return b.newSession(), nil
}
func NewServer(domain string, mapping map[string]id.RoomID, port string) *smtp.Server {
be := &backend{
domain: domain,
rooms: mapping,
}
s := smtp.NewServer(be)
s.Addr = ":" + port
s.Domain = domain
s.AuthDisabled = true
s.ReadTimeout = 360 * time.Second
s.WriteTimeout = 360 * time.Second
s.MaxMessageBytes = 63 * 1024
s.MaxRecipients = 50
s.Debug = os.Stdout
log.Println("Starting SMTP server")
log.Fatal(s.ListenAndServe())
return s
}