test: add message.Parse tests

This commit is contained in:
James Houlahan
2020-05-12 08:05:36 +02:00
parent 579e962980
commit e5d63edb62
35 changed files with 808 additions and 13 deletions

View File

@ -19,15 +19,14 @@ package message
import (
"bytes"
"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"math/rand"
"mime"
"mime/quotedprintable"
"net/mail"
"net/textproto"
"regexp"
@ -186,7 +185,7 @@ func checkHeaders(headers []textproto.MIMEHeader) bool {
// ============================== 7bit Filter ==========================
// For every MIME part in the tree that has "8bit" or "binary" content
// transfer encoding: transcode it to "quoted-printable".
// transfer encoding: transcode it to "base64".
type SevenBitFilter struct {
target pmmime.VisitAcceptor
@ -216,18 +215,16 @@ func (sd SevenBitFilter) Accept(partReader io.Reader, header textproto.MIMEHeade
for k, v := range header {
filteredHeader[k] = v
}
filteredHeader.Set("Content-Transfer-Encoding", "quoted-printable")
//filteredHeader.Set("Content-Transfer-Encoding", "base64")
filteredHeader.Set("Content-Transfer-Encoding", "base64")
filteredBuffer := &bytes.Buffer{}
decodedSlice, _ := ioutil.ReadAll(decodedPart)
w := quotedprintable.NewWriter(filteredBuffer)
//w := base64.NewEncoder(base64.StdEncoding, filteredBuffer)
w := base64.NewEncoder(base64.StdEncoding, filteredBuffer)
if _, err := w.Write(decodedSlice); err != nil {
log.Errorf("cannot write quotedprintable from %q: %v", cte, err)
log.Errorf("cannot write base64 from %q: %v", cte, err)
}
if err := w.Close(); err != nil {
log.Errorf("cannot close quotedprintable from %q: %v", cte, err)
log.Errorf("cannot close base64 from %q: %v", cte, err)
}
_ = sd.target.Accept(filteredBuffer, filteredHeader, hasPlainSibling, true, isLast)
@ -252,13 +249,15 @@ func NewHTMLOnlyConvertor(targetAccepter pmmime.VisitAcceptor) *HTMLOnlyConverto
}
func randomBoundary() string {
var buf [30]byte
_, err := io.ReadFull(rand.Reader, buf[:])
if err != nil {
buf := make([]byte, 30)
// We specifically use `math/rand` here to allow the generator to be seeded for test purposes.
// The random numbers need not be cryptographically secure; we are simply generating random part boundaries.
if _, err := rand.Read(buf); err != nil { // nolint[gosec]
panic(err)
}
return fmt.Sprintf("%x", buf[:])
return fmt.Sprintf("%x", buf)
}
func (hoc HTMLOnlyConvertor) Accept(partReader io.Reader, header textproto.MIMEHeader, hasPlainSiblings bool, isFirst, isLast bool) error {
@ -364,6 +363,8 @@ func (pka *PublicKeyAttacher) Accept(partReader io.Reader, header textproto.MIME
}()
}
isRoot := (header.Get("From") != "")
// NOTE: This should also work for unspecified Content-Type (in which case us-ascii text/plain is assumed)!
mediaType, _, err := pmmime.ParseMediaType(header.Get("Content-Type"))
if isRoot && isFirst && err == nil && pka.attachedPublicKey != "" { //nolint[gocritic]
if strings.HasPrefix(mediaType, "multipart/mixed") {
@ -447,6 +448,7 @@ func Parse(r io.Reader, attachedPublicKey, attachedPublicKeyName string) (m *pma
}
mimeBody = printAccepter.String()
plainContents = plainTextCollector.GetPlainText()
parts, headers, err := pmmime.GetAllChildParts(bytes.NewReader(mmBodyData), h)

View File

@ -18,8 +18,17 @@
package message
import (
"image/png"
"io"
"io/ioutil"
"math/rand"
"net/mail"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"golang.org/x/text/encoding/charmap"
)
func TestRFC822AddressFormat(t *testing.T) { //nolint[funlen]
@ -105,3 +114,310 @@ func TestRFC822AddressFormat(t *testing.T) { //nolint[funlen]
}
}
}
func f(filename string) io.Reader {
f, err := os.Open(filepath.Join("testdata", filename))
if err != nil {
panic(err)
}
return f
}
func s(filename string) string {
b, err := ioutil.ReadAll(f(filename))
if err != nil {
panic(err)
}
return string(b)
}
func readerToString(r io.Reader) string {
b, err := ioutil.ReadAll(r)
if err != nil {
panic(err)
}
return string(b)
}
func TestParseMessageTextPlain(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("text_plain.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body", m.Body)
assert.Equal(t, s("text_plain.b64"), mimeBody)
assert.Equal(t, "body", plainContents)
assert.Len(t, atts, 0)
}
func TestParseMessageTextPlainUTF8(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_utf8.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body", m.Body)
assert.Equal(t, s("text_plain_utf8.b64"), mimeBody)
assert.Equal(t, "body", plainContents)
assert.Len(t, atts, 0)
}
func TestParseMessageTextPlainLatin1(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_latin1.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "ééééééé", m.Body)
assert.Equal(t, s("text_plain_latin1.b64"), mimeBody)
assert.Equal(t, "ééééééé", plainContents)
assert.Len(t, atts, 0)
}
func TestParseMessageTextPlainUnknownCharsetIsActuallyLatin1(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_unknown_latin1.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "ééééééé", m.Body)
assert.Equal(t, s("text_plain_unknown_latin1.b64"), mimeBody)
assert.Equal(t, "ééééééé", plainContents)
assert.Len(t, atts, 0)
}
func TestParseMessageTextPlainUnknownCharsetIsActuallyLatin2(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_unknown_latin2.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
// The file contains latin2-encoded text, but we will assume it is latin1
// and decode it as such. This will lead to corruption.
latin2, _ := charmap.ISO8859_2.NewEncoder().Bytes([]byte("řšřšřš"))
expect, _ := charmap.ISO8859_1.NewDecoder().Bytes(latin2)
assert.NotEqual(t, []byte("řšřšřš"), expect)
assert.Equal(t, string(expect), m.Body)
assert.Equal(t, s("text_plain_unknown_latin2.b64"), mimeBody)
assert.Equal(t, string(expect), plainContents)
assert.Len(t, atts, 0)
}
func TestParseMessageTextPlainAlready7Bit(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_7bit.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body", m.Body)
assert.Equal(t, s("text_plain_7bit.mime"), mimeBody)
assert.Equal(t, "body", plainContents)
assert.Len(t, atts, 0)
}
func TestParseMessageTextPlainWithOctetAttachment(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_octet_attachment.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body", m.Body)
assert.Equal(t, s("text_plain_octet_attachment.b64"), mimeBody)
assert.Equal(t, "body", plainContents)
assert.Len(t, atts, 1)
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
}
func TestParseMessageTextPlainWithPlainAttachment(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_plain_attachment.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body", m.Body)
assert.Equal(t, s("text_plain_plain_attachment.b64"), mimeBody)
assert.Equal(t, "body", plainContents)
assert.Len(t, atts, 1)
assert.Equal(t, readerToString(atts[0]), "attachment")
}
func TestParseMessageTextPlainWithImageInline(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_image_inline.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body", m.Body)
assert.Equal(t, s("text_plain_image_inline.b64"), mimeBody)
assert.Equal(t, "body", plainContents)
// The inline image is an 8x8 mic-dropping gopher.
assert.Len(t, atts, 1)
img, err := png.DecodeConfig(atts[0])
assert.NoError(t, err)
assert.Equal(t, 8, img.Width)
assert.Equal(t, 8, img.Height)
}
func TestParseMessageWithMultipleTextParts(t *testing.T) {
m, mimeBody, plainContents, atts, err := Parse(f("multiple_text_parts.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body\nsome other part of the message", m.Body)
assert.Equal(t, s("multiple_text_parts.b64"), mimeBody)
assert.Equal(t, "body\nsome other part of the message", plainContents)
assert.Len(t, atts, 0)
}
func TestParseMessageTextHTML(t *testing.T) {
rand.Seed(0)
m, mimeBody, plainContents, atts, err := Parse(f("text_html.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "<html><head></head><body>This is body of <b>HTML mail</b> without attachment</body></html>", m.Body)
assert.Equal(t, s("text_html.b64"), mimeBody)
assert.Equal(t, "This is body of *HTML mail* without attachment", plainContents)
assert.Len(t, atts, 0)
}
func TestParseMessageTextHTMLAlready7Bit(t *testing.T) {
rand.Seed(0)
m, mimeBody, plainContents, atts, err := Parse(f("text_html_7bit.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "<html><head></head><body>This is body of <b>HTML mail</b> without attachment</body></html>", m.Body)
assert.Equal(t, s("text_html_7bit.mime"), mimeBody)
assert.Equal(t, "This is body of *HTML mail* without attachment", plainContents)
assert.Len(t, atts, 0)
}
func TestParseMessageTextHTMLWithOctetAttachment(t *testing.T) {
rand.Seed(0)
m, mimeBody, plainContents, atts, err := Parse(f("text_html_octet_attachment.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "<html><head></head><body>This is body of <b>HTML mail</b> with attachment</body></html>", m.Body)
assert.Equal(t, s("text_html_octet_attachment.b64"), mimeBody)
assert.Equal(t, "This is body of *HTML mail* with attachment", plainContents)
assert.Len(t, atts, 1)
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
}
// NOTE: Enable when bug is fixed.
func _TestParseMessageTextHTMLWithPlainAttachment(t *testing.T) { // nolint[deadcode]
rand.Seed(0)
m, mimeBody, plainContents, atts, err := Parse(f("text_html_plain_attachment.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
// BAD: plainContents should not be empty!
assert.Equal(t, "<html><head></head><body>This is body of <b>HTML mail</b> with attachment</body></html>", m.Body)
assert.Equal(t, s("text_html_plain_attachment.b64"), mimeBody)
assert.Equal(t, "This is body of *HTML mail* with attachment", plainContents)
assert.Len(t, atts, 1)
assert.Equal(t, readerToString(atts[0]), "attachment")
}
func TestParseMessageTextHTMLWithImageInline(t *testing.T) {
rand.Seed(0)
m, mimeBody, plainContents, atts, err := Parse(f("text_html_image_inline.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "<html><head></head><body>This is body of <b>HTML mail</b> with attachment</body></html>", m.Body)
assert.Equal(t, s("text_html_image_inline.b64"), mimeBody)
assert.Equal(t, "This is body of *HTML mail* with attachment", plainContents)
// The inline image is an 8x8 mic-dropping gopher.
assert.Len(t, atts, 1)
img, err := png.DecodeConfig(atts[0])
assert.NoError(t, err)
assert.Equal(t, 8, img.Width)
assert.Equal(t, 8, img.Height)
}
// NOTE: Enable when bug is fixed.
func _TestParseMessageWithAttachedPublicKey(t *testing.T) { // nolint[deadcode]
// BAD: Public Key is not attached unless Content-Type is specified (not required)!
m, mimeBody, plainContents, atts, err := Parse(f("text_plain.eml"), "publickey", "publickeyname")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body", m.Body)
assert.Equal(t, s("text_plain_pubkey.b64"), mimeBody)
assert.Equal(t, "body", plainContents)
// BAD: Public key not available as an attachment!
assert.Len(t, atts, 1)
}
// NOTE: Enable when bug is fixed.
func _TestParseMessageTextHTMLWithEmbeddedForeignEncoding(t *testing.T) { // nolint[deadcode]
rand.Seed(0)
m, mimeBody, plainContents, atts, err := Parse(f("text_html_embedded_foreign_encoding.eml"), "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
// BAD: Bridge does not detect the charset specified in the <meta> tag of the html.
assert.Equal(t, `<html><head><meta charset="ISO-8859-2"></head><body>latin2 řšřš</body></html>`, m.Body)
assert.Equal(t, s("text_html_embedded_foreign_encoding.b64"), mimeBody)
assert.Equal(t, `latin2 řšřš`, plainContents)
assert.Len(t, atts, 0)
}

View File

@ -0,0 +1,16 @@
Content-Type: multipart/mixed; boundary=longrandomstring
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--longrandomstring
Content-Transfer-Encoding: base64
Ym9keQo=
--longrandomstring
Content-Transfer-Encoding: base64
c29tZSBvdGhlciBwYXJ0IG9mIHRoZSBtZXNzYWdl
--longrandomstring--
.

View File

@ -0,0 +1,14 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/mixed; boundary=longrandomstring
this part of the text should be ignored
--longrandomstring
body
--longrandomstring
some other part of the message
--longrandomstring--

18
pkg/message/testdata/text_html.b64 vendored Normal file
View File

@ -0,0 +1,18 @@
Content-Type: multipart/alternative; boundary="0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d"
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: base64
Content-Type: text/html
PGh0bWw+PGJvZHk+VGhpcyBpcyBib2R5IG9mIDxiPkhUTUwgbWFpbDwvYj4gd2l0aG91dCBhdHRhY2htZW50PC9ib2R5PjwvaHRtbD4=
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: base64
Content-Type: text/plain
VGhpcyBpcyBib2R5IG9mICpIVE1MIG1haWwqIHdpdGhvdXQgYXR0YWNobWVudA==
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d--
.

5
pkg/message/testdata/text_html.eml vendored Normal file
View File

@ -0,0 +1,5 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: text/html
<html><body>This is body of <b>HTML mail</b> without attachment</body></html>

View File

@ -0,0 +1,6 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: text/html
Content-Transfer-Encoding: 7bit
<html><body>This is body of <b>HTML mail</b> without attachment</body></html>

View File

@ -0,0 +1,19 @@
Content-Transfer-Encoding: 7bit
Content-Type: multipart/alternative; boundary="0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d"
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: 7bit
Content-Type: text/html
<html><body>This is body of <b>HTML mail</b> without attachment</body></html>
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: 7bit
Content-Type: text/plain
This is body of *HTML mail* without attachment
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d--
.

View File

@ -0,0 +1,18 @@
Content-Type: multipart/alternative; boundary="0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d"
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: base64
Content-Type: text/html
PGh0bWw+PGhlYWQ+PG1ldGEgY2hhcnNldD0iSVNPLTg4NTktMiI+PC9oZWFkPjxib2R5PmxhdGluMiD4ufi5PC9ib2R5PjwvaHRtbD4K
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: base64
Content-Type: text/plain
bGF0aW4yIO+/ve+/ve+/ve+/vQ==
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d--
.

View File

@ -0,0 +1,5 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: text/html
<html><head><meta charset="ISO-8859-2"></head><body>latin2 <20><><EFBFBD><EFBFBD></body></html>

View File

@ -0,0 +1,52 @@
Content-Type: multipart/mixed; boundary=longrandomstring
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--longrandomstring
Content-Type: multipart/alternative; boundary="0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d"
This is a multi-part message in MIME format.
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: base64
Content-Type: text/html
PGh0bWw+PGJvZHk+VGhpcyBpcyBib2R5IG9mIDxiPkhUTUwgbWFpbDwvYj4gd2l0aCBhdHRhY2htZW50PC9ib2R5PjwvaHRtbD4=
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: base64
Content-Type: text/plain
VGhpcyBpcyBib2R5IG9mICpIVE1MIG1haWwqIHdpdGggYXR0YWNobWVudA==
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d--
.
--longrandomstring
Content-Disposition: inline
Content-Transfer-Encoding: base64
Content-Type: image/png
iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAABGdBTUEAALGPC/xhBQAAACBjSFJ
NAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAhGVYSWZNTQAqAAAACAAFAR
IAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSASgAAwAAAAEAAgAAh2kABAAAAAEAA
ABaAAAAAAAAASwAAAABAAABLAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAACKADAAQAAAAB
AAAACAAAAAAAXWZ6AAAACXBIWXMAAC4jAAAuIwF4pT92AAACZmlUWHRYTUw6Y29tLmFkb2JlLnh
tcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIE
NvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5O
TkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91
dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4
wLyIKICAgICAgICAgICAgeG1sbnM6ZXhpZj0iaHR0cDovL25zLmFkb2JlLmNvbS9leGlmLzEuMC
8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgI
CAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICAg
ICA8ZXhpZjpDb2xvclNwYWNlPjE8L2V4aWY6Q29sb3JTcGFjZT4KICAgICAgICAgPGV4aWY6UGl
4ZWxYRGltZW5zaW9uPjE2PC9leGlmOlBpeGVsWERpbWVuc2lvbj4KICAgICAgICAgPGV4aWY6UG
l4ZWxZRGltZW5zaW9uPjE2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY
3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CgZBD4sAAAEISURBVBgZY2CAAO5F
x07Zz96xZ0Pn4lXqIKGGhgYmsFTHvAWdW6/dvnb89Yf/B5+9/r/y9IXzbVPahCH6/jMysfAJygo
JC2r++/T619Mb139J8HIb8Gs5hYMUzJ+/gJ1Jmo9H6c+L5wz3bt5iEeLmYOHn42fQ4vyacqGNQS
0xMfEHc7Cvl6CYho4rh5jUPyYefqafLKyMbH9+/d28/dFfdWtfDaZvTy7Zvv72nYGZkeEvw98/f
5j//2P4yCvxq/nU7zVs//8yM2gzMMitOnnu5cUff/8ff/v5/5Xf///vuHBhJcSRDAws9aEMr38c
W7XjNgvzexZ2rn9vbjx/IXl/M9iLM2fOZAUAKCZv7dU+UgAAAAAASUVORK5CYII=
--longrandomstring--
.

View File

@ -0,0 +1,35 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/mixed; boundary=longrandomstring
--longrandomstring
Content-Type: text/html
<html><body>This is body of <b>HTML mail</b> with attachment</body></html>
--longrandomstring
Content-Type: image/png
Content-Disposition: inline
Content-Transfer-Encoding: base64
iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAABGdBTUEAALGPC/xhBQAAACBjSFJ
NAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAhGVYSWZNTQAqAAAACAAFAR
IAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSASgAAwAAAAEAAgAAh2kABAAAAAEAA
ABaAAAAAAAAASwAAAABAAABLAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAACKADAAQAAAAB
AAAACAAAAAAAXWZ6AAAACXBIWXMAAC4jAAAuIwF4pT92AAACZmlUWHRYTUw6Y29tLmFkb2JlLnh
tcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIE
NvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5O
TkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91
dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4
wLyIKICAgICAgICAgICAgeG1sbnM6ZXhpZj0iaHR0cDovL25zLmFkb2JlLmNvbS9leGlmLzEuMC
8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgI
CAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICAg
ICA8ZXhpZjpDb2xvclNwYWNlPjE8L2V4aWY6Q29sb3JTcGFjZT4KICAgICAgICAgPGV4aWY6UGl
4ZWxYRGltZW5zaW9uPjE2PC9leGlmOlBpeGVsWERpbWVuc2lvbj4KICAgICAgICAgPGV4aWY6UG
l4ZWxZRGltZW5zaW9uPjE2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY
3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CgZBD4sAAAEISURBVBgZY2CAAO5F
x07Zz96xZ0Pn4lXqIKGGhgYmsFTHvAWdW6/dvnb89Yf/B5+9/r/y9IXzbVPahCH6/jMysfAJygo
JC2r++/T619Mb139J8HIb8Gs5hYMUzJ+/gJ1Jmo9H6c+L5wz3bt5iEeLmYOHn42fQ4vyacqGNQS
0xMfEHc7Cvl6CYho4rh5jUPyYefqafLKyMbH9+/d28/dFfdWtfDaZvTy7Zvv72nYGZkeEvw98/f
5j//2P4yCvxq/nU7zVs//8yM2gzMMitOnnu5cUff/8ff/v5/5Xf///vuHBhJcSRDAws9aEMr38c
W7XjNgvzexZ2rn9vbjx/IXl/M9iLM2fOZAUAKCZv7dU+UgAAAAAASUVORK5CYII=
--longrandomstring--

View File

@ -0,0 +1,31 @@
Content-Type: multipart/mixed; boundary=longrandomstring
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--longrandomstring
Content-Type: multipart/alternative; boundary="0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d"
This is a multi-part message in MIME format.
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: base64
Content-Type: text/html
PGh0bWw+PGJvZHk+VGhpcyBpcyBib2R5IG9mIDxiPkhUTUwgbWFpbDwvYj4gd2l0aCBhdHRhY2htZW50PC9ib2R5PjwvaHRtbD4=
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d
Content-Transfer-Encoding: base64
Content-Type: text/plain
VGhpcyBpcyBib2R5IG9mICpIVE1MIG1haWwqIHdpdGggYXR0YWNobWVudA==
--0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d--
.
--longrandomstring
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream
aWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGhpIQ==
--longrandomstring--
.

View File

@ -0,0 +1,14 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/mixed; boundary=longrandomstring
--longrandomstring
Content-Type: text/html
<html><body>This is body of <b>HTML mail</b> with attachment</body></html>
--longrandomstring
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
aWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGhpIQ==
--longrandomstring--

View File

@ -0,0 +1,18 @@
Content-Type: multipart/mixed; boundary=longrandomstring
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--longrandomstring
Content-Transfer-Encoding: base64
Content-Type: text/html
PGh0bWw+PGJvZHk+VGhpcyBpcyBib2R5IG9mIDxiPkhUTUwgbWFpbDwvYj4gd2l0aCBhdHRhY2htZW50PC9ib2R5PjwvaHRtbD4=
--longrandomstring
Content-Disposition: attachment
Content-Transfer-Encoding: base64
YXR0YWNobWVudA==
--longrandomstring--
.

View File

@ -0,0 +1,13 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/mixed; boundary=longrandomstring
--longrandomstring
Content-Type: text/html
<html><body>This is body of <b>HTML mail</b> with attachment</body></html>
--longrandomstring
Content-Disposition: attachment
attachment
--longrandomstring--

5
pkg/message/testdata/text_plain.b64 vendored Normal file
View File

@ -0,0 +1,5 @@
Content-Transfer-Encoding: base64
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Ym9keQ==

4
pkg/message/testdata/text_plain.eml vendored Normal file
View File

@ -0,0 +1,4 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
body

View File

@ -0,0 +1,5 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Transfer-Encoding: 7bit
body

View File

@ -0,0 +1,5 @@
Content-Transfer-Encoding: 7bit
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
body

View File

@ -0,0 +1,38 @@
Content-Type: multipart/related; boundary=longrandomstring
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--longrandomstring
Content-Transfer-Encoding: base64
Ym9keQ==
--longrandomstring
Content-Disposition: inline
Content-Transfer-Encoding: base64
Content-Type: image/png
iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAABGdBTUEAALGPC/xhBQAAACBjSFJ
NAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAhGVYSWZNTQAqAAAACAAFAR
IAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSASgAAwAAAAEAAgAAh2kABAAAAAEAA
ABaAAAAAAAAASwAAAABAAABLAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAACKADAAQAAAAB
AAAACAAAAAAAXWZ6AAAACXBIWXMAAC4jAAAuIwF4pT92AAACZmlUWHRYTUw6Y29tLmFkb2JlLnh
tcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIE
NvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5O
TkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91
dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4
wLyIKICAgICAgICAgICAgeG1sbnM6ZXhpZj0iaHR0cDovL25zLmFkb2JlLmNvbS9leGlmLzEuMC
8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgI
CAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICAg
ICA8ZXhpZjpDb2xvclNwYWNlPjE8L2V4aWY6Q29sb3JTcGFjZT4KICAgICAgICAgPGV4aWY6UGl
4ZWxYRGltZW5zaW9uPjE2PC9leGlmOlBpeGVsWERpbWVuc2lvbj4KICAgICAgICAgPGV4aWY6UG
l4ZWxZRGltZW5zaW9uPjE2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY
3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CgZBD4sAAAEISURBVBgZY2CAAO5F
x07Zz96xZ0Pn4lXqIKGGhgYmsFTHvAWdW6/dvnb89Yf/B5+9/r/y9IXzbVPahCH6/jMysfAJygo
JC2r++/T619Mb139J8HIb8Gs5hYMUzJ+/gJ1Jmo9H6c+L5wz3bt5iEeLmYOHn42fQ4vyacqGNQS
0xMfEHc7Cvl6CYho4rh5jUPyYefqafLKyMbH9+/d28/dFfdWtfDaZvTy7Zvv72nYGZkeEvw98/f
5j//2P4yCvxq/nU7zVs//8yM2gzMMitOnnu5cUff/8ff/v5/5Xf///vuHBhJcSRDAws9aEMr38c
W7XjNgvzexZ2rn9vbjx/IXl/M9iLM2fOZAUAKCZv7dU+UgAAAAAASUVORK5CYII=
--longrandomstring--
.

View File

@ -0,0 +1,34 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/related; boundary=longrandomstring
--longrandomstring
body
--longrandomstring
Content-Type: image/png
Content-Disposition: inline
Content-Transfer-Encoding: base64
iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAABGdBTUEAALGPC/xhBQAAACBjSFJ
NAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAhGVYSWZNTQAqAAAACAAFAR
IAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSASgAAwAAAAEAAgAAh2kABAAAAAEAA
ABaAAAAAAAAASwAAAABAAABLAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAACKADAAQAAAAB
AAAACAAAAAAAXWZ6AAAACXBIWXMAAC4jAAAuIwF4pT92AAACZmlUWHRYTUw6Y29tLmFkb2JlLnh
tcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIE
NvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5O
TkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91
dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4
wLyIKICAgICAgICAgICAgeG1sbnM6ZXhpZj0iaHR0cDovL25zLmFkb2JlLmNvbS9leGlmLzEuMC
8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgI
CAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICAg
ICA8ZXhpZjpDb2xvclNwYWNlPjE8L2V4aWY6Q29sb3JTcGFjZT4KICAgICAgICAgPGV4aWY6UGl
4ZWxYRGltZW5zaW9uPjE2PC9leGlmOlBpeGVsWERpbWVuc2lvbj4KICAgICAgICAgPGV4aWY6UG
l4ZWxZRGltZW5zaW9uPjE2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY
3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+CgZBD4sAAAEISURBVBgZY2CAAO5F
x07Zz96xZ0Pn4lXqIKGGhgYmsFTHvAWdW6/dvnb89Yf/B5+9/r/y9IXzbVPahCH6/jMysfAJygo
JC2r++/T619Mb139J8HIb8Gs5hYMUzJ+/gJ1Jmo9H6c+L5wz3bt5iEeLmYOHn42fQ4vyacqGNQS
0xMfEHc7Cvl6CYho4rh5jUPyYefqafLKyMbH9+/d28/dFfdWtfDaZvTy7Zvv72nYGZkeEvw98/f
5j//2P4yCvxq/nU7zVs//8yM2gzMMitOnnu5cUff/8ff/v5/5Xf///vuHBhJcSRDAws9aEMr38c
W7XjNgvzexZ2rn9vbjx/IXl/M9iLM2fOZAUAKCZv7dU+UgAAAAAASUVORK5CYII=
--longrandomstring--

View File

@ -0,0 +1,6 @@
Content-Transfer-Encoding: base64
Content-Type: text/plain; charset=ISO-8859-1
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
6enp6enp6Q==

View File

@ -0,0 +1,5 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: text/plain; charset=ISO-8859-1
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

View File

@ -0,0 +1,17 @@
Content-Type: multipart/mixed; boundary=longrandomstring
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--longrandomstring
Content-Transfer-Encoding: base64
Ym9keQ==
--longrandomstring
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream
aWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGhpIQ==
--longrandomstring--
.

View File

@ -0,0 +1,13 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/mixed; boundary=longrandomstring
--longrandomstring
body
--longrandomstring
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
aWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGhpIQ==
--longrandomstring--

View File

@ -0,0 +1,17 @@
Content-Type: multipart/mixed; boundary=longrandomstring
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--longrandomstring
Content-Transfer-Encoding: base64
Ym9keQ==
--longrandomstring
Content-Disposition: attachment
Content-Transfer-Encoding: base64
YXR0YWNobWVudA==
--longrandomstring--
.

View File

@ -0,0 +1,12 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/mixed; boundary=longrandomstring
--longrandomstring
body
--longrandomstring
Content-Disposition: attachment
attachment
--longrandomstring--

View File

@ -0,0 +1,19 @@
Content-Type: multipart/mixed; boundary="52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2"
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2
Content-Transfer-Encoding: base64
Ym9keQ==
--52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2
Content-Disposition: attachment; filename="publickeyname.asc.pgp"
Content-Transfer-Encoding: base64
Content-Type: application/pgp-key; name="publickeyname"
cHVibGlja2V5
--52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2--
.

View File

@ -0,0 +1,6 @@
Content-Transfer-Encoding: base64
Content-Type: text/plain
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
6enp6enp6Q==

View File

@ -0,0 +1,5 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: text/plain
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

View File

@ -0,0 +1,6 @@
Content-Transfer-Encoding: base64
Content-Type: text/plain
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
+Ln4ufi5

View File

@ -0,0 +1,5 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: text/plain
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

View File

@ -0,0 +1,6 @@
Content-Transfer-Encoding: base64
Content-Type: text/plain; charset=utf-8
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Ym9keQ==

View File

@ -0,0 +1,5 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: text/plain; charset=utf-8
body