mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-08 23:12:54 +01:00
Add tests for various email scenarios
This commit introduces tests for different email scenarios including emails with no boundaries, emails with attachments, emails with embedded items, and multipart mixed emails. The tests ensure that the code correctly returns all expected parts of the email (e.g., embeds, attachments, parts) and that it correctly processes the email subject.
This commit is contained in:
parent
68d0fe9cd3
commit
ca201b1548
1 changed files with 252 additions and 1 deletions
253
eml_test.go
253
eml_test.go
|
@ -283,6 +283,36 @@ VGhpcyBpcyBhIHNpbXBsZSB0ZXN0IHRleHQgZmlsZSBhdHRhY2htZW50LgoKSXQgCiAgaGFzCiAg
|
|||
ICAgc2V2ZXJhbAogICAgICAgICAgICBuZXdsaW5lcwoJICAgICAgICAgICAgYW5kCgkgICAgc3Bh
|
||||
Y2VzCiAgICAgaW4KICBpdAouCgpBcyB3ZWxsIGFzIGFuIGVtb2ppOiDwn5mCCg==
|
||||
|
||||
--45c75ff528359022eb03679fbe91877d75343f2e1f8193e349deffa33ff7--`
|
||||
exampleMailPlainB64WithAttachmentNoBoundary = `Date: Wed, 01 Nov 2023 00:00:00 +0000
|
||||
MIME-Version: 1.0
|
||||
Message-ID: <1305604950.683004066175.AAAAAAAAaaaaaaaaB@go-mail.dev>
|
||||
Subject: Example mail // plain text base64 with attachment
|
||||
User-Agent: go-mail v0.4.1 // https://github.com/wneessen/go-mail
|
||||
X-Mailer: go-mail v0.4.1 // https://github.com/wneessen/go-mail
|
||||
From: "Toni Tester" <go-mail@go-mail.dev>
|
||||
To: <go-mail+test@go-mail.dev>
|
||||
Cc: <go-mail+cc@go-mail.dev>
|
||||
Content-Type: multipart/mixed;
|
||||
|
||||
--45c75ff528359022eb03679fbe91877d75343f2e1f8193e349deffa33ff7
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
|
||||
RGVhciBDdXN0b21lciwKClRoaXMgaXMgYSB0ZXN0IG1haWwuIFBsZWFzZSBkbyBub3QgcmVwbHkg
|
||||
dG8gdGhpcy4gQWxzbyB0aGlzIGxpbmUgaXMgdmVyeSBsb25nIHNvIGl0CnNob3VsZCBiZSB3cmFw
|
||||
cGVkLgoKClRoYW5rIHlvdXIgZm9yIHlvdXIgYnVzaW5lc3MhClRoZSBnby1tYWlsIHRlYW0KCi0t
|
||||
ClRoaXMgaXMgYSBzaWduYXR1cmU=
|
||||
|
||||
--45c75ff528359022eb03679fbe91877d75343f2e1f8193e349deffa33ff7
|
||||
Content-Disposition: attachment; filename="test.attachment"
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Type: application/octet-stream; name="test.attachment"
|
||||
|
||||
VGhpcyBpcyBhIHNpbXBsZSB0ZXN0IHRleHQgZmlsZSBhdHRhY2htZW50LgoKSXQgCiAgaGFzCiAg
|
||||
ICAgc2V2ZXJhbAogICAgICAgICAgICBuZXdsaW5lcwoJICAgICAgICAgICAgYW5kCgkgICAgc3Bh
|
||||
Y2VzCiAgICAgaW4KICBpdAouCgpBcyB3ZWxsIGFzIGFuIGVtb2ppOiDwn5mCCg==
|
||||
|
||||
--45c75ff528359022eb03679fbe91877d75343f2e1f8193e349deffa33ff7--`
|
||||
exampleMailPlainB64BrokenBody = `Date: Wed, 01 Nov 2023 00:00:00 +0000
|
||||
MIME-Version: 1.0
|
||||
|
@ -342,6 +372,159 @@ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NgYGD4DwABBAEAwS2O
|
|||
UAAAAABJRU5ErkJggg==
|
||||
|
||||
--ffbcfb94b44e5297325102f6ced05b3b37f1d70fc38a5e78dc73c1a8434b--`
|
||||
exampleMailPlainB64WithEmbedNoContentID = `Date: Wed, 01 Nov 2023 00:00:00 +0000
|
||||
MIME-Version: 1.0
|
||||
Message-ID: <1305604950.683004066175.AAAAAAAAaaaaaaaaB@go-mail.dev>
|
||||
Subject: Example mail // plain text base64 with embed
|
||||
User-Agent: go-mail v0.4.1 // https://github.com/wneessen/go-mail
|
||||
X-Mailer: go-mail v0.4.1 // https://github.com/wneessen/go-mail
|
||||
From: "Toni Tester" <go-mail@go-mail.dev>
|
||||
To: <go-mail+test@go-mail.dev>
|
||||
Cc: <go-mail+cc@go-mail.dev>
|
||||
Content-Type: multipart/related;
|
||||
boundary=ffbcfb94b44e5297325102f6ced05b3b37f1d70fc38a5e78dc73c1a8434b
|
||||
|
||||
--ffbcfb94b44e5297325102f6ced05b3b37f1d70fc38a5e78dc73c1a8434b
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
|
||||
This is a test body string
|
||||
--ffbcfb94b44e5297325102f6ced05b3b37f1d70fc38a5e78dc73c1a8434b
|
||||
Content-Disposition: inline; filename="pixel.png"
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Type: image/png; name="pixel.png"
|
||||
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2NgYGD4DwABBAEAwS2O
|
||||
UAAAAABJRU5ErkJggg==
|
||||
|
||||
--ffbcfb94b44e5297325102f6ced05b3b37f1d70fc38a5e78dc73c1a8434b--`
|
||||
exampleMailMultipartMixedAlternativeRelated = `Date: Wed, 01 Nov 2023 00:00:00 +0000
|
||||
MIME-Version: 1.0
|
||||
Message-ID: <1305604950.683004066175.AAAAAAAAaaaaaaaaB@go-mail.dev>
|
||||
Subject: Example mail // plain text base64 with attachment, embed and alternative part
|
||||
User-Agent: go-mail v0.4.1 // https://github.com/wneessen/go-mail
|
||||
X-Mailer: go-mail v0.4.1 // https://github.com/wneessen/go-mail
|
||||
From: "Toni Tester" <go-mail@go-mail.dev>
|
||||
To: <go-mail+test@go-mail.dev>
|
||||
Cc: <go-mail+cc@go-mail.dev>
|
||||
Content-Type: multipart/mixed;
|
||||
boundary=fe785e0384e2607697cc2ecb17cce003003bb7ca9112104f3e8ce727edb5
|
||||
|
||||
--fe785e0384e2607697cc2ecb17cce003003bb7ca9112104f3e8ce727edb5
|
||||
Content-Type: multipart/related;
|
||||
boundary=5897e40a22c608e252cfab849e966112fcbd5a1c291208026b3ca2bfab8a
|
||||
|
||||
|
||||
|
||||
--5897e40a22c608e252cfab849e966112fcbd5a1c291208026b3ca2bfab8a
|
||||
Content-Type: multipart/alternative;
|
||||
boundary=cbace12de35ef4eae53fd974ccd41cb2aee4f9c9c76057ec8bfdd0c97813
|
||||
|
||||
|
||||
|
||||
--cbace12de35ef4eae53fd974ccd41cb2aee4f9c9c76057ec8bfdd0c97813
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
|
||||
RGVhciBDdXN0b21lciwKCkdvb2QgbmV3cyEgWW91ciBvcmRlciBpcyBvbiB0aGUgd2F5IGFuZCBp
|
||||
bnZvaWNlIGlzIGF0dGFjaGVkIQoKWW91IHdpbGwgZmluZCB5b3VyIHRyYWNraW5nIG51bWJlciBv
|
||||
biB0aGUgaW52b2ljZS4gVHJhY2tpbmcgZGF0YSBtYXkgdGFrZQp1cCB0byAyNCBob3VycyB0byBi
|
||||
ZSBhY2Nlc3NpYmxlIG9ubGluZS4KCuKAoiBQbGVhc2UgcmVtaXQgcGF5bWVudCBhdCB5b3VyIGVh
|
||||
cmxpZXN0IGNvbnZlbmllbmNlIHVubGVzcyBpbnZvaWNlIGlzCm1hcmtlZCDigJxQQUlE4oCdLgri
|
||||
gKIgU29tZSBpdGVtcyBtYXkgc2hpcCBzZXBhcmF0ZWx5IGZyb20gbXVsdGlwbGUgbG9jYXRpb25z
|
||||
LiBTZXBhcmF0ZQppbnZvaWNlcyB3aWxsIGJlIGlzc3VlZCB3aGVuIGFwcGxpY2FibGUuCuKAoiBQ
|
||||
TEVBU0UgSU5TUEVDVCBVUE9OIFJFQ0VJUFQgRk9SIFBBVFRFUk4sIENPTE9SLCBERUZFQ1RTLCBE
|
||||
QU1BR0UgRlJPTQpTSElQUElORywgQ09SUkVDVCBZQVJEQUdFLCBFVEMhIE9uY2UgYW4gb3JkZXIg
|
||||
aXMgY3V0IG9yIHNld24sIG5vIHJldHVybnMKd2lsbCBiZSBhY2NlcHRlZCBmb3IgYW55IHJlYXNv
|
||||
biwgbm8gbWF0dGVyIHRoZSBwYXJ0eSBpbiBlcnJvci4gTm8gcmV0dXJucwp3aWxsIGJlIGF1dGhv
|
||||
cml6ZWQgYWZ0ZXIgMzAgZGF5cyBvZiBpbnZvaWNlIGRhdGUuIE5vIGV4Y2VwdGlvbnMgd2lsbCBi
|
||||
ZQptYWRlLgoKVGhhbmsgeW91ciBmb3IgeW91ciBidXNpbmVzcyEKCk5haWxkb2N0b3IgRmFicmlj
|
||||
cw==
|
||||
|
||||
--cbace12de35ef4eae53fd974ccd41cb2aee4f9c9c76057ec8bfdd0c97813
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
|
||||
PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ImVuIj4KPGJvZHk+CjxwPlRoaXMgaXMgSFRNTCA8
|
||||
c3Ryb25nPmluIEJPTEQ8L3N0cm9uZz4KPHA+ClRoaXMgaXMgYW4gZW1iZWRkZWQgcGljdHVyZTog
|
||||
CjxpbWcgYWx0PSJwaXhlbC5wbmciIHNyYz0iY2lkOmltYWdlMS5wbmciPgo8YnI+Rm9vPC9wPg==
|
||||
|
||||
--cbace12de35ef4eae53fd974ccd41cb2aee4f9c9c76057ec8bfdd0c97813--
|
||||
|
||||
--5897e40a22c608e252cfab849e966112fcbd5a1c291208026b3ca2bfab8a
|
||||
Content-Disposition: inline; filename="pixel.png"
|
||||
Content-Id: image1.png
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Type: image/png; name="pixel.png"
|
||||
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAAAAACoWZBhAAAFEmlUWHRYTUw6Y29tLmFkb2JlLnht
|
||||
cAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQi
|
||||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AAABFJREFUCJljnMoAA0wMNGcCAEQrAKk9oHKhAAAAAElFTkSuQmCC
|
||||
|
||||
--5897e40a22c608e252cfab849e966112fcbd5a1c291208026b3ca2bfab8a--
|
||||
|
||||
--fe785e0384e2607697cc2ecb17cce003003bb7ca9112104f3e8ce727edb5
|
||||
Content-Disposition: attachment; filename="attachment.png"
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Type: image/png; name="attachment.png"
|
||||
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAAAAACoWZBhAAAFEmlUWHRYTUw6Y29tLmFkb2JlLnht
|
||||
cAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQi
|
||||
Pz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUg
|
||||
NS41LjAiPgogPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIy
|
||||
LXJkZi1zeW50YXgtbnMjIj4KICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgeG1s
|
||||
bnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIgogICAgeG1sbnM6cGhvdG9zaG9w
|
||||
PSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIgogICAgeG1sbnM6ZXhpZj0iaHR0
|
||||
cDovL25zLmFkb2JlLmNvbS9leGlmLzEuMC8iCiAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRv
|
||||
YmUuY29tL3RpZmYvMS4wLyIKICAgIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hh
|
||||
cC8xLjAvbW0vIgogICAgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9z
|
||||
VHlwZS9SZX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||
eG1wbWV0YT4KPD94cGFja2V0IGVuZD0iciI/PpwIGG4AAADdaUNDUEdyZXlzY2FsZSBENTAAABiV
|
||||
dVC9CsJAGEul6KCDg4vSoQ+gIIjiKoou6qAVrLiUs/5gq8e1In0v30TwGRycnc0VcRD9IJdwfMmR
|
||||
A4xlIMLIrAPhIVaDSceduws7d0cWFvIow/JEJEfTvoO/87zB0Hyt6az/ez/HXPmRIF+IlpAqJj+I
|
||||
4TmW1EaburR3Jl3qIXUxDE7i7dWvFvzDbEquEBYGUPCRIIKAh4DaRg9N6H6/ffXUN8aRm4KnpFth
|
||||
hw22iFHl7YlpOmedZvtMTfQffXeXnvI+rTKNxguyvDKvB7U4qQAAAAlwSFlzAAALEwAACxMBAJqc
|
||||
GAAAABFJREFUCJljnMoAA0wMNGcCAEQrAKk9oHKhAAAAAElFTkSuQmCC
|
||||
|
||||
--fe785e0384e2607697cc2ecb17cce003003bb7ca9112104f3e8ce727edb5--`
|
||||
)
|
||||
|
||||
func TestEMLToMsgFromString(t *testing.T) {
|
||||
|
@ -562,6 +745,13 @@ func TestEMLToMsgFromStringBrokenTo(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestEMLToMsgFromStringNoBoundary(t *testing.T) {
|
||||
_, err := EMLToMsgFromString(exampleMailPlainB64WithAttachmentNoBoundary)
|
||||
if err == nil {
|
||||
t.Error("EML with no boundary was supposed to fail, but didn't")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEMLToMsgFromStringWithAttachment(t *testing.T) {
|
||||
wantSubject := "Example mail // plain text base64 with attachment"
|
||||
msg, err := EMLToMsgFromString(exampleMailPlainB64WithAttachment)
|
||||
|
@ -590,7 +780,68 @@ func TestEMLToMsgFromStringWithEmbed(t *testing.T) {
|
|||
}
|
||||
if len(msg.embeds) != 1 {
|
||||
t.Errorf("EMLToMsgFromString of EML with embed failed: expected no. of embeds: %d, but got: %d",
|
||||
1, len(msg.attachments))
|
||||
1, len(msg.embeds))
|
||||
}
|
||||
msg, err = EMLToMsgFromString(exampleMailPlainB64WithEmbedNoContentID)
|
||||
if err != nil {
|
||||
t.Errorf("EML with embed failed: %s", err)
|
||||
}
|
||||
if subject := msg.GetGenHeader(HeaderSubject); len(subject) > 0 && !strings.EqualFold(subject[0], wantSubject) {
|
||||
t.Errorf("EMLToMsgFromString of EML with embed failed: expected subject: %s, but got: %s",
|
||||
wantSubject, subject[0])
|
||||
}
|
||||
if len(msg.embeds) != 1 {
|
||||
t.Errorf("EMLToMsgFromString of EML with embed failed: expected no. of embeds: %d, but got: %d",
|
||||
1, len(msg.embeds))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEMLToMsgFromStringMultipartMixedAlternativeRelated(t *testing.T) {
|
||||
wantSubject := "Example mail // plain text base64 with attachment, embed and alternative part"
|
||||
msg, err := EMLToMsgFromString(exampleMailMultipartMixedAlternativeRelated)
|
||||
if err != nil {
|
||||
t.Errorf("EML multipart mixed, related, alternative failed: %s", err)
|
||||
}
|
||||
if subject := msg.GetGenHeader(HeaderSubject); len(subject) > 0 && !strings.EqualFold(subject[0], wantSubject) {
|
||||
t.Errorf("EMLToMsgFromString of EML multipart mixed, related, alternative failed: expected subject: %s,"+
|
||||
" but got: %s", wantSubject, subject[0])
|
||||
}
|
||||
if len(msg.embeds) != 1 {
|
||||
t.Errorf("EMLToMsgFromString of EML multipart mixed, related, alternative failed: expected no. of "+
|
||||
"embeds: %d, but got: %d", 1, len(msg.embeds))
|
||||
}
|
||||
if len(msg.attachments) != 1 {
|
||||
t.Errorf("EMLToMsgFromString of EML multipart mixed, related, alternative failed: expected no. of "+
|
||||
"attachments: %d, but got: %d", 1, len(msg.attachments))
|
||||
}
|
||||
if len(msg.parts) != 3 {
|
||||
t.Errorf("EMLToMsgFromString of EML multipart mixed, related, alternative failed: expected no. of "+
|
||||
"parts: %d, but got: %d", 3, len(msg.parts))
|
||||
}
|
||||
|
||||
var hasPlain, hasHTML, hasAlternative bool
|
||||
for _, part := range msg.parts {
|
||||
if strings.EqualFold(part.contentType.String(), TypeMultipartAlternative.String()) {
|
||||
hasAlternative = true
|
||||
}
|
||||
if strings.EqualFold(part.contentType.String(), TypeTextPlain.String()) {
|
||||
hasPlain = true
|
||||
}
|
||||
if strings.EqualFold(part.contentType.String(), TypeTextHTML.String()) {
|
||||
hasHTML = true
|
||||
}
|
||||
}
|
||||
if !hasPlain {
|
||||
t.Error("EMLToMsgFromString of EML multipart mixed, related, alternative failed: expected PLAIN " +
|
||||
"but got none")
|
||||
}
|
||||
if !hasHTML {
|
||||
t.Error("EMLToMsgFromString of EML multipart mixed, related, alternative failed: expected HTML " +
|
||||
"but got none")
|
||||
}
|
||||
if !hasAlternative {
|
||||
t.Error("EMLToMsgFromString of EML multipart mixed, related, alternative failed: expected Alternative " +
|
||||
"but got none")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue