File tree Expand file tree Collapse file tree 2 files changed +31
-7
lines changed Expand file tree Collapse file tree 2 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -931,3 +931,29 @@ Goodbye.`
931
931
t .Fatalf ("QUIT failed: %s" , err )
932
932
}
933
933
}
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 := "e=mc2@example.com"
954
+ c .Mail (email , & MailOptions {Auth : & email })
955
+ c .Close ()
956
+ if got , want := wrote .String (), "MAIL FROM:<e=mc2@example.com> AUTH=e+3Dmc2@example.com\r \n " ; got != want {
957
+ t .Errorf ("wrote %q; want %q" , got , want )
958
+ }
959
+ }
Original file line number Diff line number Diff line change @@ -426,16 +426,14 @@ func encodeXtext(raw string) string {
426
426
out .Grow (len (raw ))
427
427
428
428
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 :
430
434
out .WriteRune ('+' )
431
435
out .WriteString (strings .ToUpper (strconv .FormatInt (int64 (ch ), 16 )))
432
436
}
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 )))
439
437
}
440
438
return out .String ()
441
439
}
You can’t perform that action at this time.
0 commit comments