fix: update Cloudflare email sending default status

This commit is contained in:
eoao
2026-05-10 18:36:22 +08:00
parent fdf4259701
commit e68099edb3

View File

@@ -311,7 +311,7 @@ const emailService = {
emailData.content = html; emailData.content = html;
emailData.text = text; emailData.text = text;
emailData.accountId = accountId; emailData.accountId = accountId;
emailData.status = emailConst.status.SENT; emailData.status = useCloudflareEmail ? emailConst.status.DELIVERED : emailConst.status.SENT;
emailData.type = emailConst.type.SEND; emailData.type = emailConst.type.SEND;
emailData.userId = userId; emailData.userId = userId;
emailData.resendEmailId = data?.id; emailData.resendEmailId = data?.id;
@@ -402,7 +402,7 @@ const emailService = {
}; };
} }
console.log(sendForm) console.error(sendForm)
const result = await c.env.email.send(sendForm); const result = await c.env.email.send(sendForm);
@@ -422,7 +422,7 @@ const emailService = {
subject: params.subject, subject: params.subject,
text: params.text, text: params.text,
html: params.html, html: params.html,
attachments: await this.toArrayBufferAttachments(params.attachments) attachments: await this.toResendAttachments(params.attachments)
}; };
if (params.sendType === 'reply') { if (params.sendType === 'reply') {
@@ -454,6 +454,25 @@ const emailService = {
}); });
}, },
async toResendAttachments(attachments = []) {
const result = [];
for (const attachment of attachments) {
const content = await this.toAttachmentBase64(attachment);
if (!content) {
continue;
}
result.push({
...attachment,
content,
contentType: attachment.contentType || attachment.mimeType || attachment.type || 'application/octet-stream'
});
}
return result;
},
async toArrayBufferAttachments(attachments = []) { async toArrayBufferAttachments(attachments = []) {
const result = []; const result = [];
@@ -469,6 +488,35 @@ const emailService = {
return result; return result;
}, },
async toAttachmentBase64(attachment) {
let content = attachment.content;
if (!content) {
return null;
}
if (typeof content === 'string') {
if (content.startsWith('data:')) {
content = content.split(',')[1] || content;
}
return content.replace(/\s+/g, '');
}
const arrayBuffer = await this.toAttachmentArrayBuffer(attachment);
if (!arrayBuffer) {
return null;
}
const bytes = new Uint8Array(arrayBuffer);
let binary = '';
for (let i = 0; i < bytes.length; i += 0x8000) {
binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
}
return btoa(binary);
},
async toAttachmentArrayBuffer(attachment) { async toAttachmentArrayBuffer(attachment) {
let content = attachment.content; let content = attachment.content;