-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client: Implementing DSN extension (RFC 3461, RFC 6533)
- Loading branch information
Showing
3 changed files
with
187 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -932,9 +932,15 @@ Goodbye.` | |
} | ||
} | ||
|
||
var xtextClient = `MAIL FROM:<[email protected]> [email protected] | ||
RCPT TO:<[email protected]> ORCPT=UTF-8;e\x{3D}[email protected] | ||
` | ||
|
||
func TestClientXtext(t *testing.T) { | ||
server := "220 hello world\r\n" + | ||
"200 some more" | ||
"250 ok\r\n" + | ||
"250 ok" | ||
client := strings.Join(strings.Split(xtextClient, "\n"), "\r\n") | ||
var wrote bytes.Buffer | ||
var fake faker | ||
fake.ReadWriter = struct { | ||
|
@@ -949,11 +955,78 @@ func TestClientXtext(t *testing.T) { | |
t.Fatalf("NewClient: %v", err) | ||
} | ||
c.didHello = true | ||
c.ext = map[string]string{"AUTH": "PLAIN"} | ||
c.ext = map[string]string{"AUTH": "PLAIN", "DSN": ""} | ||
email := "[email protected]" | ||
c.Mail(email, &MailOptions{Auth: &email}) | ||
c.Rcpt(email, &RcptOptions{ | ||
OriginalRecipientType: AddressTypeUTF8, | ||
OriginalRecipient: 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) | ||
if got := wrote.String(); got != client { | ||
t.Errorf("wrote %q; want %q", got, client) | ||
} | ||
} | ||
|
||
const ( | ||
dsnEnvelopeID = "e=mc2" | ||
dsnEmailRFC822 = "[email protected]" | ||
dsnEmailUTF8 = "e=mc2@ドメイン名例.jp" | ||
) | ||
|
||
var dsnServer = `220 hello world | ||
250 ok | ||
250 ok | ||
250 ok | ||
250 ok | ||
` | ||
|
||
var dsnClient = `MAIL FROM:<[email protected]> RET=HDRS ENVID=e+3Dmc2 | ||
RCPT TO:<[email protected]> NOTIFY=NEVER ORCPT=RFC822;[email protected] | ||
RCPT TO:<[email protected]> NOTIFY=FAILURE,DELAY ORCPT=UTF-8;e\x{3D}mc2@\x{30C9}\x{30E1}\x{30A4}\x{30F3}\x{540D}\x{4F8B}.jp | ||
RCPT TO:<e=mc2@ドメイン名例.jp> ORCPT=UTF-8;e\x{3D}mc2@ドメイン名例.jp | ||
` | ||
|
||
func TestClientDSN(t *testing.T) { | ||
server := strings.Join(strings.Split(dsnServer, "\n"), "\r\n") | ||
client := strings.Join(strings.Split(dsnClient, "\n"), "\r\n") | ||
|
||
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{"DSN": ""} | ||
c.Mail(dsnEmailRFC822, &MailOptions{ | ||
Return: ReturnHeaders, | ||
EnvelopeID: dsnEnvelopeID, | ||
}) | ||
c.Rcpt(dsnEmailRFC822, &RcptOptions{ | ||
OriginalRecipientType: AddressTypeRFC822, | ||
OriginalRecipient: dsnEmailRFC822, | ||
Notify: []DSNNotify{NotifyNever}, | ||
}) | ||
c.Rcpt(dsnEmailRFC822, &RcptOptions{ | ||
OriginalRecipientType: AddressTypeUTF8, | ||
OriginalRecipient: dsnEmailUTF8, | ||
Notify: []DSNNotify{NotifyFailure, NotifyDelayed}, | ||
}) | ||
c.ext["SMTPUTF8"] = "" | ||
c.Rcpt(dsnEmailUTF8, &RcptOptions{ | ||
OriginalRecipientType: AddressTypeUTF8, | ||
OriginalRecipient: dsnEmailUTF8, | ||
}) | ||
c.Close() | ||
if actualcmds := wrote.String(); client != actualcmds { | ||
t.Errorf("wrote %q; want %q", actualcmds, client) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters