Skip to content

Commit 42a0048

Browse files
ikedasemersion
authored andcommitted
Fix broken encodeXtext()
1 parent c43c4c3 commit 42a0048

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

client_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -931,3 +931,29 @@ Goodbye.`
931931
t.Fatalf("QUIT failed: %s", err)
932932
}
933933
}
934+
935+
func TestClientXtext(t *testing.T) {
936+
server := "220 hello world\r\n" +
937+
"200 some more"
938+
var wrote bytes.Buffer
939+
var fake faker
940+
fake.ReadWriter = struct {
941+
io.Reader
942+
io.Writer
943+
}{
944+
strings.NewReader(server),
945+
&wrote,
946+
}
947+
c, err := NewClient(fake, "fake.host")
948+
if err != nil {
949+
t.Fatalf("NewClient: %v", err)
950+
}
951+
c.didHello = true
952+
c.ext = map[string]string{"AUTH": "PLAIN"}
953+
email := "[email protected]"
954+
c.Mail(email, &MailOptions{Auth: &email})
955+
c.Close()
956+
if got, want := wrote.String(), "MAIL FROM:<[email protected]> [email protected]\r\n"; got != want {
957+
t.Errorf("wrote %q; want %q", got, want)
958+
}
959+
}

conn.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -426,16 +426,14 @@ func encodeXtext(raw string) string {
426426
out.Grow(len(raw))
427427

428428
for _, ch := range raw {
429-
if ch == '+' || ch == '=' {
429+
switch {
430+
case ch >= '!' && ch <= '~' && ch != '+' && ch != '=':
431+
// printable non-space US-ASCII except '+' and '='
432+
out.WriteRune(ch)
433+
default:
430434
out.WriteRune('+')
431435
out.WriteString(strings.ToUpper(strconv.FormatInt(int64(ch), 16)))
432436
}
433-
if ch > '!' && ch < '~' { // printable non-space US-ASCII
434-
out.WriteRune(ch)
435-
}
436-
// Non-ASCII.
437-
out.WriteRune('+')
438-
out.WriteString(strings.ToUpper(strconv.FormatInt(int64(ch), 16)))
439437
}
440438
return out.String()
441439
}

0 commit comments

Comments
 (0)