test(router): pin the edges of DSN parsing
- message/global-delivery-status (RFC 6533) counts like delivery-status. - Only the first delivery-status part is read. - A malformed delivery-status part does not count. - Drop the redundant empty-boundary check: the multipart reader already fails on it.
This commit is contained in:
parent
8317e44338
commit
cd31d919a9
2 changed files with 32 additions and 1 deletions
|
|
@ -119,3 +119,34 @@ func TestAnyFailedRecipientBlockCounts(t *testing.T) {
|
|||
t.Fatalf("counted %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGlobalDeliveryStatusCounts(t *testing.T) {
|
||||
// RFC 6533: the internationalized report has the same fields.
|
||||
msg := strings.Replace(string(dsn("failed", "5.1.1")), "message/delivery-status", "message/global-delivery-status", 1)
|
||||
e := newEnv(t)
|
||||
e.command("", e.r.bounceAddress(e.list, e.alice), []byte(msg))
|
||||
if n := bounceCount(t, e); n != 1 {
|
||||
t.Fatalf("counted %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOnlyTheFirstDeliveryStatusPartIsRead(t *testing.T) {
|
||||
// A report has one delivery-status part; another one after it is not the MTA speaking.
|
||||
extra := "--BOUNDARY\r\nContent-Type: message/delivery-status\r\n\r\nReporting-MTA: dns; x\r\n\r\n" +
|
||||
"Final-Recipient: rfc822; alice@example.com\r\nAction: failed\r\nStatus: 5.1.1\r\n\r\n--BOUNDARY--"
|
||||
msg := strings.Replace(string(dsn("delayed", "4.4.1")), "--BOUNDARY--", extra, 1)
|
||||
e := newEnv(t)
|
||||
e.command("", e.r.bounceAddress(e.list, e.alice), []byte(msg))
|
||||
if n := bounceCount(t, e); n != 0 {
|
||||
t.Fatalf("counted %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAMalformedDeliveryStatusDoesNotCount(t *testing.T) {
|
||||
msg := strings.Replace(string(dsn("failed", "5.1.1")), "Arrival-Date:", "this line is not a field\r\nArrival-Date:", 1)
|
||||
e := newEnv(t)
|
||||
e.command("", e.r.bounceAddress(e.list, e.alice), []byte(msg))
|
||||
if n := bounceCount(t, e); n != 0 {
|
||||
t.Fatalf("counted %d", n)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func isHardBounce(data []byte) bool {
|
|||
return false
|
||||
}
|
||||
mt, params, err := mime.ParseMediaType(msg.Header.Get("Content-Type"))
|
||||
if err != nil || mt != "multipart/report" || params["boundary"] == "" {
|
||||
if err != nil || mt != "multipart/report" {
|
||||
return false
|
||||
}
|
||||
mr := multipart.NewReader(msg.Body, params["boundary"])
|
||||
|
|
|
|||
Loading…
Reference in a new issue