diff --git a/services/gmail.js b/services/gmail.js index 69189ce..d1d5662 100644 --- a/services/gmail.js +++ b/services/gmail.js @@ -274,8 +274,8 @@ async function sendGmailReply( `Re: ${subject}` ).toString('base64')}?=`; const safeUser = escapeHtml(discordUser); - const safeReply = escapeHtml(replyText).replace(/\n/g, '
'); const safeLogoUrl = escapeHtml(CONFIG.LOGO_URL || ''); + const companySignatureText = (CONFIG.SIGNATURE || '').replace(/
/g, '\n'); // Get staff signature if userId provided let signatureBlocks = { text: '', html: '' }; @@ -283,41 +283,61 @@ async function sendGmailReply( signatureBlocks = await getStaffSignatureBlocks(userId); } - const companySignatureHtml = ` - - - - - -
- ${safeLogoUrl ? `` : ''} - -

${safeUser}

-
${escapeHtml(CONFIG.SIGNATURE || '').replace(/\n/g, '
')}
-
`; + const safeStaffSigHtml = signatureBlocks.html ? signatureBlocks.html.replace(/\n/g, '
') : ''; + const safeStaffSigText = signatureBlocks.text; + const safeCompanySigHtml = escapeHtml(CONFIG.SIGNATURE || '').replace(/\n/g, '
'); const htmlBody = `
-

From: ${safeUser} on Discord

-

${safeReply}

- ${signatureBlocks.html ? `

${signatureBlocks.html.replace(/\n/g, '
')}

` : ''} +

${escapeHtml(replyText).replace(/\n/g, '
')}

+ ${safeStaffSigHtml ? `

${safeStaffSigHtml}

` : ''}
- ${companySignatureHtml} + + + + + +
+ ${safeLogoUrl ? `` : ''} + +

${safeUser}

+
${safeCompanySigHtml}
+
`; - 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}`, `To: ${recipientEmail}`, `Subject: ${utf8Subject}`, messageId ? `In-Reply-To: ${messageId}` : '', messageId ? `References: ${messageId}` : '', '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"', '', - htmlBody - ].filter(Boolean); - - const raw = Buffer.from(headers.join('\r\n')) + htmlBody, + '', + '--' + boundary + '--' + ].join('\r\n')) .toString('base64') .replace(/\+/g, '-') .replace(/\//g, '_')