Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ahmedayob/email-toolkit

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ahmedayob/email-toolkit - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

16

dist/index.d.ts

@@ -145,2 +145,4 @@ import z, { z as z$1 } from 'zod';

}, "strip", z.ZodTypeAny, {
"Content-Type"?: "text/plain" | "text/html" | "application/pdf" | "image/png" | "image/jpeg" | undefined;
"Content-Transfer-Encoding"?: "7bit" | "8bit" | "binary" | "quoted-printable" | "base64" | undefined;
Subject?: string | undefined;

@@ -153,7 +155,7 @@ From?: string | undefined;

"In-Reply-To"?: string | undefined;
"Content-Type"?: "text/plain" | "text/html" | "application/pdf" | "image/png" | "image/jpeg" | undefined;
"Content-Transfer-Encoding"?: "7bit" | "8bit" | "binary" | "base64" | "quoted-printable" | undefined;
"MIME-Version"?: string | undefined;
Charset?: "utf-8" | "utf8" | "utf16le" | "utf-16le" | "latin1" | undefined;
}, {
"Content-Type"?: "text/plain" | "text/html" | "application/pdf" | "image/png" | "image/jpeg" | undefined;
"Content-Transfer-Encoding"?: "7bit" | "8bit" | "binary" | "quoted-printable" | "base64" | undefined;
Subject?: string | undefined;

@@ -166,4 +168,2 @@ From?: string | undefined;

"In-Reply-To"?: string | undefined;
"Content-Type"?: "text/plain" | "text/html" | "application/pdf" | "image/png" | "image/jpeg" | undefined;
"Content-Transfer-Encoding"?: "7bit" | "8bit" | "binary" | "base64" | "quoted-printable" | undefined;
"MIME-Version"?: string | undefined;

@@ -195,7 +195,7 @@ Charset?: "utf-8" | "utf8" | "utf16le" | "utf-16le" | "latin1" | undefined;

"Content-Type"?: "text/plain" | "text/html" | "application/pdf" | "image/png" | "image/jpeg" | undefined;
"Content-Transfer-Encoding"?: "7bit" | "8bit" | "binary" | "base64" | "quoted-printable" | undefined;
"Content-Transfer-Encoding"?: "7bit" | "8bit" | "binary" | "quoted-printable" | "base64" | undefined;
"Content-Disposition"?: string | undefined;
}, {
"Content-Type"?: "text/plain" | "text/html" | "application/pdf" | "image/png" | "image/jpeg" | undefined;
"Content-Transfer-Encoding"?: "7bit" | "8bit" | "binary" | "base64" | "quoted-printable" | undefined;
"Content-Transfer-Encoding"?: "7bit" | "8bit" | "binary" | "quoted-printable" | "base64" | undefined;
"Content-Disposition"?: string | undefined;

@@ -642,3 +642,3 @@ }>;

constructor();
getSignature({ from, url, name }: GetSignatureType): string[];
getSignature({ from, url, name }: GetSignatureType): string;
setSignature({ name, url, }: NonNullableType<Omit<GetSignatureType, "from">>): this;

@@ -875,3 +875,3 @@ }

