-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: missing plaintext with inline attachments (#70)
* fix: inline images * test: add text, html with inline attachment test
- Loading branch information
Showing
2 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,7 +193,52 @@ test('generates plain text and html mixed message with an attachment', () => { | |
) | ||
}) | ||
|
||
test('sending only an attachment, without content isn not allowed', async () => { | ||
test('generates plain text and html related message with an inline attachment', () => { | ||
const msg = new MIMEMessage(envctx) | ||
msg.boundaries = {related: 'abcdef', alt: 'qwerty'} | ||
msg.setHeader('Date', 'Wed, 22 Mar 2023 23:36:33 +0000') | ||
msg.setHeader('Message-ID', '<[email protected]>') | ||
msg.setSender('[email protected]') | ||
msg.setSubject('Lorem Ipsum') | ||
msg.addMessage({contentType: 'text/plain', data: 'hello there'}) | ||
msg.addMessage({contentType: 'text/html', data: 'hello there <b>Murat</b>'}) | ||
msg.addAttachment({ | ||
inline: true, | ||
contentType: 'image/jpg', | ||
filename: 'sample.jpg', | ||
data: sampleImageBase64 | ||
}) | ||
|
||
expect(msg.hasInlineAttachments()).toBe(true); | ||
expect(msg.getMessageByType("text/plain")?.data).toBe("hello there") | ||
|
||
expect(msg.asRaw()).toBe('Date: Wed, 22 Mar 2023 23:36:33 +0000' + envctx.eol + | ||
'From: <[email protected]>' + envctx.eol + | ||
'Message-ID: <[email protected]>' + envctx.eol + | ||
'Subject: =?utf-8?B?TG9yZW0gSXBzdW0=?=' + envctx.eol + | ||
'MIME-Version: 1.0' + envctx.eol + | ||
'Content-Type: multipart/related; boundary=abcdef' + envctx.eol + envctx.eol + | ||
'--abcdef' + envctx.eol + | ||
'Content-Type: multipart/alternative; boundary=qwerty' + envctx.eol + envctx.eol + | ||
'--qwerty' + envctx.eol + | ||
'Content-Type: text/plain; charset=UTF-8' + envctx.eol + | ||
'Content-Transfer-Encoding: 7bit' + envctx.eol + envctx.eol + | ||
'hello there' + envctx.eol + envctx.eol + | ||
'--qwerty' + envctx.eol + | ||
'Content-Type: text/html; charset=UTF-8' + envctx.eol + | ||
'Content-Transfer-Encoding: 7bit' + envctx.eol + envctx.eol + | ||
'hello there <b>Murat</b>' + envctx.eol + envctx.eol + | ||
'--qwerty--' + envctx.eol + envctx.eol + | ||
'--abcdef' + envctx.eol + | ||
'Content-Type: image/jpg; name="sample.jpg"' + envctx.eol + | ||
'Content-Transfer-Encoding: base64' + envctx.eol + | ||
'Content-Disposition: inline; filename="sample.jpg"' + envctx.eol + envctx.eol + | ||
sampleImageBase64 + envctx.eol + | ||
'--abcdef--' | ||
) | ||
}) | ||
|
||
test('sending only an attachment, without content is not allowed', async () => { | ||
const msg = new MIMEMessage(envctx) | ||
msg.setHeader('Date', 'Wed, 22 Mar 2023 23:36:33 +0000') | ||
msg.setHeader('Message-ID', '<[email protected]>') | ||
|