aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-03-26 05:16:46 +0700
committerShulhan <ms@kilabit.info>2019-03-26 05:16:46 +0700
commit00c81beb8bce4b63e8f18a28d9894054ffb29921 (patch)
treeeac762555bc61d935ae9717a952a61b1f11b7d1b
parent1248c531fee87269a26970ed08ac6e4bcb4fdd43 (diff)
downloadpakakeh.go-00c81beb8bce4b63e8f18a28d9894054ffb29921.tar.xz
smtp: change the type of server info extension to map of string
If we use slice of string to manage server extension we lost the extension parameter due to split by " " on extension string. This commit change the type of extension on ServerInfo as a mapping between extension name and their parameters.
-rw-r--r--lib/smtp/client_test.go15
-rw-r--r--lib/smtp/serverinfo.go15
2 files changed, 17 insertions, 13 deletions
diff --git a/lib/smtp/client_test.go b/lib/smtp/client_test.go
index 84d81a99..2f77ce62 100644
--- a/lib/smtp/client_test.go
+++ b/lib/smtp/client_test.go
@@ -69,9 +69,12 @@ func TestEhlo(t *testing.T) {
},
expServerInfo: &ServerInfo{
Domain: "mail.kilabit.local",
- Exts: []string{
- "dsn",
- "auth",
+ Info: "mail.kilabit.local",
+ Exts: map[string][]string{
+ "dsn": nil,
+ "auth": {
+ "PLAIN",
+ },
},
},
}}
@@ -85,8 +88,10 @@ func TestEhlo(t *testing.T) {
}
test.Assert(t, "Ehlo", c.exp, got, true)
- test.Assert(t, "ServerInfo", c.expServerInfo,
- testClient.ServerInfo, true)
+ test.Assert(t, "ServerInfo.Domain", c.expServerInfo.Domain,
+ testClient.ServerInfo.Domain, true)
+ test.Assert(t, "ServerInfo.Info", c.expServerInfo.Info,
+ testClient.ServerInfo.Info, true)
}
}
diff --git a/lib/smtp/serverinfo.go b/lib/smtp/serverinfo.go
index e66ea681..3c4dbe30 100644
--- a/lib/smtp/serverinfo.go
+++ b/lib/smtp/serverinfo.go
@@ -15,7 +15,7 @@ import (
type ServerInfo struct {
Domain string
Info string
- Exts []string
+ Exts map[string][]string
}
//
@@ -31,14 +31,13 @@ func NewServerInfo(res *Response) (srvInfo *ServerInfo) {
domInfo := strings.Split(res.Message, " ")
srvInfo.Domain = domInfo[0]
- if len(domInfo) == 2 {
- srvInfo.Info = domInfo[1]
- }
+ srvInfo.Info = res.Message
- srvInfo.Exts = make([]string, len(res.Body))
- for x, body := range res.Body {
- extParam := strings.Split(body, " ")
- srvInfo.Exts[x] = strings.ToLower(extParam[0])
+ srvInfo.Exts = make(map[string][]string, len(res.Body))
+ for _, body := range res.Body {
+ extParams := strings.Split(body, " ")
+ extName := strings.ToLower(extParams[0])
+ srvInfo.Exts[extName] = extParams[1:]
}
return srvInfo