修复TG一些邮件解析为空和格式优化
This commit is contained in:
@@ -20,7 +20,7 @@ const zh = {
|
|||||||
daySendLack: '当日剩余发送次数不足',
|
daySendLack: '当日剩余发送次数不足',
|
||||||
totalSendLack: '剩余发送次数不足',
|
totalSendLack: '剩余发送次数不足',
|
||||||
senderAccountNotExist: '发件人邮箱不存在',
|
senderAccountNotExist: '发件人邮箱不存在',
|
||||||
noResendToken: 'resend密钥未配置',
|
noResendToken: 'Resend未配置,只能给站内邮箱发件',
|
||||||
sendEmailNotCurUser: '发件人邮箱非当前用户所有',
|
sendEmailNotCurUser: '发件人邮箱非当前用户所有',
|
||||||
notExistEmailReply: '邮件不存在无法回复',
|
notExistEmailReply: '邮件不存在无法回复',
|
||||||
imageAttLimit: '图片不能超过10个',
|
imageAttLimit: '图片不能超过10个',
|
||||||
|
|||||||
@@ -77,10 +77,10 @@ const telegramService = {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
console.error(`转发 Telegram 失败: chatId=${chatId}, 状态码=${res.status}`);
|
console.error(`转发 Telegram 失败 status: ${res.status} response: ${await res.text()}`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} 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') {
|
if (tgMsgFrom === 'only-name') {
|
||||||
template += `
|
template += `
|
||||||
|
|
||||||
发件人:${email.name}`
|
From\u200B:${email.name}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tgMsgFrom === 'show') {
|
if (tgMsgFrom === 'show') {
|
||||||
template += `
|
template += `
|
||||||
|
|
||||||
发件人:${email.name} <${email.sendEmail}>`
|
From\u200B:${email.name} <${email.sendEmail}>`
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tgMsgTo === 'show' && tgMsgFrom === 'hide') {
|
if(tgMsgTo === 'show' && tgMsgFrom === 'hide') {
|
||||||
template += `
|
template += `
|
||||||
|
|
||||||
收件人:\u200B${email.toEmail}`
|
To:\u200B${email.toEmail}`
|
||||||
|
|
||||||
} else if(tgMsgTo === 'show') {
|
} else if(tgMsgTo === 'show') {
|
||||||
template += `
|
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, '<')
|
||||||
.replace(/>/g, '>');
|
.replace(/>/g, '>');
|
||||||
|
|
||||||
|
|||||||
@@ -14,13 +14,30 @@ const emailUtils = {
|
|||||||
return parts.length === 2 ? parts[0] : '';
|
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) {
|
htmlToText(content) {
|
||||||
if (!content) return ''
|
if (!content) return ''
|
||||||
try {
|
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());
|
document.querySelectorAll('style, script, title').forEach(el => el.remove());
|
||||||
let text = document.body.innerText;
|
let text = document.body.innerText;
|
||||||
return text.trim();
|
return this.formatText(text);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
return ''
|
return ''
|
||||||
|
|||||||
Reference in New Issue
Block a user