mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2026-02-08 10:08:33 +00:00
feat: revert back to quoted-printable
This commit is contained in:
@ -115,7 +115,7 @@ func TestRFC822AddressFormat(t *testing.T) { //nolint[funlen]
|
||||
}
|
||||
}
|
||||
|
||||
func f(filename string) io.Reader {
|
||||
func f(filename string) io.ReadCloser {
|
||||
f, err := os.Open(filepath.Join("testdata", filename))
|
||||
|
||||
if err != nil {
|
||||
@ -146,63 +146,78 @@ func readerToString(r io.Reader) string {
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlain(t *testing.T) {
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_plain.eml"), "", "")
|
||||
f := f("text_plain.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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, "body", m.Body)
|
||||
assert.Equal(t, s("text_plain.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_plain.mime"), 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"), "", "")
|
||||
f := f("text_plain_utf8.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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, "body", m.Body)
|
||||
assert.Equal(t, s("text_plain_utf8.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_plain_utf8.mime"), 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"), "", "")
|
||||
f := f("text_plain_latin1.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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, "ééééééé", m.Body)
|
||||
assert.Equal(t, s("text_plain_latin1.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_plain_latin1.mime"), 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"), "", "")
|
||||
f := f("text_plain_unknown_latin1.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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, "ééééééé", m.Body)
|
||||
assert.Equal(t, s("text_plain_unknown_latin1.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_plain_unknown_latin1.mime"), 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"), "", "")
|
||||
f := f("text_plain_unknown_latin2.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
|
||||
@ -215,14 +230,17 @@ 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.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_plain_unknown_latin2.mime"), 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"), "", "")
|
||||
f := f("text_plain_7bit.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
|
||||
@ -236,14 +254,17 @@ func TestParseMessageTextPlainAlready7Bit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainWithOctetAttachment(t *testing.T) {
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_octet_attachment.eml"), "", "")
|
||||
f := f("text_plain_octet_attachment.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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, "body", m.Body)
|
||||
assert.Equal(t, s("text_plain_octet_attachment.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_plain_octet_attachment.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
|
||||
assert.Len(t, atts, 1)
|
||||
@ -251,14 +272,17 @@ func TestParseMessageTextPlainWithOctetAttachment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainWithPlainAttachment(t *testing.T) {
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_plain_attachment.eml"), "", "")
|
||||
f := f("text_plain_plain_attachment.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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, "body", m.Body)
|
||||
assert.Equal(t, s("text_plain_plain_attachment.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_plain_plain_attachment.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
|
||||
assert.Len(t, atts, 1)
|
||||
@ -266,14 +290,17 @@ func TestParseMessageTextPlainWithPlainAttachment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseMessageTextPlainWithImageInline(t *testing.T) {
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_plain_image_inline.eml"), "", "")
|
||||
f := f("text_plain_image_inline.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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, "body", m.Body)
|
||||
assert.Equal(t, s("text_plain_image_inline.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_plain_image_inline.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
|
||||
// The inline image is an 8x8 mic-dropping gopher.
|
||||
@ -285,14 +312,17 @@ func TestParseMessageTextPlainWithImageInline(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseMessageWithMultipleTextParts(t *testing.T) {
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("multiple_text_parts.eml"), "", "")
|
||||
f := f("multiple_text_parts.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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, "body\nsome other part of the message", m.Body)
|
||||
assert.Equal(t, s("multiple_text_parts.b64"), mimeBody)
|
||||
assert.Equal(t, s("multiple_text_parts.mime"), mimeBody)
|
||||
assert.Equal(t, "body\nsome other part of the message", plainContents)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
@ -301,14 +331,17 @@ func TestParseMessageWithMultipleTextParts(t *testing.T) {
|
||||
func TestParseMessageTextHTML(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_html.eml"), "", "")
|
||||
f := f("text_html.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_html.mime"), mimeBody)
|
||||
assert.Equal(t, "This is body of *HTML mail* without attachment", plainContents)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
@ -317,7 +350,10 @@ func TestParseMessageTextHTML(t *testing.T) {
|
||||
func TestParseMessageTextHTMLAlready7Bit(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_html_7bit.eml"), "", "")
|
||||
f := f("text_html_7bit.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
|
||||
@ -333,14 +369,17 @@ func TestParseMessageTextHTMLAlready7Bit(t *testing.T) {
|
||||
func TestParseMessageTextHTMLWithOctetAttachment(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_html_octet_attachment.eml"), "", "")
|
||||
f := f("text_html_octet_attachment.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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_octet_attachment.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_html_octet_attachment.mime"), mimeBody)
|
||||
assert.Equal(t, "This is body of *HTML mail* with attachment", plainContents)
|
||||
|
||||
assert.Len(t, atts, 1)
|
||||
@ -351,7 +390,10 @@ func TestParseMessageTextHTMLWithOctetAttachment(t *testing.T) {
|
||||
func _TestParseMessageTextHTMLWithPlainAttachment(t *testing.T) { // nolint[deadcode]
|
||||
rand.Seed(0)
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_html_plain_attachment.eml"), "", "")
|
||||
f := f("text_html_plain_attachment.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
|
||||
@ -359,7 +401,7 @@ func _TestParseMessageTextHTMLWithPlainAttachment(t *testing.T) { // nolint[dead
|
||||
|
||||
// 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, s("text_html_plain_attachment.mime"), mimeBody)
|
||||
assert.Equal(t, "This is body of *HTML mail* with attachment", plainContents)
|
||||
|
||||
assert.Len(t, atts, 1)
|
||||
@ -369,14 +411,17 @@ func _TestParseMessageTextHTMLWithPlainAttachment(t *testing.T) { // nolint[dead
|
||||
func TestParseMessageTextHTMLWithImageInline(t *testing.T) {
|
||||
rand.Seed(0)
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_html_image_inline.eml"), "", "")
|
||||
f := f("text_html_image_inline.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, 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.b64"), mimeBody)
|
||||
assert.Equal(t, s("text_html_image_inline.mime"), mimeBody)
|
||||
assert.Equal(t, "This is body of *HTML mail* with attachment", plainContents)
|
||||
|
||||
// The inline image is an 8x8 mic-dropping gopher.
|
||||
@ -389,15 +434,18 @@ func TestParseMessageTextHTMLWithImageInline(t *testing.T) {
|
||||
|
||||
// NOTE: Enable when bug is fixed.
|
||||
func _TestParseMessageWithAttachedPublicKey(t *testing.T) { // nolint[deadcode]
|
||||
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("text_plain.eml"), "publickey", "publickeyname")
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "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, s("text_plain_pubkey.mime"), mimeBody)
|
||||
assert.Equal(t, "body", plainContents)
|
||||
|
||||
// BAD: Public key not available as an attachment!
|
||||
@ -408,7 +456,10 @@ func _TestParseMessageWithAttachedPublicKey(t *testing.T) { // nolint[deadcode]
|
||||
func _TestParseMessageTextHTMLWithEmbeddedForeignEncoding(t *testing.T) { // nolint[deadcode]
|
||||
rand.Seed(0)
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f("text_html_embedded_foreign_encoding.eml"), "", "")
|
||||
f := f("text_html_embedded_foreign_encoding.eml")
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
|
||||
@ -416,7 +467,7 @@ func _TestParseMessageTextHTMLWithEmbeddedForeignEncoding(t *testing.T) { // nol
|
||||
|
||||
// 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, s("text_html_embedded_foreign_encoding.mime"), mimeBody)
|
||||
assert.Equal(t, `latin2 řšřš`, plainContents)
|
||||
|
||||
assert.Len(t, atts, 0)
|
||||
|
||||
Reference in New Issue
Block a user