14 type ReplyLine struct {
19 func (l ReplyLine) String() string {
20 return fmt.Sprintf("%d %s", l.Code, l.Message)
23 var SendAsSubject = regexp.MustCompile(`(?i)\[sendas:\s*([a-zA-Z0-9\.\-_]+)\]`)
26 ReplyOK = ReplyLine{250, "OK"}
27 ReplyBadSyntax = ReplyLine{501, "syntax error"}
28 ReplyBadSequence = ReplyLine{503, "bad sequence of commands"}
29 ReplyBadMailbox = ReplyLine{550, "mailbox unavailable"}
30 ReplyMailboxUnallowed = ReplyLine{553, "mailbox name not allowed"}
33 func DomainForAddress(addr mail.Address) string {
34 return DomainForAddressString(addr.Address)
37 func DomainForAddressString(address string) string {
38 domainIdx := strings.LastIndex(address, "@")
42 return address[domainIdx+1:]
45 type Envelope struct {
55 func WriteEnvelopeForDelivery(w io.Writer, e Envelope) {
56 fmt.Fprintf(w, "Delivered-To: <%s>\r\n", e.RcptTo[0].Address)
57 fmt.Fprintf(w, "Return-Path: <%s>\r\n", e.MailFrom.Address)
61 type Server interface {
63 TLSConfig() *tls.Config
64 VerifyAddress(mail.Address) ReplyLine
65 // Verify that the authc+passwd identity can send mail as authz.
66 Authenticate(authz, authc, passwd string) bool
67 OnMessageDelivered(Envelope) *ReplyLine
69 // RelayMessage instructs the server to send the Envelope to another
70 // MTA for outbound delivery.
71 RelayMessage(Envelope)
74 type EmptyServerCallbacks struct{}
76 func (*EmptyServerCallbacks) TLSConfig() *tls.Config {
80 func (*EmptyServerCallbacks) VerifyAddress(mail.Address) ReplyLine {
84 func (*EmptyServerCallbacks) Authenticate(authz, authc, passwd string) bool {
88 func (*EmptyServerCallbacks) OnMessageDelivered(Envelope) *ReplyLine {
92 func (*EmptyServerCallbacks) RelayMessage(Envelope) {