forked from chrj/smtpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvelope.go
69 lines (54 loc) · 1.29 KB
/
envelope.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
package smtpd
import (
"crypto/tls"
"fmt"
"net"
"time"
)
// Envelope holds a message
type Envelope struct {
Sender string
Recipients []string
Data []byte
}
// AddReceivedLine prepends a Received header to the Data
func (env *Envelope) AddReceivedLine(peer Peer, addrFor string) {
tlsDetails := ""
tlsVersions := map[uint16]string{
tls.VersionSSL30: "SSL3.0",
tls.VersionTLS10: "TLS1.0",
tls.VersionTLS11: "TLS1.1",
tls.VersionTLS12: "TLS1.2",
tls.VersionTLS13: "TLS1.3",
}
if peer.TLS != nil {
version := "unknown"
if val, ok := tlsVersions[peer.TLS.Version]; ok {
version = val
}
cipher := tls.CipherSuiteName(peer.TLS.CipherSuite)
tlsDetails = fmt.Sprintf(
"\r\n\t(version=%s cipher=%s);",
version,
cipher,
)
}
peerIP := ""
if addr, ok := peer.Addr.(*net.TCPAddr); ok {
peerIP = addr.IP.String()
}
line := wrap([]byte(fmt.Sprintf(
"Received: from %s ([%s])\r\n by %s with %s;%s\r\n for %s; %s\r\n",
peer.HeloName,
peerIP,
peer.ServerName,
peer.Protocol,
tlsDetails,
addrFor,
time.Now().Format("Mon, 02 Jan 2006 15:04:05 -0700 (MST)"),
)))
env.Data = append(env.Data, line...)
// Move the new Received line up front
copy(env.Data[len(line):], env.Data[0:len(env.Data)-len(line)])
copy(env.Data, line)
}