When receiving a message, the SMTP server must add its trace information.
[mailpopbox.git] / smtp / server.go
1 package smtp
2
3 import (
4 "crypto/tls"
5 "net"
6 "net/mail"
7 "time"
8 )
9
10 type ReplyLine struct {
11 Code int
12 Message string
13 }
14
15 var (
16 ReplyOK = ReplyLine{250, "OK"}
17 ReplyBadSyntax = ReplyLine{501, "syntax error"}
18 ReplyBadSequence = ReplyLine{503, "bad sequence of commands"}
19 ReplyBadMailbox = ReplyLine{550, "mailbox unavailable"}
20 )
21
22 type Envelope struct {
23 RemoteAddr net.Addr
24 EHLO string
25 MailFrom mail.Address
26 RcptTo []mail.Address
27 Data []byte
28 Received time.Time
29 ID string
30 }
31
32 type Server interface {
33 Name() string
34 TLSConfig() *tls.Config
35 OnEHLO() *ReplyLine
36 VerifyAddress(mail.Address) ReplyLine
37 OnMessageDelivered(Envelope) *ReplyLine
38 }
39
40 type EmptyServerCallbacks struct{}
41
42 func (*EmptyServerCallbacks) TLSConfig() *tls.Config {
43 return nil
44 }
45
46 func (*EmptyServerCallbacks) OnEHLO() *ReplyLine {
47 return nil
48 }
49
50 func (*EmptyServerCallbacks) VerifyAddress(mail.Address) ReplyLine {
51 return ReplyOK
52 }
53
54 func (*EmptyServerCallbacks) OnMessageDelivered(Envelope) *ReplyLine {
55 return nil
56 }