@stacksjs/email 0.74.29 → 0.74.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import PostalMime from"postal-mime";import{inboundMailboxRecipient}from"./inbox-mailbox";import{inboxAttachmentContentType}from"./sdk/inbox-attachments";export{inboundMailboxRecipient}from"./inbox-mailbox";const MAX_RAW_EMAIL_BYTES=52428800,MAX_ATTACHMENTS=1000;function flattenAddresses(addresses){return(addresses||[]).flatMap((address)=>{if("group"in address&&Array.isArray(address.group))return address.group;return[address]})}function mailbox(address){if(!address)return;if("group"in address&&Array.isArray(address.group))return address.group[0];return address}export function inboundAttachmentName(filename,index){return String(filename||"").replace(/[\u0000-\u001F\u007F]/g,"").replace(/[\\/]/g,"_").trim().slice(0,220)||`attachment-${index+1}`}export function inboundAttachmentStorageName(filename,index){return`stacks-${String(index+1).padStart(4,"0")}--${encodeURIComponent(filename)}`}export function inboundMessageStorageId(messageId){const normalized=messageId.replace(/[\u0000-\u001F\u007F\\/]/g,"_").trim().slice(0,240);if(!normalized||normalized==="."||normalized==="..")throw TypeError("Inbound email object has no safe message identifier.");return normalized}export async function parseInboundEmail(rawEmail){if((typeof rawEmail==="string"?Buffer.byteLength(rawEmail):rawEmail.byteLength)>MAX_RAW_EMAIL_BYTES)throw RangeError(`Raw email exceeds the ${MAX_RAW_EMAIL_BYTES} byte parsing limit.`);const parsed=await PostalMime.parse(rawEmail,{attachmentEncoding:"arraybuffer",maxHeadersSize:524288,maxNestingDepth:64,maxRfc822NestingDepth:4});if(parsed.attachments.length>MAX_ATTACHMENTS)throw RangeError(`Email contains more than ${MAX_ATTACHMENTS} attachments.`);const sender=mailbox(parsed.from),recipients=flattenAddresses(parsed.to).map((recipient)=>recipient.address?.trim().toLowerCase()).filter((address)=>Boolean(address));if(parsed.deliveredTo)recipients.push(parsed.deliveredTo.trim().toLowerCase());const attachments=parsed.attachments.map((attachment,index)=>{const name=inboundAttachmentName(attachment.filename,index),content=typeof attachment.content==="string"?new TextEncoder().encode(attachment.content):new Uint8Array(attachment.content);return{name,storageName:inboundAttachmentStorageName(name,index),contentType:inboxAttachmentContentType(attachment.mimeType),content,...attachment.contentId?{contentId:attachment.contentId}:{},...attachment.disposition?{disposition:attachment.disposition}:{}}});return{from:sender?.address?.trim().toLowerCase()||"",fromName:sender?.name?.trim()||"",recipients:[...new Set(recipients)],subject:parsed.subject?.trim()||"No Subject",...parsed.date?{date:parsed.date}:{},html:parsed.html?.trim()||"",text:parsed.text?.trim()||"",attachments}}
1
+ import{MimeParser}from"@stacksjs/mail/mime";import{inboundMailboxRecipient}from"./inbox-mailbox";import{inboxAttachmentContentType}from"./sdk/inbox-attachments";export{inboundMailboxRecipient}from"./inbox-mailbox";const MAX_RAW_EMAIL_BYTES=52428800,MAX_ATTACHMENTS=1000;function flattenAddresses(addresses){return(addresses||[]).flatMap((address)=>{if("group"in address&&Array.isArray(address.group))return address.group;return[address]})}function mailbox(address){if(!address)return;if("group"in address&&Array.isArray(address.group))return address.group[0];return address}export function inboundAttachmentName(filename,index){return String(filename||"").replace(/[\u0000-\u001F\u007F]/g,"").replace(/[\\/]/g,"_").trim().slice(0,220)||`attachment-${index+1}`}export function inboundAttachmentStorageName(filename,index){return`stacks-${String(index+1).padStart(4,"0")}--${encodeURIComponent(filename)}`}export function inboundMessageStorageId(messageId){const normalized=messageId.replace(/[\u0000-\u001F\u007F\\/]/g,"_").trim().slice(0,240);if(!normalized||normalized==="."||normalized==="..")throw TypeError("Inbound email object has no safe message identifier.");return normalized}export async function parseInboundEmail(rawEmail){if((typeof rawEmail==="string"?Buffer.byteLength(rawEmail):rawEmail.byteLength)>MAX_RAW_EMAIL_BYTES)throw RangeError(`Raw email exceeds the ${MAX_RAW_EMAIL_BYTES} byte parsing limit.`);const parsed=await MimeParser.parse(rawEmail,{attachmentEncoding:"arraybuffer",maxHeadersSize:524288,maxNestingDepth:64,maxRfc822NestingDepth:4});if(parsed.attachments.length>MAX_ATTACHMENTS)throw RangeError(`Email contains more than ${MAX_ATTACHMENTS} attachments.`);const sender=mailbox(parsed.from),recipients=flattenAddresses(parsed.to).map((recipient)=>recipient.address?.trim().toLowerCase()).filter((address)=>Boolean(address));if(parsed.deliveredTo)recipients.push(parsed.deliveredTo.trim().toLowerCase());const attachments=parsed.attachments.map((attachment,index)=>{const name=inboundAttachmentName(attachment.filename,index),content=typeof attachment.content==="string"?new TextEncoder().encode(attachment.content):new Uint8Array(attachment.content);return{name,storageName:inboundAttachmentStorageName(name,index),contentType:inboxAttachmentContentType(attachment.mimeType),content,...attachment.contentId?{contentId:attachment.contentId}:{},...attachment.disposition?{disposition:attachment.disposition}:{}}});return{from:sender?.address?.trim().toLowerCase()||"",fromName:sender?.name?.trim()||"",recipients:[...new Set(recipients)],subject:parsed.subject?.trim()||"No Subject",...parsed.date?{date:parsed.date}:{},html:parsed.html?.trim()||"",text:parsed.text?.trim()||"",attachments}}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/email",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.74.29",
5
+ "version": "0.74.31",
6
6
  "description": "The Stacks Email integration. Painlessly create & manage your inboxes, templates, and send emails.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -61,26 +61,26 @@
