From f380d3e217863936c2984157a6851f9ded5c1324 Mon Sep 17 00:00:00 2001 From: Christopher Dabu Date: Thu, 21 Nov 2024 16:32:40 +0800 Subject: [PATCH] Added smtp-data encrypt --- lib/smtp-interface.js | 57 +++++++++++++++++++++++++++++++------------ package-lock.json | 4 +-- package.json | 2 +- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/lib/smtp-interface.js b/lib/smtp-interface.js index 488a850..ba6013a 100644 --- a/lib/smtp-interface.js +++ b/lib/smtp-interface.js @@ -388,31 +388,58 @@ class SMTPInterface { envelope.tls = session.tlsOptions; } + let data = stream; + 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); + }); + } }); } } diff --git a/package-lock.json b/package-lock.json index 44d9fc3..5d94fb0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@pulsar-sd/zone-mta", - "version": "0.1.5", + "version": "0.1.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@pulsar-sd/zone-mta", - "version": "0.1.5", + "version": "0.1.6", "license": "EUPL-1.1+", "dependencies": { "base32.js": "0.1.0", diff --git a/package.json b/package.json index 5839236..94d1d6a 100644 --- a/package.json +++ b/package.json @@ -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": {