forked from alash3al/go-smtpsrv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.go
More file actions
59 lines (47 loc) · 1 KB
/
Copy pathsession.go
File metadata and controls
59 lines (47 loc) · 1 KB
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
package smtpsrv
import (
"errors"
"io"
"net/mail"
"github.com/emersion/go-smtp"
)
// A Session is returned after successful login.
type Session struct {
connState *smtp.ConnectionState
From *mail.Address
To *mail.Address
handler HandlerFunc
body io.Reader
username *string
password *string
}
// NewSession initialize a new session
func NewSession(state *smtp.ConnectionState, handler HandlerFunc, username, password *string) *Session {
return &Session{
connState: state,
handler: handler,
}
}
func (s *Session) Mail(from string, opts smtp.MailOptions) (err error) {
s.From, err = mail.ParseAddress(from)
return
}
func (s *Session) Rcpt(to string) (err error) {
s.To, err = mail.ParseAddress(to)
return
}
func (s *Session) Data(r io.Reader) error {
if s.handler == nil {
return errors.New("internal error: no handler")
}
s.body = r
c := Context{
session: s,
}
return s.handler(&c)
}
func (s *Session) Reset() {
}
func (s *Session) Logout() error {
return nil
}