-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn_test.go
38 lines (31 loc) · 950 Bytes
/
conn_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"bytes"
"io"
"testing"
"github.com/DusanKasan/parsemail"
"github.com/stretchr/testify/assert"
)
func TestParse(t *testing.T) {
data := []byte(`Subject: Our family reunion
From: you@restsend.com
To: oss@restsend.com
Content-Type: multipart/mixed; boundary="===============8642179929463994206=="
You will not see this in a MIME-aware mail reader.
--===============8642179929463994206==
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="logo.png"
MIME-Version: 1.0
aW1nX2RhdGE=
--===============8642179929463994206==--`)
r := bytes.NewReader(data)
msg, err := parsemail.Parse(r)
assert.Nil(t, err)
assert.Equal(t, "Our family reunion", msg.Subject)
assert.Equal(t, 1, len(msg.Attachments))
assert.Equal(t, "logo.png", msg.Attachments[0].Filename)
data, err = io.ReadAll(msg.Attachments[0].Data)
assert.Nil(t, err)
assert.Equal(t, []byte("img_data"), data)
}