Skip to content

Commit

Permalink
Added smtp-data encrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
cdabupulsarsd committed Nov 21, 2024
1 parent f5eda56 commit f380d3e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
57 changes: 42 additions & 15 deletions lib/smtp-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,31 +388,58 @@ class SMTPInterface {
envelope.tls = session.tlsOptions;
}

let data = stream;

Check failure on line 391 in lib/smtp-interface.js

View workflow job for this annotation

GitHub Actions / test (16.x, ubuntu-20.04)

'data' is assigned a value but never used

Check failure on line 391 in lib/smtp-interface.js

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-20.04)

'data' is assigned a value but never used

plugins.handler.runHooks('smtp:data', [envelope, session], err => {
if (err) {
stream.destroy();
return setImmediate(() => callback(err));
}

let sizeLimiter = new SizeLimiter({
maxSize: this.options.maxSize
});
if(!envelope.encrypt) {
let sizeLimiter = new SizeLimiter({
maxSize: this.options.maxSize
});

stream.on('error', err => sizeLimiter.emit('error', err));
stream.pipe(sizeLimiter);

this.maildrop.add(envelope, sizeLimiter, (err, message) => {
if (err) {
if (err.name === 'SMTPResponse') {
if (err.responseCode) {
return callback(err);
}
return callback(null, err.message);
}
return callback(err);
}
callback(null, message);
});
} else {
let customStream = envelope.encrypt(stream, result => result);
stream = customStream;

stream.on('error', err => sizeLimiter.emit('error', err));
stream.pipe(sizeLimiter);
let sizeLimiter = new SizeLimiter({
maxSize: this.options.maxSize
});

this.maildrop.add(envelope, sizeLimiter, (err, message) => {
if (err) {
if (err.name === 'SMTPResponse') {
if (err.responseCode) {
return callback(err);
stream.on('error', err => sizeLimiter.emit('error', err));
stream.pipe(sizeLimiter);

this.maildrop.add(envelope, sizeLimiter, (err, message) => {
if (err) {
if (err.name === 'SMTPResponse') {
if (err.responseCode) {
return callback(err);
}
return callback(null, err.message);
}
return callback(null, err.message);
return callback(err);
}
return callback(err);
}
callback(null, message);
});
callback(null, message);
});
}
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@pulsar-sd/zone-mta",
"private": false,
"version": "0.1.5",
"version": "0.1.6",
"description": "Tiny outbound MTA",
"main": "app.js",
"scripts": {
Expand Down

0 comments on commit f380d3e

Please sign in to comment.