Skip to content

Commit

Permalink
Fix broken encodeXtext()
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedas authored and emersion committed Sep 7, 2023
1 parent c43c4c3 commit 42a0048
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
26 changes: 26 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,3 +931,29 @@ Goodbye.`
t.Fatalf("QUIT failed: %s", err)
}
}

func TestClientXtext(t *testing.T) {
server := "220 hello world\r\n" +
"200 some more"
var wrote bytes.Buffer
var fake faker
fake.ReadWriter = struct {
io.Reader
io.Writer
}{
strings.NewReader(server),
&wrote,
}
c, err := NewClient(fake, "fake.host")
if err != nil {
t.Fatalf("NewClient: %v", err)
}
c.didHello = true
c.ext = map[string]string{"AUTH": "PLAIN"}
email := "[email protected]"
c.Mail(email, &MailOptions{Auth: &email})
c.Close()
if got, want := wrote.String(), "MAIL FROM:<[email protected]> [email protected]\r\n"; got != want {
t.Errorf("wrote %q; want %q", got, want)
}
}
12 changes: 5 additions & 7 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,14 @@ func encodeXtext(raw string) string {
out.Grow(len(raw))

for _, ch := range raw {
if ch == '+' || ch == '=' {
switch {
case ch >= '!' && ch <= '~' && ch != '+' && ch != '=':
// printable non-space US-ASCII except '+' and '='
out.WriteRune(ch)
default:
out.WriteRune('+')
out.WriteString(strings.ToUpper(strconv.FormatInt(int64(ch), 16)))
}
if ch > '!' && ch < '~' { // printable non-space US-ASCII
out.WriteRune(ch)
}
// Non-ASCII.
out.WriteRune('+')
out.WriteString(strings.ToUpper(strconv.FormatInt(int64(ch), 16)))
}
return out.String()
}
Expand Down

0 comments on commit 42a0048

Please sign in to comment.