From fb2bf06c2b7cf5e2a83bf15c9f121bf75cf29284 Mon Sep 17 00:00:00 2001 From: wild_duck Date: Fri, 9 Aug 2024 17:40:31 +0300 Subject: [PATCH] chore: fixed the signature context --- src/EmailBuilder/EmailBuilder.ts | 8 +- src/EmailBuilder/EmailBuilder.types.ts | 2 +- .../__test__/EmailBuilder.test.ts | 18 +-- src/index.ts | 107 +++++++++--------- 4 files changed, 67 insertions(+), 68 deletions(-) diff --git a/src/EmailBuilder/EmailBuilder.ts b/src/EmailBuilder/EmailBuilder.ts index c0503d9..7748b38 100644 --- a/src/EmailBuilder/EmailBuilder.ts +++ b/src/EmailBuilder/EmailBuilder.ts @@ -215,16 +215,14 @@ export class EmailBuilder implements EmailBuilderClass { * }); * console.log(signature.join("\n")); */ - public getSignature({ from, url, name }: GetSignatureType): string[] { + public getSignature({ from, url, name }: GetSignatureType): string { return [ - ``, - ``, `
`, `---------------------------------`, - `

This email was sent from ${from} by ${name} app

`, + `

This email was sent from ${from} by ${name} app

`, `---------------------------------`, `
`, - ]; + ].join("\r\n"); } /** diff --git a/src/EmailBuilder/EmailBuilder.types.ts b/src/EmailBuilder/EmailBuilder.types.ts index 5f2d8d8..eecad0d 100644 --- a/src/EmailBuilder/EmailBuilder.types.ts +++ b/src/EmailBuilder/EmailBuilder.types.ts @@ -18,7 +18,7 @@ export type MIMEType = typeof MIMETypes; export declare class EmailBuilderClass { public constructor(); - public getSignature({ from, url, name }: GetSignatureType): string[]; + public getSignature({ from, url, name }: GetSignatureType): string; public setSignature({ name, url, diff --git a/src/EmailBuilder/__test__/EmailBuilder.test.ts b/src/EmailBuilder/__test__/EmailBuilder.test.ts index c0b24d2..ad96949 100644 --- a/src/EmailBuilder/__test__/EmailBuilder.test.ts +++ b/src/EmailBuilder/__test__/EmailBuilder.test.ts @@ -66,15 +66,15 @@ describe("EmailBuilder", () => { name: emailBuilder.applicationSignature.name, }); - expect(signature).toEqual([ - "", - ``, - `
`, - `---------------------------------`, - `

This email was sent from sender@example.com by ${emailBuilder.applicationSignature.name} app

`, - `---------------------------------`, - `
`, - ]); + expect(signature).toEqual( + [ + `
`, + `---------------------------------`, + `

This email was sent from sender@example.com by ${emailBuilder.applicationSignature.name} app

`, + `---------------------------------`, + `
`, + ].join("\r\n") + ); }); it("should include attachments in the raw message", () => { diff --git a/src/index.ts b/src/index.ts index b0e14a9..a8f3316 100755 --- a/src/index.ts +++ b/src/index.ts @@ -6,56 +6,57 @@ export * from "./EmailBuilderAttachment"; export * from "./Error"; export * from "./zod"; -// import { Base64 } from "./Base64"; -// import { EmailBuilderHeader } from "./EmailBiulderHeader"; -// import { EmailBuilder } from "./EmailBuilder"; -// import { EmailBuilderAttachment } from "./EmailBuilderAttachment/EmailBuilderAttachment"; -// const header = new EmailBuilderHeader(); -// header -// .setFrom("ahmed ") -// .setTo("ahmed ") -// .setCc("ahmed ") -// .setBcc("ahmed ") -// .setSubject("this is wild duck email test subject") -// .setInReplyTo("ahmed@gmail.com") -// .setMIMEVersion("1.0") -// .setContentTransferEncoding("quoted-printable") -// .setContentType("text/html") -// .setCharset("utf8"); -// -// const attachment = new EmailBuilderAttachment(); -// attachment.addAttachment({ -// headers: { -// "Content-Type": 'text/plain; charset="utf-8"', -// "Content-Transfer-Encoding": "base64", -// "Content-Disposition": 'attachment; filename="test.txt"', -// }, -// size: 1234, -// filename: "test.txt", -// mimeType: "text/plain", -// attachmentId: "1234", -// attachmentContent: Base64.encodeToBase64("test"), -// }); -// attachment.addAttachment({ -// headers: { -// "Content-Type": 'text/plain; charset="utf-8"', -// "Content-Transfer-Encoding": "base64", -// "Content-Disposition": 'attachment; filename="test.txt"', -// }, -// size: 1234, -// filename: "test.txt", -// mimeType: "text/plain", -// attachmentId: "1234", -// attachmentContent: Base64.encodeToBase64("test"), -// }); -// -// // console.log(header.attachments); -// -// const email = new EmailBuilder(); -// email.messagebody = "this is message body"; -// -// const finalEmail = email.getEncodedMessage( -// header.headers, -// attachment.attachments -// ); -// console.log(finalEmail); +import { Base64 } from "./Base64"; +import { EmailBuilderHeader } from "./EmailBiulderHeader"; +import { EmailBuilder } from "./EmailBuilder"; +import { EmailBuilderAttachment } from "./EmailBuilderAttachment/EmailBuilderAttachment"; +const header = new EmailBuilderHeader(); +header + .setFrom("ahmed ") + .setTo("ahmed ") + .setCc("ahmed ") + .setBcc("ahmed ") + .setSubject("this is wild duck email test subject") + .setInReplyTo("") + .setMIMEVersion("1.0") + .setContentTransferEncoding("quoted-printable") + .setContentType("text/html") + .setCharset("utf8"); + +const attachment = new EmailBuilderAttachment(); +attachment.addAttachment({ + headers: { + "Content-Type": 'text/plain; charset="utf-8"', + "Content-Transfer-Encoding": "base64", + "Content-Disposition": 'attachment; filename="test.txt"', + }, + size: 1234, + filename: "test.txt", + mimeType: "text/plain", + attachmentId: "1234", + attachmentContent: Base64.encodeToBase64("test"), +}); +attachment.addAttachment({ + headers: { + "Content-Type": 'text/plain; charset="utf-8"', + "Content-Transfer-Encoding": "base64", + "Content-Disposition": 'attachment; filename="test.txt"', + }, + size: 1234, + filename: "test.txt", + mimeType: "text/plain", + attachmentId: "1234", + attachmentContent: Base64.encodeToBase64("test"), +}); + +// console.log(header.attachments); + +const email = new EmailBuilder(); +email.setSignature({ + name: "ahmed", + url: "https://ahmed.com", +}); +email.messagebody = "this is message body"; + +const finalEmail = email.getRawMessage(header.headers, attachment.attachments); +console.log(finalEmail);