Skip to content

Commit

Permalink
v1.7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed May 3, 2018
1 parent a2e3b98 commit 17dddf4
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 81 deletions.
8 changes: 1 addition & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

module.exports = {
rules: {
indent: [
2,
4,
{
SwitchCase: 1
}
],
indent: 0,
quotes: [2, 'single'],
'linebreak-style': [2, 'unix'],
semi: [2, 'always'],
Expand Down
3 changes: 3 additions & 0 deletions config/bounces.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@
# 553 5.3.0 flph825 DNSBL:ATTRBL 521< 1.2.3.4 >_is_blocked.For assistance forward this email to abuse@example.com
^553[ \-]+5\.3\.0[ \-]+.*DNSBL:ATTRBL 5\d\d,defer,blacklist,Sender IP blacklisted

# 554-mx.example.com Your access to this mail system has been rejected due to the sending MTA's poor reputation. If you believe that this failure is in error, please contact the intended recipient
^554[ \-].*Your access to this mail system has been rejected due to the sending MTA's poor reputation,defer,blacklist,Sender IP blacklisted

# Hotmail error messages
# https://mail.live.com/mail/troubleshooting.aspx
^421[ \-]+RP\-00\d,slowdown,rate,Rate limit exceeded
Expand Down
2 changes: 1 addition & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = {

// Make sure messages have all required headers like Date or Message-ID
'core/default-headers': {
enabled: ['receiver', 'main', 'sender'],
enabled: ['*'],

// which interfaces to allow using routing headers like X-Sending-Zone
allowRoutingHeaders: ['api', 'bounce'],
Expand Down
26 changes: 14 additions & 12 deletions lib/mail-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const config = require('wild-config');
const log = require('npmlog');
const remotelog = require('./remotelog');
const MessageParser = require('./message-parser');
const PassThrough = require('stream').PassThrough;
const DkimRelaxedBody = require('./dkim-relaxed-body');
Expand Down Expand Up @@ -71,13 +70,16 @@ class MailDrop {
message.onHeaders = (headers, next) => {
envelope.headers = headers;

headers.getDecoded('received').reverse().find(header => {
let match = (header.value || '').match(/\(Authenticated sender:\s*([^)]+)\)/i);
if (match) {
messageInfo.auth = match[1];
return true;
}
});
headers
.getDecoded('received')
.reverse()
.find(header => {
let match = (header.value || '').match(/\(Authenticated sender:\s*([^)]+)\)/i);
if (match) {
messageInfo.auth = match[1];
return true;
}
});

let subject = envelope.headers.getFirst('subject');
try {
Expand Down Expand Up @@ -175,7 +177,7 @@ class MailDrop {
}
});
keys.error = err.message;
remotelog(id, false, 'NOQUEUE', keys);
plugins.handler.remotelog(id, false, 'NOQUEUE', keys);
return this.queue.removeMessage(id, () => callback(err));
}
return callback(err);
Expand All @@ -200,7 +202,7 @@ class MailDrop {
}
});
keys.error = err.message;
remotelog(id, false, 'NOQUEUE', keys);
plugins.handler.remotelog(id, false, 'NOQUEUE', keys);
return this.queue.removeMessage(id, () => callback(err));
}