*/
getSignature({ from, url, name }: GetSignatureType): string[];
getSignature({ from, url, name }: GetSignatureType): string;
/**

@@ -878,0 +878,0 @@ * Sets the signature details for the email.

@@ -260,11 +260,11 @@ "use strict";

].join("\r\n");
const Attachments = attachments?.flatMap((attachment) => {
const Attachments = attachments?.flatMap((attachment2) => {
return [
``,
`--boundary`,
`Content-Type: ${attachment.headers?.["Content-Type"]}`,
`Content-Transfer-Encoding: ${attachment.headers?.["Content-Transfer-Encoding"]}`,
`Content-Disposition: attachment; filename="${attachment.filename}"`,
`Content-Type: ${attachment2.headers?.["Content-Type"]}`,
`Content-Transfer-Encoding: ${attachment2.headers?.["Content-Transfer-Encoding"]}`,
`Content-Disposition: attachment; filename="${attachment2.filename}"`,
``,
attachment.attachmentContent,
attachment2.attachmentContent,
``

@@ -355,10 +355,8 @@ ];

return [
``,
`</div>`,
`<div style="margin: 1rem">`,
`---------------------------------`,
`<p>This email was sent from ${from} by <a style="color: blue" href="${url}" target="_blank">${name}</a> app</p>`,
`<p>This email was sent from ${from} by <a style="color: blue;" href="${url}" target="_blank">${name}</a> app</p>`,
`---------------------------------`,
`</div>`
];
].join("\r\n");
}

@@ -934,2 +932,140 @@ /**

};
// src/EmailBuilderAttachment/EmailBuilderAttachment.ts
var EmailBuilderAttachment = class extends EmailValidator {
/**
* An optional array of attachments to be included in the email.
* It is initialized as `undefined` and populated when attachments are added.
*
* @type {AttachmentType[] | undefined}
*/
attachments;
/**
* The boundary string used to separate different parts of a multipart email.
* Default value is `"boundary"`.
*
* @type {string | undefined}
*/
boundary = "boundary";
/**
* Initializes a new instance of the `EmailBuilderAttachment` class.
* Calls the constructor of the `EmailValidator` class to initialize inherited properties.
*
* @constructor
* @extends EmailValidator
*/
constructor() {
super();
}
/**
* Adds an attachment to the email.
*
* If there are no existing attachments, this method initializes the `attachments` array.
* It then adds the provided attachment to the array.
*
* @param {AttachmentType} attachment - The attachment to be added to the email. This should conform to the `AttachmentType` schema.
* @returns {this} - The current instance of `EmailBuilder` for method chaining, allowing further configuration of the email.
*
* @example
* const emailBuilder = new EmailBuilder();
* emailBuilder.addAttachment({
* filename: "document.pdf",
* content: "<base64-encoded-content>",
* headers: {
* "Content-Type": "application/pdf",
* "Content-Transfer-Encoding": "base64"
* }
* });
*/
addAttachment(attachment2) {
if (!this.attachments) {
this.attachments = [];
}
this.attachments.push(attachment2);
return this;
}
/**
* Generates the MIME parts for all the attachments in the email.
*
* This method constructs and returns an array of strings, each representing a MIME part for an attachment.
* The MIME parts include headers for content type, transfer encoding, and disposition, followed by the attachment content.
* If no attachments are present, the method returns `undefined`.
*
* @returns {string[] | undefined} - An array of MIME part strings for the attachments, or `undefined` if no attachments are present.
*
* @example
* const emailBuilder = new EmailBuilder();
* emailBuilder.addAttachment({
* filename: "document.pdf",
* content: "<base64-encoded-content>",
* headers: {
* "Content-Type": "application/pdf",
* "Content-Transfer-Encoding": "base64",
* "Content-Disposition": "attachment"
* }
* });
*
* const mimeParts = emailBuilder.getAttachment();
* // mimeParts will be an array of strings representing MIME parts for the attachments
*/
getAttachment() {
return this.attachments?.flatMap((attachment2) => {
const { error: attachmentError } = this.isValidAttachment({
"Content-Type": attachment2.headers?.["Content-Type"].split(
";"
)?.[0],
"Content-Disposition": attachment2.headers?.["Content-Disposition"],
"Content-Transfer-Encoding": attachment2.headers?.["Content-Transfer-Encoding"]
});
if (attachmentError) this.logError(attachmentError);
return [
``,
`--${this.boundary}`,
`Content-Type: ${attachment2.headers?.["Content-Type"]}`,
`Content-Transfer-Encoding: ${attachment2.headers?.["Content-Transfer-Encoding"]}`,
`Content-Disposition: attachment; filename="${attachment2.filename}"`,
``,
attachment2.attachmentContent,
``
];
});
}
};
// src/index.ts
var header = new EmailBuilderHeader();
header.setFrom("ahmed <ahmed@gmail.com>").setTo("ahmed <ahmed@gmail.com>").setCc("ahmed <ahmed@gmai.com>").setBcc("ahmed <ahmed@gmai.com>").setSubject("this is wild duck email test subject").setInReplyTo("<ahmed@gmail.com>").setMIMEVersion("1.0").setContentTransferEncoding("quoted-printable").setContentType("text/html").setCharset("utf8");
var 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")
});
var email = new EmailBuilder();
email.setSignature({
name: "ahmed",
url: "https://ahmed.com"
});
email.messagebody = "this is message body";
var finalEmail = email.getRawMessage(header.headers, attachment.attachments);
console.log(finalEmail);
// Annotate the CommonJS export names for ESM import in node:

@@ -936,0 +1072,0 @@ 0 && (module.exports = {

{
"name": "@ahmedayob/email-toolkit",
"version": "0.2.1",
"version": "0.2.2",
"main": "index.js",

@@ -5,0 +5,0 @@ "module": "dist/index.mjs",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc