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
|
package smtp
import (
"dove/config"
"dove/utils/errors"
"dove/utils/logger"
"io"
gosmtp "github.com/emersion/go-smtp"
)
type Session struct {
fromAddress string
toAddresses []string
}
func (self *Session) AuthPlain(username string, password string) error {
if !config.SMTP.AuthRequired {
return nil
}
if username != config.SMTP.Username || password != config.SMTP.Password {
logger.Warnf(LogPrefix, AuthFailed, username)
return errors.Error(InvalidCredentials)
}
return nil
}
func (self *Session) Mail(senderAddress string, _ *gosmtp.MailOptions) error {
logger.Debugf(LogPrefix, MailFrom, senderAddress)
self.fromAddress = senderAddress
return nil
}
func (self *Session) Rcpt(recipientAddress string, _ *gosmtp.RcptOptions) error {
logger.Debugf(LogPrefix, Recipient, recipientAddress)
self.toAddresses = append(self.toAddresses, recipientAddress)
return nil
}
func (self *Session) Data(messageReader io.Reader) error {
rawMessage, readError := io.ReadAll(messageReader)
if readError != nil {
return readError
}
logger.Infof(LogPrefix, MessageReceived, len(rawMessage))
_ = rawMessage
return nil
}
func (self *Session) Reset() {
self.fromAddress = ""
self.toAddresses = nil
}
func (self *Session) Logout() error {
return nil
}
|