-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.go
More file actions
42 lines (35 loc) · 879 Bytes
/
backend.go
File metadata and controls
42 lines (35 loc) · 879 Bytes
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
package smtp
import (
"github.com/emersion/go-smtp"
"github.com/google/uuid"
"go.uber.org/zap"
)
// Backend implements go-smtp backend interface
type Backend struct {
plugin *Plugin
log *zap.Logger
}
// NewBackend creates SMTP backend
func NewBackend(plugin *Plugin) *Backend {
return &Backend{
plugin: plugin,
log: plugin.log,
}
}
// NewSession is called when new SMTP connection is established
func (b *Backend) NewSession(c *smtp.Conn) (smtp.Session, error) {
session := &Session{
backend: b,
conn: c,
uuid: uuid.NewString(),
remoteAddr: c.Conn().RemoteAddr().String(),
log: b.log,
}
// Store connection for management
b.plugin.connections.Store(session.uuid, session)
b.log.Debug("new SMTP connection",
zap.String("uuid", session.uuid),
zap.String("remote_addr", session.remoteAddr),
)
return session, nil
}