Skip to content

Commit

Permalink
fix: strip html from error bounce messages
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Aug 30, 2023
1 parent ec5ca82 commit 1429f92
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion helpers/create-bounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const MimeNode = require('nodemailer/lib/mime-node');
const _ = require('lodash');
const ip = require('ip');
const isFQDN = require('is-fqdn');
const { convert } = require('html-to-text');

const getErrorCode = require('#helpers/get-error-code');
const getDiagnosticCode = require('#helpers/get-diagnostic-code');
Expand Down Expand Up @@ -50,6 +51,18 @@ function createBounce(email, error, message) {
rootNode.setHeader('References', email.messageId);
rootNode.setHeader('X-Original-Message-ID', email.messageId);

const response = convert(error.response || error.message, {
wordwrap: false,
selectors: [
{ selector: 'img', format: 'skip' },
{ selector: 'ul', options: { itemPrefix: ' ' } },
{
selector: 'a',
options: { baseUrl: config.urls.web, linkBrackets: false }
}
]
});

rootNode
.createChild('text/plain; charset=utf-8')
.setHeader('Content-Description', 'Notification')
Expand All @@ -63,7 +76,7 @@ function createBounce(email, error, message) {
'',
'The response was:',
'',
error.response || error.message
response
].join('\n')
);

Expand Down

0 comments on commit 1429f92

Please sign in to comment.