-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction_mailfrom.go
75 lines (72 loc) · 2.01 KB
/
transaction_mailfrom.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
74
75
package msmtpd
import (
"net/mail"
"strings"
"go.opentelemetry.io/otel/attribute"
)
func (t *Transaction) handleMAIL(cmd command) {
if len(cmd.params) != 2 || strings.ToUpper(cmd.params[0]) != "FROM" {
t.Hate(missingParameterPenalty)
t.reply(502, "Invalid syntax.")
return
}
if t.dataHandlersCalledProperly {
t.LogWarn("MAIL FROM called after DATA accepted")
t.Hate(wrongCommandOrderPenalty)
t.reply(502, "wrong order of commands")
return
}
if t.HeloName == "" {
t.Hate(missingParameterPenalty)
t.LogDebug("MAIL FROM called without HELO/EHLO")
t.reply(502, "Please introduce yourself first.")
return
}
if !t.Encrypted && t.server.ForceTLS {
t.LogDebug("MAIL FROM called without STARTTLS")
t.Hate(missingParameterPenalty)
t.reply(502, "Please turn on TLS by issuing a STARTTLS command.")
return
}
if t.server.Authenticator != nil && t.Username == "" {
t.LogDebug("MAIL FROM called without authentication")
t.Hate(missingParameterPenalty)
t.reply(530, "Authentication Required.")
return
}
if t.MailFrom.Address != "" {
t.LogDebug("MAIL FROM was already called")
t.Hate(missingParameterPenalty)
t.reply(502, "Duplicate MAIL")
return
}
var err error
var addr *mail.Address // null sender
// We must accept a null sender as per rfc5321 section-6.1.
if cmd.params[1] != "<>" {
addr, err = parseAddress(cmd.params[1])
if err != nil {
t.reply(502, "Malformed e-mail address")
return
}
t.MailFrom = *addr
} else {
t.MailFrom = mail.Address{}
}
t.LogDebug("Checking MAIL FROM %s by %v SenderCheckers...",
t.MailFrom.String(), len(t.server.SenderCheckers),
)
t.Span.SetAttributes(attribute.String("from", t.MailFrom.String()))
for k := range t.server.SenderCheckers {
err = t.server.SenderCheckers[k](t)
if err != nil {
t.error(err)
return
}
}
t.LogInfo("MAIL FROM %s is checked by %v SenderCheckers and accepted!",
t.MailFrom.String(), len(t.server.SenderCheckers),
)
t.reply(250, "Ok, it makes sense, go ahead please!")
t.Love(commandExecutedProperly)
}