forked from emersion/go-smtp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.go
73 lines (60 loc) · 1.99 KB
/
backend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package smtp
import (
"context"
"errors"
"io"
)
var (
ErrAuthRequired = errors.New("Please authenticate first")
ErrAuthUnsupported = errors.New("Authentication not supported")
)
// The DefaultBackend
type DefaultBackend struct {
s SessionFactory
}
// SessionFactory Creates a New session for each Connection
type SessionFactory interface {
New() Session
}
// NewDefaultBackend creates a backend without Authentication
func NewDefaultBackend(s SessionFactory) Backend {
return &DefaultBackend{s: s}
}
// Login returns a session
func (be *DefaultBackend) Login(state *ConnectionState, username, password string) (Session, error) {
return be.s.New(), nil
}
// AnonymousLogin is not implemented in default backend
func (be *DefaultBackend) AnonymousLogin(state *ConnectionState) (Session, error) {
return be.s.New(), nil
}
// A SMTP server backend.
type Backend interface {
// Authenticate a user. Return smtp.ErrAuthUnsupported if you don't want to
// support this.
Login(state *ConnectionState, username, password string) (Session, error)
// Called if the client attempts to send mail without logging in first.
// Return smtp.ErrAuthRequired if you don't want to support this.
AnonymousLogin(state *ConnectionState) (Session, error)
}
type Session interface {
// Discard currently processed message.
Reset()
// Free all resources associated with session.
Logout() error
// Set return path for currently processed message.
Mail(from string) error
// Add recipient for currently processed message.
Rcpt(to string) error
// Set currently processed message contents and send it.
Data(r io.Reader, d DataContext) error
}
type DataContext interface {
// SetStatus is used for LMTP only to set the answer for an Recipient
SetStatus(rcpt string, status *SMTPError)
// SetSMTPResponse can be used to overwrite default SMTP Accept Message after DATA finished (not for LMTP)
SetSMTPResponse(response *SMTPError)
StartDelivery(ctx context.Context, rcpt string)
GetXForward() XForward
GetHelo() string
}