-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add test for attachments * fix tests * compare text * upgrade deps * fix encoding LB * add better test case * trim all strings * fix lb * add binary attachment test * fix file path * fix fmt * ff * add more tests * encode all non text attachment to base64
- Loading branch information
Showing
8 changed files
with
181 additions
and
24 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
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
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
export { | ||
BufReader, | ||
BufWriter, | ||
} from "https://deno.land/[email protected]/io/buffer.ts"; | ||
export { TextProtoReader } from "https://deno.land/[email protected]/textproto/mod.ts"; | ||
export { decode as base64Decode } from "https://deno.land/[email protected]/encoding/base64.ts"; | ||
} from "https://deno.land/[email protected]/io/buffer.ts"; | ||
export { TextProtoReader } from "https://deno.land/[email protected]/textproto/mod.ts"; | ||
export { | ||
decode as base64Decode, | ||
encode as base64Encode, | ||
} from "https://deno.land/[email protected]/encoding/base64.ts"; |
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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { clearEmails, getEmails } from "../fake-smtp.ts"; | ||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { SMTPClient } from "../../mod.ts"; | ||
|
||
function wait(to = 10000) { | ||
return new Promise((res) => setTimeout(res, to)); | ||
} | ||
|
||
Deno.test("test text attachment", async () => { | ||
await clearEmails(); | ||
|
||
const client = new SMTPClient({ | ||
debug: { | ||
allowUnsecure: true, | ||
// log: true, | ||
noStartTLS: true, | ||
}, | ||
connection: { | ||
hostname: "localhost", | ||
port: 1025, | ||
tls: false, | ||
}, | ||
}); | ||
|
||
const content = "A\r\nHello\nWorld\rjmjkjj"; | ||
|
||
await client.send({ | ||
from: "[email protected]", | ||
to: "[email protected]", | ||
subject: "testing", | ||
content: "test", | ||
attachments: [ | ||
{ | ||
content, | ||
filename: "text.txt", | ||
encoding: "text", | ||
contentType: "text/plain", | ||
}, | ||
], | ||
}); | ||
|
||
const mails = await getEmails(); | ||
const data = new Uint8Array(mails[0].attachments[0].content.data); | ||
assertEquals(new TextDecoder().decode(data).trim(), content.trim()); | ||
await client.close(); | ||
}); | ||
|
||
Deno.test("test binary attachment", async () => { | ||
await clearEmails(); | ||
|
||
const client = new SMTPClient({ | ||
debug: { | ||
allowUnsecure: true, | ||
// log: true, | ||
noStartTLS: true, | ||
}, | ||
connection: { | ||
hostname: "localhost", | ||
port: 1025, | ||
tls: false, | ||
}, | ||
}); | ||
|
||
const content = await Deno.readFile( | ||
Deno.cwd() + "/test/e2e/attachments/image.png", | ||
); | ||
|
||
await client.send({ | ||
from: "[email protected]", | ||
to: "[email protected]", | ||
subject: "testing", | ||
content: "test", | ||
attachments: [ | ||
{ | ||
content, | ||
filename: "text.txt", | ||
encoding: "binary", | ||
contentType: "image/png", | ||
}, | ||
], | ||
}); | ||
|
||
await wait(2000); | ||
|
||
const mails = await getEmails(); | ||
const data = new Uint8Array(mails[0].attachments[0].content.data); | ||
assertEquals(data, content); | ||
await client.close(); | ||
}); | ||
|
||
Deno.test("test more text attachment", async () => { | ||
await clearEmails(); | ||
|
||
const client = new SMTPClient({ | ||
debug: { | ||
allowUnsecure: true, | ||
// log: true, | ||
noStartTLS: true, | ||
}, | ||
connection: { | ||
hostname: "localhost", | ||
port: 1025, | ||
tls: false, | ||
}, | ||
}); | ||
|
||
const content = [ | ||
"abc\ndef\nghi", | ||
"abc\rdef\rghi", | ||
"abc\ndef\rghi", | ||
"abc\rdef\ndhi", | ||
]; | ||
|
||
for (let i = 0; i < content.length; i++) { | ||
await client.send({ | ||
from: "[email protected]", | ||
to: "[email protected]", | ||
subject: "testing", | ||
content: "test", | ||
attachments: [ | ||
{ | ||
content: content[i], | ||
filename: "text.txt", | ||
encoding: "text", | ||
contentType: "text/plain", | ||
}, | ||
], | ||
}); | ||
|
||
const mails = await getEmails(); | ||
const data = new Uint8Array(mails[0].attachments[0].content.data); | ||
assertEquals(new TextDecoder().decode(data).trim(), content[i].trim()); | ||
} | ||
await client.close(); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hello World! | ||
With LB! |