Created
September 20, 2017 14:51
-
-
Save manjeshpv/48bd0c9c3c468bdececade7998fc1790 to your computer and use it in GitHub Desktop.
webhooks from postal bounced email for mailtrain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/models/links.js b/lib/models/links.js | |
index e7ce559..aabc9ab 100644 | |
--- a/lib/models/links.js | |
+++ b/lib/models/links.js | |
@@ -277,7 +277,7 @@ module.exports.updateLinks = (campaign, list, subscription, serviceUrl, message, | |
if (!campaign.openTrackingDisabled) { | |
let inserted = false; | |
let imgUrl = urllib.resolve(serviceUrl, util.format('/links/%s/%s/%s', campaign.cid, list.cid, encodeURIComponent(subscription.cid))); | |
- let img = '<img src="' + imgUrl + '" width="1" height="1" alt="mt">'; | |
+ let img = '<img src="' + imgUrl + '" width="1" height="1" alt="">'; | |
message = message.replace(/<\/body\b/i, match => { | |
inserted = true; | |
return img + match; | |
diff --git a/routes/webhooks.js b/routes/webhooks.js | |
index 4fa2701..161e7c2 100644 | |
--- a/routes/webhooks.js | |
+++ b/routes/webhooks.js | |
@@ -10,6 +10,7 @@ let multer = require('multer'); | |
let uploads = multer(); | |
router.post('/aws', (req, res, next) => { | |
+ log.verbose('AWS', 'Recieved webhook: %s', JSON.stringify(req.body)); | |
if (typeof req.body === 'string') { | |
try { | |
req.body = JSON.parse(req.body); | |
@@ -18,6 +19,16 @@ router.post('/aws', (req, res, next) => { | |
} | |
} | |
+ if (['MessageBounced', 'MessageDeliveryFailed'].includes(req.body.event)) { | |
+ const message = req.body.payload.original_message || req.body.payload.message; | |
+ req.body.Type = 'Notification'; | |
+ req.body.Message = { | |
+ notificationType: 'Bounce', | |
+ bounce: { bounceType: 'Permanent' }, | |
+ mail: { messageId: '<' +message.message_id+ '>' } | |
+ }; | |
+ } | |
+ | |
switch (req.body.Type) { | |
case 'SubscriptionConfirmation': | |
diff --git a/services/sender.js b/services/sender.js | |
index f04dd48..b106c5e 100644 | |
--- a/services/sender.js | |
+++ b/services/sender.js | |
@@ -515,7 +515,7 @@ let sendLoop = () => { | |
} | |
let status = err ? 2 : 1; | |
- let response = err && (err.response || err.message) || info.response || info.messageId; | |
+ let response = err && (err.response || err.message) || info.messageId || info.response; | |
let responseId = response.split(/\s+/).pop(); | |
db.getConnection((err, connection) => { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment