Skip to content

Commit

Permalink
feat(dsn): add example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Kasianenko committed Nov 16, 2022
1 parent 695d9d9 commit 5c8d874
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions dsn/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dsn_test

import (
"fmt"
"os"

"github.com/jhillyerd/enmime"
"github.com/jhillyerd/enmime/dsn"
)

// ExampleParseReport shows how to parse message as Delivery Status Notification (DSN).
func ExampleParseReport() {
f, err := os.Open("testdata/simple_dsn.raw")
if err != nil {
fmt.Println(err)
return
}
defer f.Close()

env, err := enmime.ReadEnvelope(f)
if err != nil {
fmt.Print(err)
return
}

rep, err := dsn.ParseReport(env.Root)
if err != nil {
fmt.Print(err)
return
}

fmt.Printf("Original message: %s", rep.OriginalMessage)
fmt.Printf("Failed?: %t\n", dsn.IsFailed(rep.DeliveryStatus.RecipientDSNs[0]))
fmt.Printf("Why?: %s", rep.Explanation.Text)
// Output:
// Original message: [original message goes here]
// Failed?: true
// Why?: [human-readable explanation goes here]
}

0 comments on commit 5c8d874

Please sign in to comment.