| 39 | ) |
| 40 | |
| 41 | func doTestDelivery(t *testing.T, tgt module.DeliveryTarget, from string, to []string, hdr string) (string, error) { |
| 42 | t.Helper() |
| 43 | |
| 44 | IDRaw := sha1.Sum([]byte(t.Name())) |
| 45 | encodedID := hex.EncodeToString(IDRaw[:]) |
| 46 | |
| 47 | body := buffer.MemoryBuffer{Slice: []byte("foobar")} |
| 48 | ctx := module.MsgMetadata{ |
| 49 | DontTraceSender: true, |
| 50 | ID: encodedID, |
| 51 | } |
| 52 | |
| 53 | hdrParsed, err := textproto.ReadHeader(bufio.NewReader(strings.NewReader(hdr))) |
| 54 | if err != nil { |
| 55 | panic(err) |
| 56 | } |
| 57 | |
| 58 | delivery, err := tgt.StartDelivery(context.Background(), &ctx, from) |
| 59 | if err != nil { |
| 60 | return encodedID, err |
| 61 | } |
| 62 | for _, rcpt := range to { |
| 63 | if err := delivery.AddRcpt(context.Background(), rcpt, smtp.RcptOptions{}); err != nil { |
| 64 | if err := delivery.Abort(context.Background()); err != nil { |
| 65 | t.Log("delivery.Abort:", err) |
| 66 | } |
| 67 | return encodedID, err |
| 68 | } |
| 69 | } |
| 70 | if err := delivery.Body(context.Background(), hdrParsed, body); err != nil { |
| 71 | if err := delivery.Abort(context.Background()); err != nil { |
| 72 | t.Log("delivery.Abort:", err) |
| 73 | } |
| 74 | return encodedID, err |
| 75 | } |
| 76 | if err := delivery.Commit(context.Background()); err != nil { |
| 77 | return encodedID, err |
| 78 | } |
| 79 | |
| 80 | return encodedID, err |
| 81 | } |
| 82 | |
| 83 | func dmarcResult(t *testing.T, hdr textproto.Header) authres.ResultValue { |
| 84 | field := hdr.Get("Authentication-Results") |