Start saving SMTP messages in the maildrop.
[mailpopbox.git] / smtp / server.go
1 package smtp
2
3 import (
4 "crypto/tls"
5 "fmt"
6 "io"
7 "net"
8 "net/mail"
9 "time"
10 )
11
12 type ReplyLine struct {
13 Code int
14 Message string
15 }
16
17 var (
18 ReplyOK = ReplyLine{250, "OK"}
19 ReplyBadSyntax = ReplyLine{501, "syntax error"}
20 ReplyBadSequence = ReplyLine{503, "bad sequence of commands"}
21 ReplyBadMailbox = ReplyLine{550, "mailbox unavailable"}
22 )
23
24 type Envelope struct {
25 RemoteAddr net.Addr
26 EHLO string
27 MailFrom mail.Address
28 RcptTo []mail.Address
29 Data []byte
30 Received time.Time
31 ID string
32 }
33
34 func WriteEnvelopeForDelivery(w io.Writer, e Envelope) {
35 fmt.Fprintf(w, "Delivered-To: <%s>\r\n", e.RcptTo[0].Address)
36 fmt.Fprintf(w, "Return-Path: <%s>\r\n", e.MailFrom.Address)
37 w.Write(e.Data)
38 }
39
40 type Server interface {
41 Name() string
42 TLSConfig() *tls.Config
43 OnEHLO() *ReplyLine
44 VerifyAddress(mail.Address) ReplyLine
45 OnMessageDelivered(Envelope) *ReplyLine
46 }
47
48 type EmptyServerCallbacks struct{}
49
50 func (*EmptyServerCallbacks) TLSConfig() *tls.Config {
51 return nil
52 }
53
54 func (*EmptyServerCallbacks) OnEHLO() *ReplyLine {
55 return nil
56 }
57
58 func (*EmptyServerCallbacks) VerifyAddress(mail.Address) ReplyLine {
59 return ReplyOK
60 }
61
62 func (*EmptyServerCallbacks) OnMessageDelivered(Envelope) *ReplyLine {
63 return nil
64 }