Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #195 from godsflaw/godsflaw

enable_tls fixes to smtp_client
  • Loading branch information...
commit a89387d14cca68e590666993763510377be7744f 2 parents 877f07c + a9c0b95
@baudehlo authored
View
4 config/smtp_forward.ini
@@ -12,3 +12,7 @@ port=2555
;
; uncomment to enable TLS to the backend SMTP server
;enable_tls=1
+;
+; for messages that have multiple RCPT, send a separate message for each RCPT
+; when forwarding.
+;one_message_per_rcpt=true
View
22 plugins/queue/smtp_forward.js
@@ -22,12 +22,32 @@ exports.hook_queue = function (next, connection) {
}
};
smtp_client.on('mail', send_rcpt);
- smtp_client.on('rcpt', send_rcpt);
+ if (config.main.one_message_per_rcpt) {
+ smtp_client.on('rcpt', function () { smtp_client.send_command('DATA'); });
+ }
+ else {
+ smtp_client.on('rcpt', send_rcpt);
+ }
smtp_client.on('data', function () {
smtp_client.start_data(connection.transaction.data_lines);
});
+ smtp_client.on('dot', function () {
+ if (rcpt < connection.transaction.rcpt_to.length) {
+ smtp_client.send_command('RSET');
+ }
+ else {
+ smtp_client.call_next(OK, smtp_client.response + ' (' + connection.transaction.uuid + ')');
+ smtp_client.release();
+ }
+ });
+
+ smtp_client.on('rset', function () {
+ smtp_client.send_command('MAIL',
+ 'FROM:' + connection.transaction.mail_from);
+ });
+
smtp_client.on('bad_code', function (code, msg) {
smtp_client.release();
smtp_client.call_next();
View
2  plugins/queue/smtp_proxy.js
@@ -18,6 +18,8 @@ exports.hook_mail = function (next, connection, params) {
smtp_client.on('data', smtp_client.call_next);
smtp_client.on('dot', function () {
+ smtp_client.call_next(OK, smtp_client.response + ' (' + connection.transaction.uuid + ')');
+ smtp_client.release();
delete connection.notes.smtp_client;
});
View
24 smtp_client.js
@@ -7,7 +7,6 @@ var util = require('util');
var generic_pool = require('generic-pool');
var line_socket = require('./line_socket');
var logger = require('./logger');
-var constants = require('./constants');
var uuid = require('./utils').uuid;
var smtp_regexp = /^([0-9]{3})([ -])(.*)/;
@@ -17,7 +16,7 @@ var STATE_RELEASED = 3;
var STATE_DEAD = 4;
var STATE_DESTROYED = 5;
-function SMTPClient(port, host, timeout, enable_tls) {
+function SMTPClient(port, host, timeout) {
events.EventEmitter.call(this);
this.uuid = uuid();
this.socket = line_socket.connect(port, host);
@@ -232,12 +231,11 @@ SMTPClient.prototype.destroy = function () {
};
// Separate pools are kept for each set of server attributes.
-exports.get_pool = function (server, port, host, timeout, enable_tls, max) {
+exports.get_pool = function (server, port, host, timeout, max) {
var port = port || 25;
var host = host || 'localhost';
var timeout = (timeout == undefined) ? 300 : timeout;
- var enable_tls = /(true|yes|1)/i.exec(enable_tls) != null;
- var name = port + ':' + host + ':' + timeout + ':' + enable_tls;
+ var name = port + ':' + host + ':' + timeout;
if (!server.notes.pool) {
server.notes.pool = {};
}
@@ -245,7 +243,7 @@ exports.get_pool = function (server, port, host, timeout, enable_tls, max) {
var pool = generic_pool.Pool({
name: name,
create: function (callback) {
- var smtp_client = new SMTPClient(port, host, timeout, enable_tls);
+ var smtp_client = new SMTPClient(port, host, timeout);
logger.logdebug('[smtp_client_pool] ' + smtp_client.uuid + ' created');
callback(null, smtp_client);
},
@@ -282,8 +280,8 @@ exports.get_pool = function (server, port, host, timeout, enable_tls, max) {
};
// Get a smtp_client for the given attributes.
-exports.get_client = function (server, callback, port, host, timeout, enable_tls, max) {
- var pool = exports.get_pool(server, port, host, timeout, enable_tls, max);
+exports.get_client = function (server, callback, port, host, timeout, max) {
+ var pool = exports.get_pool(server, port, host, timeout, max);
pool.acquire(callback);
};
@@ -291,10 +289,9 @@ exports.get_client = function (server, callback, port, host, timeout, enable_tls
// config and listeners for plugins. Currently this is what smtp_proxy and
// smtp_forward have in common.
exports.get_client_plugin = function (plugin, connection, config, callback) {
- var enable_tls = config.main.enable_tls;
+ var enable_tls = /(true|yes|1)/i.exec(config.main.enable_tls) != null;
var pool = exports.get_pool(connection.server, config.main.port,
- config.main.host, config.main.timeout, config.main.enable_tls,
- config.main.max_connections);
+ config.main.host, config.main.timeout, config.main.max_connections);
pool.acquire(function (err, smtp_client) {
connection.logdebug(plugin, 'Got smtp_client: ' + smtp_client.uuid);
smtp_client.call_next = function (retval, msg) {
@@ -352,11 +349,6 @@ exports.get_client_plugin = function (plugin, connection, config, callback) {
'FROM:' + connection.transaction.mail_from);
});
- smtp_client.on('dot', function () {
- smtp_client.call_next(constants.ok, smtp_client.response + ' (' + connection.transaction.uuid + ')');
- smtp_client.release();
- });
-
smtp_client.on('error', function (msg) {
connection.logwarn(plugin, msg);
smtp_client.call_next();
View
2  tests/smtp_client/basic.js
@@ -2,7 +2,7 @@ test.expect(24);
var server = {notes: {}};
exports.get_pool(server);
-var pool_name = '25:localhost:300:false';
+var pool_name = '25:localhost:300';
test.equals(1, Object.keys(server.notes.pool).length);
test.equals(pool_name, Object.keys(server.notes.pool)[0]);
test.equals(0, server.notes.pool[pool_name].getPoolSize());
Please sign in to comment.
Something went wrong with that request. Please try again.