-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
31 lines (25 loc) · 990 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
const spfCheck = require('./lib/spf-check');
const { checkRateLimit, updateCounters } = require('./lib/process-headers');
module.exports.title = 'X-Auth Rate Limiter';
module.exports.init = function (app, done) {
// SPF validity is processed immediatelly on MAIL FROM command
app.addHook('smtp:mail_from', (address, session, next) => {
spfCheck(app, address, session)
.then(() => next())
.catch(err => next(err));
});
// Check if rate limit is already reached for this user
app.addHook('message:headers', (envelope, messageInfo, next) => {
checkRateLimit(app, envelope, messageInfo)
.then(() => next())
.catch(err => next(err));
});
// Increment rate limit counters
app.addHook('message:queue', (envelope, messageInfo, next) => {
updateCounters(app, envelope, messageInfo)
.then(() => next())
.catch(err => next(err));
});
done();
};