-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction_helo.go
102 lines (97 loc) · 2.58 KB
/
transaction_helo.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package msmtpd
import (
"fmt"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
)
func (t *Transaction) handleHELO(cmd command) {
var err error
if len(cmd.fields) < 2 {
t.reply(502, "i think you have missed parameter")
t.Hate(missingParameterPenalty)
return
}
if t.dataHandlersCalledProperly {
t.LogWarn("HELO called after DATA accepted")
t.reply(502, "wrong order of commands")
t.Hate(wrongCommandOrderPenalty)
return
}
if t.HeloName != "" {
// Reset envelope in case of duplicate HELO
t.reset()
}
t.LogDebug("HELO <%s> is received...", cmd.fields[1])
t.HeloName = cmd.fields[1]
t.Protocol = SMTP
t.Span.SetAttributes(attribute.String("helo", t.HeloName))
t.Span.SetAttributes(semconv.NetProtocolName("smtp"))
for k := range t.server.HeloCheckers {
err = t.server.HeloCheckers[k](t)
if err != nil {
t.error(err)
return
}
}
t.LogInfo("HELO <%s> is accepted!", cmd.fields[1])
t.reply(250, "Go on, i'm listening...")
t.Love(commandExecutedProperly)
return
}
func (t *Transaction) extensions() []string {
extensions := []string{
fmt.Sprintf("SIZE %d", t.server.MaxMessageSize),
"8BITMIME",
"PIPELINING",
}
if t.server.EnableXCLIENT {
extensions = append(extensions, "XCLIENT")
}
if t.server.TLSConfig != nil && !t.Encrypted {
extensions = append(extensions, "STARTTLS")
}
if t.server.Authenticator != nil && t.Encrypted {
extensions = append(extensions, "AUTH PLAIN LOGIN")
}
return extensions
}
func (t *Transaction) handleEHLO(cmd command) {
var err error
if len(cmd.fields) < 2 {
t.reply(502, "i think you have missed parameter")
t.Hate(missingParameterPenalty)
return
}
if t.dataHandlersCalledProperly {
t.LogWarn("EHLO called after DATA accepted")
t.reply(502, "wrong order of commands")
t.Hate(wrongCommandOrderPenalty)
return
}
if t.HeloName != "" {
// Reset envelope in case of duplicate HELO
t.reset()
}
t.LogDebug("EHLO <%s> is received...", cmd.fields[1])
t.HeloName = cmd.fields[1]
t.Protocol = ESMTP
t.Span.SetAttributes(attribute.String("ehlo", t.HeloName))
t.Span.SetAttributes(semconv.NetProtocolName("esmtp"))
for k := range t.server.HeloCheckers {
err = t.server.HeloCheckers[k](t)
if err != nil {
t.error(err)
return
}
}
t.LogInfo("EHLO <%s> is accepted!", cmd.fields[1])
fmt.Fprintf(t.writer, "250-%s\r\n", t.server.Hostname)
extensions := t.extensions()
if len(extensions) > 1 {
for _, ext := range extensions[:len(extensions)-1] {
fmt.Fprintf(t.writer, "250-%s\r\n", ext)
}
}
t.reply(250, extensions[len(extensions)-1])
t.Love(commandExecutedProperly)
}