mirror of
https://github.com/eoao/cloud-mail.git
synced 2026-05-06 13:41:43 +08:00
修复TG一些邮件解析为空和格式优化
This commit is contained in:
@@ -20,7 +20,7 @@ const zh = {
|
||||
daySendLack: '当日剩余发送次数不足',
|
||||
totalSendLack: '剩余发送次数不足',
|
||||
senderAccountNotExist: '发件人邮箱不存在',
|
||||
noResendToken: 'resend密钥未配置',
|
||||
noResendToken: 'Resend未配置,只能给站内邮箱发件',
|
||||
sendEmailNotCurUser: '发件人邮箱非当前用户所有',
|
||||
notExistEmailReply: '邮件不存在无法回复',
|
||||
imageAttLimit: '图片不能超过10个',
|
||||
|
||||
@@ -77,10 +77,10 @@ const telegramService = {
|
||||
})
|
||||
});
|
||||
if (!res.ok) {
|
||||
console.error(`转发 Telegram 失败: chatId=${chatId}, 状态码=${res.status}`);
|
||||
console.error(`转发 Telegram 失败 status: ${res.status} response: ${await res.text()}`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`转发 Telegram 失败: chatId=${chatId}`, e.message);
|
||||
console.error(`转发 Telegram 失败:`, e.message);
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
@@ -7,26 +7,26 @@ export default function emailMsgTemplate(email, tgMsgTo, tgMsgFrom, tgMsgText) {
|
||||
if (tgMsgFrom === 'only-name') {
|
||||
template += `
|
||||
|
||||
发件人:${email.name}`
|
||||
From\u200B:${email.name}`
|
||||
}
|
||||
|
||||
if (tgMsgFrom === 'show') {
|
||||
template += `
|
||||
|
||||
发件人:${email.name} <${email.sendEmail}>`
|
||||
From\u200B:${email.name} <${email.sendEmail}>`
|
||||
}
|
||||
|
||||
if(tgMsgTo === 'show' && tgMsgFrom === 'hide') {
|
||||
template += `
|
||||
|
||||
收件人:\u200B${email.toEmail}`
|
||||
To:\u200B${email.toEmail}`
|
||||
|
||||
} else if(tgMsgTo === 'show') {
|
||||
template += `
|
||||
收件人:\u200B${email.toEmail}`
|
||||
To:\u200B${email.toEmail}`
|
||||
}
|
||||
|
||||
const text = (email.text || emailUtils.htmlToText(email.content))
|
||||
const text = (emailUtils.formatText(email.text) || emailUtils.htmlToText(email.content))
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
|
||||
|
||||
@@ -14,13 +14,30 @@ const emailUtils = {
|
||||
return parts.length === 2 ? parts[0] : '';
|
||||
},
|
||||
|
||||
formatText(text) {
|
||||
if (!text) return ''
|
||||
return text
|
||||
.split('\n')
|
||||
.map(line => {
|
||||
return line.replace(/[\u200B-\u200F\uFEFF\u034F\u200B-\u200F\u00A0\u3000\u00AD]/g, '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
})
|
||||
.join('\n')
|
||||
.replace(/\n{3,}/g, '\n')
|
||||
.trim();
|
||||
},
|
||||
|
||||
htmlToText(content) {
|
||||
if (!content) return ''
|
||||
try {
|
||||
const { document } = parseHTML(content);
|
||||
const wrappedContent = content.includes('<body')
|
||||
? content
|
||||
: `<!DOCTYPE html><html><body>${content}</body></html>`;
|
||||
const { document } = parseHTML(wrappedContent);
|
||||
document.querySelectorAll('style, script, title').forEach(el => el.remove());
|
||||
let text = document.body.innerText;
|
||||
return text.trim();
|
||||
return this.formatText(text);
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return ''
|
||||
|
||||
Reference in New Issue
Block a user