forked from Silverfish/proton-bridge
feat: better handling of multipart messages
This commit is contained in:
@ -61,79 +61,79 @@ func readerToString(r io.Reader) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlain(t *testing.T) {
|
||||
func TestParseTextPlain(t *testing.T) {
|
||||
f := f("text_plain.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
assert.Equal(t, s("text_plain.mime"), mimeMessage)
|
||||
assert.Equal(t, "body", plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainUTF8(t *testing.T) {
|
||||
func TestParseTextPlainUTF8(t *testing.T) {
|
||||
f := f("text_plain_utf8.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
assert.Equal(t, s("text_plain_utf8.mime"), mimeMessage)
|
||||
assert.Equal(t, "body", plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainLatin1(t *testing.T) {
|
||||
func TestParseTextPlainLatin1(t *testing.T) {
|
||||
f := f("text_plain_latin1.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "ééééééé", plainContents)
|
||||
assert.Equal(t, s("text_plain_latin1.mime"), mimeMessage)
|
||||
assert.Equal(t, "ééééééé", plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainUnknownCharsetIsActuallyLatin1(t *testing.T) {
|
||||
func TestParseTextPlainUnknownCharsetIsActuallyLatin1(t *testing.T) {
|
||||
f := f("text_plain_unknown_latin1.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "ééééééé", plainContents)
|
||||
assert.Equal(t, s("text_plain_unknown_latin1.mime"), mimeMessage)
|
||||
assert.Equal(t, "ééééééé", plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainUnknownCharsetIsActuallyLatin2(t *testing.T) {
|
||||
func TestParseTextPlainUnknownCharsetIsActuallyLatin2(t *testing.T) {
|
||||
f := f("text_plain_unknown_latin2.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
|
||||
@ -146,271 +146,271 @@ func TestParseMessageTextPlainUnknownCharsetIsActuallyLatin2(t *testing.T) {
|
||||
assert.NotEqual(t, []byte("řšřšřš"), expect)
|
||||
|
||||
assert.Equal(t, string(expect), m.Body)
|
||||
assert.Equal(t, s("text_plain_unknown_latin2.mime"), mimeBody)
|
||||
assert.Equal(t, string(expect), plainContents)
|
||||
assert.Equal(t, s("text_plain_unknown_latin2.mime"), mimeMessage)
|
||||
assert.Equal(t, string(expect), plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainAlready7Bit(t *testing.T) {
|
||||
func TestParseTextPlainAlready7Bit(t *testing.T) {
|
||||
f := f("text_plain_7bit.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.Equal(t, s("text_plain_7bit.mime"), mimeMessage)
|
||||
assert.Equal(t, "body", plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainWithOctetAttachment(t *testing.T) {
|
||||
func TestParseTextPlainWithOctetAttachment(t *testing.T) {
|
||||
f := f("text_plain_octet_attachment.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
assert.Equal(t, s("text_plain_octet_attachment.mime"), mimeMessage)
|
||||
assert.Equal(t, "body", plainBody)
|
||||
|
||||
require.Len(t, atts, 1)
|
||||
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
|
||||
require.Len(t, attReaders, 1)
|
||||
assert.Equal(t, readerToString(attReaders[0]), "if you are reading this, hi!")
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainWithOctetAttachmentGoodFilename(t *testing.T) {
|
||||
func TestParseTextPlainWithOctetAttachmentGoodFilename(t *testing.T) {
|
||||
f := f("text_plain_octet_attachment_good_2231_filename.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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_good_2231_filename.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
assert.Equal(t, s("text_plain_octet_attachment_good_2231_filename.mime"), mimeMessage)
|
||||
assert.Equal(t, "body", plainBody)
|
||||
|
||||
assert.Len(t, atts, 1)
|
||||
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
|
||||
assert.Len(t, attReaders, 1)
|
||||
assert.Equal(t, readerToString(attReaders[0]), "if you are reading this, hi!")
|
||||
assert.Equal(t, "😁😂.txt", m.Attachments[0].Name)
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainWithOctetAttachmentBadFilename(t *testing.T) {
|
||||
func TestParseTextPlainWithOctetAttachmentBadFilename(t *testing.T) {
|
||||
f := f("text_plain_octet_attachment_bad_2231_filename.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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_bad_2231_filename.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
assert.Equal(t, s("text_plain_octet_attachment_bad_2231_filename.mime"), mimeMessage)
|
||||
assert.Equal(t, "body", plainBody)
|
||||
|
||||
assert.Len(t, atts, 1)
|
||||
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
|
||||
assert.Len(t, attReaders, 1)
|
||||
assert.Equal(t, readerToString(attReaders[0]), "if you are reading this, hi!")
|
||||
assert.Equal(t, "attachment.bin", m.Attachments[0].Name)
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainWithPlainAttachment(t *testing.T) {
|
||||
func TestParseTextPlainWithPlainAttachment(t *testing.T) {
|
||||
f := f("text_plain_plain_attachment.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
assert.Equal(t, s("text_plain_plain_attachment.mime"), mimeMessage)
|
||||
assert.Equal(t, "body", plainBody)
|
||||
|
||||
require.Len(t, atts, 1)
|
||||
assert.Equal(t, readerToString(atts[0]), "attachment")
|
||||
require.Len(t, attReaders, 1)
|
||||
assert.Equal(t, readerToString(attReaders[0]), "attachment")
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainWithImageInline(t *testing.T) {
|
||||
func TestParseTextPlainWithImageInline(t *testing.T) {
|
||||
f := f("text_plain_image_inline.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
assert.Equal(t, s("text_plain_image_inline.mime"), mimeMessage)
|
||||
assert.Equal(t, "body", plainBody)
|
||||
|
||||
// The inline image is an 8x8 mic-dropping gopher.
|
||||
require.Len(t, atts, 1)
|
||||
img, err := png.DecodeConfig(atts[0])
|
||||
require.Len(t, attReaders, 1)
|
||||
img, err := png.DecodeConfig(attReaders[0])
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 8, img.Width)
|
||||
assert.Equal(t, 8, img.Height)
|
||||
}
|
||||
|
||||
func TestParseMessageWithMultipleTextParts(t *testing.T) {
|
||||
func TestParseWithMultipleTextParts(t *testing.T) {
|
||||
f := f("multiple_text_parts.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "body\nsome other part of the message", plainContents)
|
||||
assert.Equal(t, s("multiple_text_parts.mime"), mimeMessage)
|
||||
assert.Equal(t, "body\nsome other part of the message", plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMessageTextHTML(t *testing.T) {
|
||||
func TestParseTextHTML(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
f := f("text_html.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "This is body of *HTML mail* without attachment", plainContents)
|
||||
assert.Equal(t, s("text_html.mime"), mimeMessage)
|
||||
assert.Equal(t, "This is body of *HTML mail* without attachment", plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMessageTextHTMLAlready7Bit(t *testing.T) {
|
||||
func TestParseTextHTMLAlready7Bit(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
f := f("text_html_7bit.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
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.Equal(t, s("text_html_7bit.mime"), mimeMessage)
|
||||
assert.Equal(t, "This is body of *HTML mail* without attachment", plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMessageTextHTMLWithOctetAttachment(t *testing.T) {
|
||||
func TestParseTextHTMLWithOctetAttachment(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
f := f("text_html_octet_attachment.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "This is body of *HTML mail* with attachment", plainContents)
|
||||
assert.Equal(t, s("text_html_octet_attachment.mime"), mimeMessage)
|
||||
assert.Equal(t, "This is body of *HTML mail* with attachment", plainBody)
|
||||
|
||||
require.Len(t, atts, 1)
|
||||
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
|
||||
require.Len(t, attReaders, 1)
|
||||
assert.Equal(t, readerToString(attReaders[0]), "if you are reading this, hi!")
|
||||
}
|
||||
|
||||
func TestParseMessageTextHTMLWithPlainAttachment(t *testing.T) { // nolint[deadcode]
|
||||
func TestParseTextHTMLWithPlainAttachment(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
f := f("text_html_plain_attachment.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.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!
|
||||
// BAD: plainBody 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.mime"), mimeBody)
|
||||
assert.Equal(t, "This is body of *HTML mail* with attachment", plainContents)
|
||||
assert.Equal(t, s("text_html_plain_attachment.mime"), mimeMessage)
|
||||
assert.Equal(t, "This is body of *HTML mail* with attachment", plainBody)
|
||||
|
||||
require.Len(t, atts, 1)
|
||||
assert.Equal(t, readerToString(atts[0]), "attachment")
|
||||
require.Len(t, attReaders, 1)
|
||||
assert.Equal(t, readerToString(attReaders[0]), "attachment")
|
||||
}
|
||||
|
||||
func TestParseMessageTextHTMLWithImageInline(t *testing.T) {
|
||||
func TestParseTextHTMLWithImageInline(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
f := f("text_html_image_inline.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
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.mime"), mimeBody)
|
||||
assert.Equal(t, "This is body of *HTML mail* with attachment", plainContents)
|
||||
assert.Equal(t, s("text_html_image_inline.mime"), mimeMessage)
|
||||
assert.Equal(t, "This is body of *HTML mail* with attachment", plainBody)
|
||||
|
||||
// The inline image is an 8x8 mic-dropping gopher.
|
||||
require.Len(t, atts, 1)
|
||||
img, err := png.DecodeConfig(atts[0])
|
||||
require.Len(t, attReaders, 1)
|
||||
img, err := png.DecodeConfig(attReaders[0])
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 8, img.Width)
|
||||
assert.Equal(t, 8, img.Height)
|
||||
}
|
||||
|
||||
func TestParseMessageWithAttachedPublicKey(t *testing.T) { // nolint[deadcode]
|
||||
func TestParseWithAttachedPublicKey(t *testing.T) {
|
||||
f := f("text_plain.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
// BAD: Public Key is not attached unless Content-Type is specified (not required)!
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "publickey", "publickeyname")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "publickey", "publickeyname")
|
||||
require.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.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
assert.Equal(t, s("text_plain_pubkey.mime"), mimeMessage)
|
||||
assert.Equal(t, "body", plainBody)
|
||||
|
||||
// BAD: Public key not available as an attachment!
|
||||
require.Len(t, atts, 1)
|
||||
require.Len(t, attReaders, 1)
|
||||
}
|
||||
|
||||
func TestParseMessageTextHTMLWithEmbeddedForeignEncoding(t *testing.T) { // nolint[deadcode]
|
||||
func TestParseTextHTMLWithEmbeddedForeignEncoding(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
f := f("text_html_embedded_foreign_encoding.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
m, mimeMessage, plainBody, attReaders, err := Parse(f, "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
|
||||
@ -418,8 +418,58 @@ func TestParseMessageTextHTMLWithEmbeddedForeignEncoding(t *testing.T) { // noli
|
||||
|
||||
// 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.mime"), mimeBody)
|
||||
assert.Equal(t, `latin2 řšřš`, plainContents)
|
||||
assert.Equal(t, s("text_html_embedded_foreign_encoding.mime"), mimeMessage)
|
||||
assert.Equal(t, `latin2 řšřš`, plainBody)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
assert.Len(t, attReaders, 0)
|
||||
}
|
||||
|
||||
func TestParseMultipartAlternative(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
f := f("multipart_alternative.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, _, plainBody, _, err := Parse(f, "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `"schizofrenic" <schizofrenic@pm.me>`, m.Sender.String())
|
||||
assert.Equal(t, `<pmbridgeietest@outlook.com>`, m.ToList[0].String())
|
||||
|
||||
assert.Equal(t, `<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
<b>aoeuaoeu</b>
|
||||
</body>
|
||||
</html>
|
||||
`, m.Body)
|
||||
|
||||
assert.Equal(t, "*aoeuaoeu*\n\n", plainBody)
|
||||
}
|
||||
|
||||
func TestParseMultipartAlternativeNested(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
f := f("multipart_alternative_nested.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, _, plainBody, _, err := Parse(f, "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `"schizofrenic" <schizofrenic@pm.me>`, m.Sender.String())
|
||||
assert.Equal(t, `<pmbridgeietest@outlook.com>`, m.ToList[0].String())
|
||||
|
||||
assert.Equal(t, `<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
<b>multipart 2.2</b>
|
||||
</body>
|
||||
</html>
|
||||
`, m.Body)
|
||||
|
||||
assert.Equal(t, "*multipart 2.1*\n\n", plainBody)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user