61
61
  "prepublishOnly": "bun run build"
62
62
  },
63
63
  "dependencies": {
64
- "@stacksjs/config": "0.74.29",
65
- "@stacksjs/database": "0.74.29",
66
- "@stacksjs/events": "0.74.29",
67
- "@stacksjs/logging": "0.74.29",
68
- "@stacksjs/path": "0.74.29",
69
- "@stacksjs/storage": "0.74.29",
70
- "@stacksjs/strings": "0.74.29",
64
+ "@stacksjs/config": "0.74.31",
65
+ "@stacksjs/database": "0.74.31",
66
+ "@stacksjs/events": "0.74.31",
67
+ "@stacksjs/logging": "0.74.31",
68
+ "@stacksjs/mail": "^0.3.6",
69
+ "@stacksjs/path": "0.74.31",
70
+ "@stacksjs/storage": "0.74.31",
71
+ "@stacksjs/strings": "0.74.31",
71
72
  "@stacksjs/stx": "^0.2.274",
72
73
  "@stacksjs/ts-cloud": "^0.12.15",
73
- "@stacksjs/utils": "0.74.29",
74
- "postal-mime": "^2.7.6"
74
+ "@stacksjs/utils": "0.74.31"
75
75
  },
76
76
  "devDependencies": {
77
- "@stacksjs/cli": "0.74.29",
78
- "@stacksjs/error-handling": "0.74.29",
79
- "@stacksjs/types": "0.74.29",
77
+ "@stacksjs/cli": "0.74.31",
78
+ "@stacksjs/error-handling": "0.74.31",
79
+ "@stacksjs/types": "0.74.31",
80
80
  "better-dx": "^0.2.24"
81
81
  },
82
82
  "peerDependencies": {
83
- "@stacksjs/queue": "0.74.29"
83
+ "@stacksjs/queue": "0.74.31"
84
84
  },
85
85
  "peerDependenciesMeta": {
86
86
  "@stacksjs/queue": {