]>
src.bluestatic.org Git - mailpopbox.git/blob - smtp.go
12 "src.bluestatic.org/mailpopbox/smtp"
15 func runSMTPServer(config Config
) <-chan error
{
24 type smtpServer
struct {
29 func (server
*smtpServer
) run() {
30 l
, err
:= net
.Listen("tcp", fmt
.Sprintf(":%d", server
.config
.SMTPPort
))
37 conn
, err
:= l
.Accept()
43 go smtp
.AcceptConnection(conn
, server
)
47 func (server
*smtpServer
) Name() string {
48 return server
.config
.Hostname
51 func (server
*smtpServer
) TLSConfig() *tls
.Config
{
55 func (server
*smtpServer
) VerifyAddress(addr mail
.Address
) smtp
.ReplyLine
{
56 if server
.maildropForAddress(addr
) == "" {
57 return smtp
.ReplyBadMailbox
62 func (server
*smtpServer
) OnEHLO() *smtp
.ReplyLine
{
66 func (server
*smtpServer
) OnMessageDelivered(en smtp
.Envelope
) *smtp
.ReplyLine
{
67 maildrop
:= server
.maildropForAddress(en
.RcptTo
[0])
70 return &smtp
.ReplyBadMailbox
73 f
, err
:= os
.Create(path
.Join(maildrop
, en
.ID
+".msg"))
76 return &smtp
.ReplyBadMailbox
79 smtp
.WriteEnvelopeForDelivery(f
, en
)
84 func (server
*smtpServer
) maildropForAddress(addr mail
.Address
) string {
85 domainIdx
:= strings
.LastIndex(addr
.Address
, "@")
90 domain
:= addr
.Address
[domainIdx
+1:]
92 for _
, s
:= range server
.config
.Servers
{
93 if domain
== s
.Domain
{