Debian Codegraph @

cmd/example_test.go

raw
1 package cmd_test
2
3 import (
4 "log"
5 "os"
6 "strings"
7
8 "github.com/jhillyerd/enmime"
9 "github.com/jhillyerd/enmime/cmd"
10 )
11
12 func Example() {
13 mail := `From: James Hillyerd <[email protected]>
14 To: Greg Reader <[email protected]>, Root Node <[email protected]>
15 Date: Sat, 04 Dec 2016 18:38:25 -0800
16 Subject: Example Message
17 Content-Type: multipart/mixed; boundary="Enmime-Test-100"
18
19 --Enmime-Test-100
20 Content-Type: text/plain
21
22 Text section.
23 --Enmime-Test-100
24 Content-Type: text/html
25
26 <em>HTML</em> section.
27 --Enmime-Test-100
28 Content-Transfer-Encoding: base64
29 Content-Disposition: inline;
30 filename=favicon.png
31 Content-Type: image/png;
32 x-unix-mode=0644;
33 name="favicon.png"
34 Content-Id: <8B8481A2-25CA-4886-9B5A-8EB9115DD064@skynet>
35
36 iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
37 bWFnZVJlYWR5ccllPAAAAlFJREFUeNqUU8tOFEEUPVVdNV3dPe8xYRBnjGhmBgKjKzCIiQvBoIaN
38 bly5Z+PSv3Aj7DSiP2B0rwkLGVdGgxITSCRIJGSMEQWZR3eVt5sEFBgTb/dN1yvnnHtPNTPG4Pqd
39 HgCMXnPRSZrpSuH8vUJu4DE4rYHDGAZDX62BZttHqTiIayM3gGiXQsgYLEvATaqxU+dy1U13YXap
40 XptpNHY8iwn8KyIAzm1KBdtRZWErpI5lEWTXp5Z/vHpZ3/wyKKwYGGOdAYwR0EZwoezTYApBEIOb
41 yELl/aE1/83cp40Pt5mxqCKrE4Ck+mVWKKcI5tA8BLEhRBKJLjez6a7MLq7XZtp+yyOawwCBtkiB
42 VZDKzRk4NN7NQBMYPHiZDFhXY+p9ff7F961vVcnl4R5I2ykJ5XFN7Ab7Gc61VoipNBKF+PDyztu5
43 lfrSLT/wIwCxq0CAGtXHZTzqR2jtwQiXONma6hHpj9sLT7YaPxfTXuZdBGA02Wi7FS48YiTfj+i2
44 NhqtdhP5RC8mh2/Op7y0v6eAcWVLFT8D7kWX5S9mepp+C450MV6aWL1cGnvkxbwHtLW2B9AOkLeU
45 d9KEDuh9fl/7CEj7YH5g+3r/lWfF9In7tPz6T4IIwBJOr1SJyIGQMZQbsh5P9uBq5VJtqHh2mo49
46 pdw5WFoEwKWqWHacaWOjQXWGcifKo6vj5RGS6zykI587XeUIQDqJSmAp+lE4qt19W5P9o8+Lma5D
47 cjsC8JiT607lMVkdqQ0Vyh3lHhmh52tfNy78ajXv0rgYzv8nfwswANuk+7sD/Q0aAAAAAElFTkSu
48 QmCC
49 --Enmime-Test-100
50 Content-Transfer-Encoding: base64
51 Content-Type: text/html; name="test.html"
52 Content-Disposition: attachment; filename=test.html
53
54 PGh0bWw+Cg==
55 --Enmime-Test-100--
56 `
57 // Convert MIME text to Envelope
58 r := strings.NewReader(mail)
59 env, err := enmime.ReadEnvelope(r)
60 if err != nil {
61 log.Fatal(err)
62 return
63 }
64
65 err = cmd.EnvelopeToMarkdown(os.Stdout, env, "Example Message Output")
66 if err != nil {
67 log.Fatal(err)
68 return
69 }
70
71 // Output:
72 // Example Message Output
73 // ======================
74 //
75 // ## Header
76 // Content-Type: multipart/mixed; boundary="Enmime-Test-100"
77 // Date: Sat, 04 Dec 2016 18:38:25 -0800
78 //
79 // ## Envelope
80 // ### From
81 // - James Hillyerd `<[email protected]>`
82 //
83 // ### To
84 // - Greg Reader `<[email protected]>`
85 // - Root Node `<[email protected]>`
86 //
87 // ### Subject
88 // Example Message
89 //
90 // ## Body Text
91 // Text section.
92 //
93 // ## Body HTML
94 // <em>HTML</em> section.
95 //
96 // ## Attachment List
97 // - test.html (text/html)
98 //
99 // ## Inline List
100 // - favicon.png (image/png)
101 // Content-ID: 8B8481A2-25CA-4886-9B5A-8EB9115DD064@skynet
102 //
103 // ## Other Part List
104 //
105 // ## MIME Part Tree
106 // multipart/mixed
107 // |-- text/plain
108 // |-- text/html
109 // |-- image/png, disposition: inline, filename: "favicon.png"
110 // `-- text/html, disposition: attachment, filename: "test.html"
111 //
112 }