-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dmytro Kasianenko
committed
Nov 16, 2022
1 parent
695d9d9
commit 5c8d874
Showing
1 changed file
with
39 additions
and
0 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
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] | ||
} |