Expand All @@ -215,11 +217,11 @@ class MailDrop {
if (err) {
log.error('Queue/' + process.pid, '%s NOQUEUE push "%s" (%s)', id, err.message, messageInfo.format());
keys.error = err.message;
remotelog(id, false, 'NOQUEUE', keys);
plugins.handler.remotelog(id, false, 'NOQUEUE', keys);
return this.queue.removeMessage(id, () => callback(err));
}
log.info('Queue/' + process.pid, '%s QUEUED (%s)', id, messageInfo.format());
remotelog(id, false, 'QUEUED', keys);
plugins.handler.remotelog(id, false, 'QUEUED', keys);
return setImmediate(() => callback(null, 'Message queued as ' + id));
});
});
Expand Down
7 changes: 3 additions & 4 deletions lib/mail-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const plugins = require('./plugins');
const db = require('./db');
const GridFSBucket = require('mongodb').GridFSBucket;
const internalCounters = require('./counters');
const remotelog = require('./remotelog');
const yaml = require('js-yaml');
const fs = require('fs');
const pathlib = require('path');
Expand Down Expand Up @@ -469,7 +468,7 @@ class MailQueue {
},
() => {
this.locks.release(delivery._lock);
remotelog(delivery.id, false, 'DELETED', {
plugins.handler.remotelog(delivery.id, false, 'DELETED', {
reason: 'Not found from GridStore'
});
// try to find another delivery
Expand Down Expand Up @@ -531,7 +530,7 @@ class MailQueue {
suppressvalue = suppressed.domain;
}

remotelog(delivery.id, delivery.seq, 'DROP', {
plugins.handler.remotelog(delivery.id, delivery.seq, 'DROP', {
reason: 'Recipient was found from suppression list',
recipient: delivery.recipient,
[suppresskey]: suppressvalue
Expand Down Expand Up @@ -609,7 +608,7 @@ class MailQueue {
log.error('Delete', '%s.%s DELERROR %s', delivery.id, delivery.seq, err.message);
} else {
log.info('Delete', '%s.%s DELSUCCESS Delivery entry deleted', delivery.id, delivery.seq);
remotelog(delivery.id, delivery.seq, 'DELETED', {
plugins.handler.remotelog(delivery.id, delivery.seq, 'DELETED', {
reason: 'Deletion requested from API'
});
}
Expand Down
73 changes: 61 additions & 12 deletions lib/plugin-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const log = require('npmlog');
const mailsplit = require('mailsplit');
const PassThrough = require('stream').PassThrough;
const addressTools = require('./address-tools');
const remotelog = require('./remotelog');
const db = require('./db');
const config = require('wild-config');
const dgram = require('dgram');
const msgpack = require('msgpack-js');

class PluginInstance {
constructor(manager, options) {
Expand Down Expand Up @@ -91,7 +93,7 @@ class PluginInstance {
}
});

remotelog(id, false, 'DROP', keys);
this.manager.remotelog(id, false, 'DROP', keys);

let msg = '%s DROP' + (description ? '[' + description + ']' : '') + (messageInfo ? ' (' + messageInfo + ')' : '');
this.logger.info(this.options.title, msg, id);
Expand Down Expand Up @@ -141,7 +143,7 @@ class PluginInstance {
}
});

remotelog(id, false, 'NOQUEUE', keys);
this.manager.remotelog(id, false, 'NOQUEUE', keys);

let msg = '%s NOQUEUE' + (description ? '[' + description + ']' : '') + (messageInfo ? ' (' + messageInfo + ')' : '');
this.logger.info(this.options.title, msg, id);
Expand All @@ -157,8 +159,8 @@ class PluginInstance {
return err;
}

remotelog(id, seq, action, keys) {
remotelog(id, seq, action, keys);
remotelog(id, seq, action, data) {
this.manager.remotelog(id, seq, action, data);
}
}

Expand Down Expand Up @@ -270,19 +272,27 @@ class PluginHandler {
pluginData[key] !== true
? pluginData[key]
: {
enabled: true,
ordering: Infinity
};
enabled: true,
ordering: Infinity
};

// Only load plugins with correct context. If context is not set then default to "main"
let allowedContext = [].concat(pluginConfig.enabled || 'receiver').map(context => {
if (context === true) {
return '*';
}

if (typeof context !== 'string') {
return 'receiver';
}
return context.toString().toLowerCase().trim();

return context
.toString()
.toLowerCase()
.trim();
});

if (!allowedContext.includes(this.context)) {
if (!allowedContext.includes(this.context) && !allowedContext.includes('*')) {
return;
}

Expand All @@ -298,7 +308,10 @@ class PluginHandler {
}

addHook(title, name, action) {
name = (name || '').toString().toLowerCase().trim();
name = (name || '')
.toString()
.toLowerCase()
.trim();
let hook = {
title,
name,
Expand Down Expand Up @@ -386,7 +399,10 @@ class PluginHandler {
}

runHooks(name, args, done) {
name = (name || '').toString().toLowerCase().trim();
name = (name || '')
.toString()
.toLowerCase()
.trim();
let hooks = this.hooks.get(name) || [];
let pos = 0;

Expand Down Expand Up @@ -415,6 +431,39 @@ class PluginHandler {
};
setImmediate(checkNext);
}

remotelog(id, seq, action, data) {
let entry = {
id
};
if (seq) {
entry.seq = seq;
}
if (action) {
entry.action = action;
}
if (data) {
Object.keys(data).forEach(key => {
if (!(key in entry)) {
entry[key] = data[key];
}
});
}

if (config.log.remote) {
let payload;
try {
payload = msgpack.encode(entry);
} catch (E) {
log.error('REMOTELOG', '%s Failed encoding message. error="%s"', id + (seq ? '.' + seq : ''), E.message);
}

let client = dgram.createSocket(config.log.remote.protocol);
client.send(payload, config.log.remote.port, config.log.remote.host || 'localhost', () => client.close());
}

this.runHooks('log:entry', [entry], () => false);
}
}

module.exports = PluginHandler;
40 changes: 0 additions & 40 deletions lib/remotelog.js

This file was deleted.

7 changes: 3 additions & 4 deletions lib/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const log = require('npmlog');
const net = require('net');
const crypto = require('crypto');
const request = require('request');
const remotelog = require('./remotelog');
const os = require('os');
const bounces = require('./bounces');
const Headers = require('mailsplit').Headers;
Expand Down Expand Up @@ -510,7 +509,7 @@ class Sender extends EventEmitter {
bounces.formatSMTPResponse(info.response)
);

remotelog(delivery.id, delivery.seq, 'ACCEPTED', {
plugins.handler.remotelog(delivery.id, delivery.seq, 'ACCEPTED', {
zone: this.zone.name,
from: delivery.from,
returnPath: (delivery.envelope && delivery.envelope.from) || delivery.from,
Expand Down Expand Up @@ -598,7 +597,7 @@ class Sender extends EventEmitter {
smtpResponse
);

remotelog(delivery.id, delivery.seq, 'DEFERRED', {
plugins.handler.remotelog(delivery.id, delivery.seq, 'DEFERRED', {
category: bounce.category,
defcount: deferredCount + 1,
nextattempt: Date.now() + ttl,
Expand Down Expand Up @@ -644,7 +643,7 @@ class Sender extends EventEmitter {
smtpResponse
);

remotelog(delivery.id, delivery.seq, 'REJECTED', {
plugins.handler.remotelog(delivery.id, delivery.seq, 'REJECTED', {
category: bounce.category,
zone: this.zone.name,
from: delivery.from,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zone-mta",
"private": false,
"version": "1.7.5",
"version": "1.7.6",
"description": "Tiny outbound MTA",
"main": "app.js",
"scripts": {
Expand Down

0 comments on commit 17dddf4

Please sign in to comment.