-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction_xclient.go
92 lines (89 loc) · 1.75 KB
/
transaction_xclient.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
package msmtpd
import (
"net"
"strconv"
"strings"
"go.opentelemetry.io/otel/attribute"
)
func (t *Transaction) handleXCLIENT(cmd command) {
if len(cmd.fields) < 2 {
t.reply(502, "Invalid syntax.")
return
}
if !t.server.EnableXCLIENT {
t.reply(550, "XCLIENT not enabled")
return
}
var (
newHeloName, newUsername string
newProto Protocol
newAddr net.IP
newTCPPort uint64
)
t.Span.SetAttributes(attribute.String("XCLIENT", cmd.line))
for _, item := range cmd.fields[1:] {
parts := strings.Split(item, "=")
if len(parts) != 2 {
t.reply(502, "Couldn't decode the command.")
return
}
name := parts[0]
value := parts[1]
switch name {
case "NAME":
// Unused in smtpd package
continue
case "HELO":
newHeloName = value
continue
case "ADDR":
newAddr = net.ParseIP(value)
continue
case "PORT":
var err error
newTCPPort, err = strconv.ParseUint(value, 10, 16)
if err != nil {
t.reply(502, "Couldn't decode the command.")
return
}
continue
case "LOGIN":
newUsername = value
continue
case "PROTO":
if value == string(SMTP) {
newProto = SMTP
} else if value == string(ESMTP) {
newProto = ESMTP
}
continue
default:
t.reply(502, "Couldn't decode the command.")
return
}
}
tcpAddr, ok := t.Addr.(*net.TCPAddr)
if !ok {
t.reply(502, "Unsupported network connection")
return
}
if newHeloName != "" {
t.HeloName = newHeloName
}
if newAddr != nil {
tcpAddr.IP = newAddr
}
if newTCPPort != 0 {
tcpAddr.Port = int(newTCPPort)
}
if newUsername != "" {
t.Username = newUsername
}
if newProto != "" {
t.Protocol = newProto
}
if newAddr != nil && newTCPPort != 0 {
t.Addr = tcpAddr
}
t.welcome()
}