2 // Copyright 2020 Blue Static <https://www.bluestatic.org>
3 // This program is free software licensed under the GNU General Public License,
4 // version 3.0. The full text of the license can be found in LICENSE.txt.
5 // SPDX-License-Identifier: GPL-3.0-only
20 type ReplyLine struct {
25 func (l ReplyLine) String() string {
26 return fmt.Sprintf("%d %s", l.Code, l.Message)
29 var SendAsSubject = regexp.MustCompile(`(?i)\[sendas:\s*([a-zA-Z0-9\.\-_]+)\]`)
32 ReplyOK = ReplyLine{250, "OK"}
33 ReplyBadSyntax = ReplyLine{501, "syntax error"}
34 ReplyBadSequence = ReplyLine{503, "bad sequence of commands"}
35 ReplyBadMailbox = ReplyLine{550, "mailbox unavailable"}
36 ReplyMailboxUnallowed = ReplyLine{553, "mailbox name not allowed"}
39 func DomainForAddress(addr mail.Address) string {
40 return DomainForAddressString(addr.Address)
43 func DomainForAddressString(address string) string {
44 domainIdx := strings.LastIndex(address, "@")
48 return address[domainIdx+1:]
51 type Envelope struct {
61 func WriteEnvelopeForDelivery(w io.Writer, e Envelope) {
62 fmt.Fprintf(w, "Delivered-To: <%s>\r\n", e.RcptTo[0].Address)
63 fmt.Fprintf(w, "Return-Path: <%s>\r\n", e.MailFrom.Address)
67 type Server interface {
69 TLSConfig() *tls.Config
70 VerifyAddress(mail.Address) ReplyLine
71 // Verify that the authc+passwd identity can send mail as authz.
72 Authenticate(authz, authc, passwd string) bool
73 OnMessageDelivered(Envelope) *ReplyLine
75 // RelayMessage instructs the server to send the Envelope to another
76 // MTA for outbound delivery.
77 RelayMessage(Envelope)
80 type EmptyServerCallbacks struct{}
82 func (*EmptyServerCallbacks) TLSConfig() *tls.Config {
86 func (*EmptyServerCallbacks) VerifyAddress(mail.Address) ReplyLine {
90 func (*EmptyServerCallbacks) Authenticate(authz, authc, passwd string) bool {
94 func (*EmptyServerCallbacks) OnMessageDelivered(Envelope) *ReplyLine {
98 func (*EmptyServerCallbacks) RelayMessage(Envelope) {