manual commit 2026-04-10T20:31:52Z

This commit is contained in:
2026-04-10 20:31:52 +00:00
parent cda5019918
commit 785b2e5b8f

View File

@@ -274,8 +274,8 @@ async function sendGmailReply(
`Re: ${subject}` `Re: ${subject}`
).toString('base64')}?=`; ).toString('base64')}?=`;
const safeUser = escapeHtml(discordUser); const safeUser = escapeHtml(discordUser);
const safeReply = escapeHtml(replyText).replace(/\n/g, '<br>');
const safeLogoUrl = escapeHtml(CONFIG.LOGO_URL || ''); const safeLogoUrl = escapeHtml(CONFIG.LOGO_URL || '');
const companySignatureText = (CONFIG.SIGNATURE || '').replace(/<br>/g, '\n');
// Get staff signature if userId provided // Get staff signature if userId provided
let signatureBlocks = { text: '', html: '' }; let signatureBlocks = { text: '', html: '' };
@@ -283,7 +283,15 @@ async function sendGmailReply(
signatureBlocks = await getStaffSignatureBlocks(userId); signatureBlocks = await getStaffSignatureBlocks(userId);
} }
const companySignatureHtml = ` const safeStaffSigHtml = signatureBlocks.html ? signatureBlocks.html.replace(/\n/g, '<br>') : '';
const safeStaffSigText = signatureBlocks.text;
const safeCompanySigHtml = escapeHtml(CONFIG.SIGNATURE || '').replace(/\n/g, '<br>');
const htmlBody = `
<div style="font-family: sans-serif; font-size: 14px; color: #333;">
<p>${escapeHtml(replyText).replace(/\n/g, '<br>')}</p>
${safeStaffSigHtml ? `<p style="margin: 10px 0;">${safeStaffSigHtml}</p>` : ''}
<hr style="border:none; border-top:1px solid #ddd; margin:20px 0;">
<table border="0" cellpadding="0" cellspacing="0"> <table border="0" cellpadding="0" cellspacing="0">
<tr> <tr>
<td style="padding-right: 12px;"> <td style="padding-right: 12px;">
@@ -291,33 +299,45 @@ async function sendGmailReply(
</td> </td>
<td style="border-left: 1px solid #ddd; padding-left: 12px;"> <td style="border-left: 1px solid #ddd; padding-left: 12px;">
<p style="margin: 0; font-weight: bold;">${safeUser}</p> <p style="margin: 0; font-weight: bold;">${safeUser}</p>
<div style="color: #666; font-size: 12px;">${escapeHtml(CONFIG.SIGNATURE || '').replace(/\n/g, '<br>')}</div> <div style="color: #666; font-size: 12px;">${safeCompanySigHtml}</div>
</td> </td>
</tr> </tr>
</table>`; </table>
const htmlBody = `
<div style="font-family: sans-serif; font-size: 14px; color: #333;">
<p><strong>From:</strong> ${safeUser} on Discord</p>
<p>${safeReply}</p>
${signatureBlocks.html ? `<p style="margin: 10px 0;">${signatureBlocks.html.replace(/\n/g, '<br>')}</p>` : ''}
<hr style="border:none; border-top:1px solid #ddd; margin:20px 0;">
${companySignatureHtml}
</div>`; </div>`;
const headers = [ const boundary = `\000000000000${Date.now().toString(16)}`;
const plainBody = [];
plainBody.push(replyText);
if (safeStaffSigText) {
plainBody.push(safeStaffSigText);
}
plainBody.push('');
plainBody.push('------------------------------');
plainBody.push('');
plainBody.push(companySignatureText);
const raw = Buffer.from([
`From: ${CONFIG.MY_EMAIL}`, `From: ${CONFIG.MY_EMAIL}`,
`To: ${recipientEmail}`, `To: ${recipientEmail}`,
`Subject: ${utf8Subject}`, `Subject: ${utf8Subject}`,
messageId ? `In-Reply-To: ${messageId}` : '', messageId ? `In-Reply-To: ${messageId}` : '',
messageId ? `References: ${messageId}` : '', messageId ? `References: ${messageId}` : '',
'MIME-Version: 1.0', 'MIME-Version: 1.0',
'Content-Type: multipart/alternative; boundary="' + boundary + '"',
'',
'--' + boundary,
'Content-Type: text/plain; charset="UTF-8"',
'',
...plainBody,
'',
'--' + boundary,
'Content-Type: text/html; charset="UTF-8"', 'Content-Type: text/html; charset="UTF-8"',
'', '',
htmlBody htmlBody,
].filter(Boolean); '',
'--' + boundary + '--'
const raw = Buffer.from(headers.join('\r\n')) ].join('\r\n'))
.toString('base64') .toString('base64')
.replace(/\+/g, '-') .replace(/\+/g, '-')
.replace(/\//g, '_') .replace(/\//g, '_')