Permalink
Browse files

Reworked smtp_forward/proxy and conn_pool.

  • Loading branch information...
1 parent 2bcfd31 commit 9969655a5ff5bec057e1f676d58e63c95ebc05bb Eric Day committed Apr 4, 2012
Showing with 277 additions and 460 deletions.
  1. +202 −3 plugins/queue/conn_pool_base.js
  2. +36 −176 plugins/queue/smtp_forward.js
  3. +39 −281 plugins/queue/smtp_proxy.js
View
205 plugins/queue/conn_pool_base.js
@@ -3,6 +3,7 @@
// See plugins/queue/smtp_forward.js for an example.
var sock = require('./line_socket');
+var smtp_regexp = /^([0-9]{3})([ -])(.*)/;
exports.conn_get = function (connection, host, port, timeout) {
var conn = {};
@@ -38,15 +39,15 @@ exports.conn_get = function (connection, host, port, timeout) {
var self = this;
conn.socket.on('error', function (err) {
- self.conn_destroy(self, connection, conn);
+ self.conn_destroy(connection, conn);
});
conn.socket.on('timeout', function () {
- self.conn_destroy(self, connection, conn);
+ self.conn_destroy(connection, conn);
});
conn.socket.on('close', function (had_error) {
- self.conn_destroy(self, connection, conn);
+ self.conn_destroy(connection, conn);
});
}
else {
@@ -156,3 +157,201 @@ exports.conn_idle = function (connection) {
return;
}
+
+exports.smtp_conn_get = function (connection, host, port, timeout, enable_tls) {
+ var smtp_conn = this.conn_get(connection, host, port, timeout);
+ smtp_conn.data_marker = 0;
+ smtp_conn.dot_pending = true;
+ smtp_conn.response = []
+ smtp_conn.command = 'connect';
+ var self = this;
+
+ smtp_conn.send_data = function () {
+ while (smtp_conn.data_marker < connection.transaction.data_lines.length) {
+ var line = connection.transaction.data_lines[smtp_conn.data_marker];
+ smtp_conn.data_marker++;
+ var wrote_all = smtp_conn.socket.write(line.replace(/^\./, '..').replace(/\r?\n/g, '\r\n'));
+ if (!wrote_all) return;
+ }
+ // we get here if wrote_all still true, and we got to end of data_lines
+ if (smtp_conn.dot_pending) {
+ smtp_conn.dot_pending = false;
+ smtp_conn.send_command('dot');
+ }
+ }
+
+ smtp_conn.send_command = function (cmd, data) {
+ var line = cmd + (data ? (' ' + data) : '');
+ if (cmd === 'dot') {
+ line = '.';
+ }
+ connection.logprotocol(self, "C: " + line);
+ smtp_conn.command = cmd.toLowerCase();
+ smtp_conn.response = [];
+ smtp_conn.socket.write(line + "\r\n");
+ };
+
+ smtp_conn.reset = function () {
+ smtp_conn.socket.removeAllListeners('line');
+ smtp_conn.socket.on('line', function (line) {
+ var matches = smtp_regexp.exec(line);
+ if (!matches) {
+ connection.logerror(self, "Unrecognised response from upstream server: " + line);
+ smtp_conn.socket.end();
+ return;
+ }
+
+ var code = matches[1], cont = matches[2];
+ if (cont !== ' ') {
+ return;
+ }
+
+ if (code.match(/^[45]/)) {
+ smtp_conn.socket.end();
+ return;
+ }
+ self.conn_idle(connection);
+ });
+ smtp_conn.send_command('RSET');
+ };
+
+ smtp_conn.call_next = function (retval, msg) {
+ if (smtp_conn.next) {
+ smtp_conn.next(retval, msg);
+ smtp_conn.next = undefined;
+ }
+ };
+
+ smtp_conn.start = function () {
+ if (smtp_conn.pool_connection) {
+ if (smtp_conn.xclient) {
+ smtp_conn.send_command('XCLIENT', 'ADDR=' + connection.remote_ip);
+ }
+ else {
+ smtp_conn.send_command('MAIL', 'FROM:' + connection.transaction.mail_from);
+ }
+ }
+ };
+
+ smtp_conn.socket.on('drain', function() {
+ if (smtp_conn.dot_pending && smtp_conn.command === 'mailbody') {
+ process.nextTick(function () { smtp_conn.send_data() });
+ }
+ });
+
+ smtp_conn.socket.on('error', function (err) {
+ connection.logdebug(self, "Ongoing connection failed: " + err);
+ smtp_conn.call_next();
+ });
+
+ smtp_conn.socket.on('timeout', function () {
+ connection.logdebug(self, "Ongoing connection timed out");
+ smtp_conn.call_next();
+ });
+
+ smtp_conn.socket.on('close', function (had_error) {
+ connection.logdebug(self, "Ongoing connection closed");
+ });
+
+ smtp_conn.socket.on('connect', function () {
+ connection.logdebug(self, "Ongoing connection established");
+ });
+
+ smtp_conn.socket.on('line', function (line) {
+ connection.logprotocol(self, "S: " + line);
+ var matches = smtp_regexp.exec(line);
+ if (!matches) {
+ connection.logerror(self, "Unrecognised response from upstream server: " + line);
+ smtp_conn.socket.end();
+ return smtp_conn.call_next();
+ }
+
+ var code = matches[1],
+ cont = matches[2],
+ rest = matches[3];
+ smtp_conn.response.push(rest);
+ if (cont !== ' ') {
+ return;
+ }
+
+ if (smtp_conn.command === 'ehlo') {
+ if (code.match(/^5/)) {
+ // Handle fallback to HELO if EHLO is rejected
+ if (smtp_conn.xclient) {
+ smtp_conn.send_command('HELO', connection.hello_host);
+ }
+ else {
+ smtp_conn.send_command('HELO', self.config.get('me'));
+ }
+ return;
+ }
+ // Parse CAPABILITIES
+ for (var i in smtp_conn.response) {
+ if (smtp_conn.response[i].match(/^XCLIENT/)) {
+ if(!smtp_conn.xclient) {
+ // Just use the ADDR= key for now
+ smtp_conn.send_command('XCLIENT', 'ADDR=' + connection.remote_ip);
+ return;
+ }
+ }
+ if (smtp_conn.response[i].match(/^STARTTLS/)) {
+ var key = self.config.get('tls_key.pem', 'data').join("\n");
+ var cert = self.config.get('tls_cert.pem', 'data').join("\n");
+ if (key && cert && (!/(true|yes|1)/i.exec(enable_tls))) {
+ smtp_conn.socket.on('secure', function () {
+ smtp_conn.send_command('EHLO', self.config.get('me'));
+ });
+ smtp_conn.send_command('STARTTLS');
+ return;
+ }
+ }
+ }
+ }
+ if (smtp_conn.command === 'xclient' && code.match(/^5/)) {
+ // XCLIENT command was rejected (no permission?)
+ // Carry on without XCLIENT
+ smtp_conn.command = 'helo';
+ }
+ else if (code.match(/^[45]/)) {
+ if (!smtp_conn.on_error(code)) {
+ return;
+ }
+ }
+ switch (smtp_conn.command) {
+ case 'xclient':
+ smtp_conn.xclient = true;
+ smtp_conn.send_command('EHLO', connection.hello_host);
+ break;
+ case 'starttls':
+ var tls_options = { key: key, cert: cert };
+ smtp_conn.socket.upgrade(tls_options);
+ break;
+ case 'connect':
+ smtp_conn.send_command('EHLO', self.config.get('me'));
+ break;
+ case 'ehlo':
+ case 'helo':
+ smtp_conn.send_command('MAIL', 'FROM:' + connection.transaction.mail_from);
+ break;
+ case 'mail':
+ smtp_conn.on_mail();
+ break;
+ case 'rcpt':
+ smtp_conn.on_rcpt();
+ break;
+ case 'data':
+ smtp_conn.on_data();
+ break;
+ case 'dot':
+ // Return the response from the server back to the client
+ // but add in our transaction UUID at the end of the line.
+ smtp_conn.call_next(OK, smtp_conn.response + ' (' + connection.transaction.uuid + ')');
+ smtp_conn.reset();
+ break;
+ default:
+ throw new Error("Unknown command: " + smtp_conn.command);
+ }
+ });
+
+ return smtp_conn;
+}
View
212 plugins/queue/smtp_forward.js
@@ -1,191 +1,51 @@
// Forward to an SMTP server
-var sock = require('./line_socket');
+// Opens the connection to the ongoing SMTP server at queue time
+// and passes back any errors seen on the ongoing server to the
+// originating server.
+
+var smtp_regexp = /^([0-9]{3})([ -])(.*)/;
exports.register = function () {
this.inherits('queue/conn_pool_base');
- this.register_hook('queue', 'smtp_forward');
};
-var smtp_regexp = /^([0-9]{3})([ -])(.*)/;
-
-exports.smtp_forward = function (next, connection) {
- var smtp_config = this.config.get('smtp_forward.ini');
- connection.loginfo(this, "forwarding to " + smtp_config.main.host + ":" + smtp_config.main.port);
- var smtp_forward = this.conn_get(connection, smtp_config.main.host, smtp_config.main.port, 300 * 1000);
- var socket = smtp_forward.socket;
- var command = 'connect';
- var self = this;
- var response = [];
- // copy the recipients:
+exports.hook_queue = function (next, connection) {
+ var config = this.config.get('smtp_forward.ini');
+ connection.loginfo(this, "forwarding to " + config.main.host + ":" + config.main.port);
+ var smtp_conn = this.smtp_conn_get(connection, config.main.host, config.main.port, config.main.timeout, config.main.enable_tls);
+ smtp_conn.next = next;
var recipients = connection.transaction.rcpt_to.map(function(item) { return item });
- var data_marker = 0;
- var dot_pending = true;
- var send_data = function () {
- var wrote_all = true;
- while (wrote_all && (data_marker < connection.transaction.data_lines.length)) {
- var line = connection.transaction.data_lines[data_marker];
- data_marker++;
- wrote_all = socket.write(line.replace(/^\./, '..').replace(/\r?\n/g, '\r\n'));
- if (!wrote_all) return;
- }
- // we get here if wrote_all still true, and we got to end of data_lines
- if (dot_pending) {
- dot_pending = false;
- socket.send_command('dot');
- }
+ smtp_conn.on_error = function (code) {
+ if (!(smtp_conn.command === 'mail' || smtp_conn.command === 'rcpt')) {
+ // NOTE: recipients can be sent at both 'mail' *AND* 'rcpt'
+ // command states if multiple recipients are present.
+ // We ignore errors for both states as the DATA command will
+ // be rejected by the remote end if there are no recipients.
+ smtp_conn.reset();
+ smtp_conn.call_next(); // Fall through to other queue hooks here
+ return false;
+ }
+ return true;
};
- socket.on('drain', function () {
- connection.logdebug(self, 'drain');
- if (dot_pending && command === 'databody') {
- process.nextTick(function () { send_data() });
+ smtp_conn.on_mail = function () {
+ smtp_conn.send_command('RCPT', 'TO:' + recipients.shift());
+ if (recipients.length) {
+ // don't move to next state if we have more recipients
+ smtp_conn.command = 'mail';
+ return;
}
- });
+ };
- socket.send_command = function (cmd, data) {
- var line = cmd + (data ? (' ' + data) : '');
- if (cmd === 'dot') {
- line = '.';
- }
- connection.logprotocol(self, "C: " + line);
- command = cmd.toLowerCase();
- socket.write(line + "\r\n");
- // Clear response buffer from previous command
- response = [];
+ smtp_conn.on_rcpt = function () {
+ smtp_conn.send_command('DATA');
};
-
- socket.on('timeout', function () {
- connection.logerror(self, "Ongoing connection timed out");
- next();
- });
- socket.on('error', function (err) {
- connection.logerror(self, "Ongoing connection failed: " + err);
- // we don't deny on error - maybe another plugin can deliver
- next();
- });
- socket.on('connect', function () {
- });
- socket.on('line', function (line) {
- var matches;
- connection.logprotocol(self, "S: " + line);
- if (matches = smtp_regexp.exec(line)) {
- var code = matches[1],
- cont = matches[2],
- rest = matches[3];
- response.push(rest);
- if (cont === ' ') {
- connection.logdebug(self, 'command state: ' + command);
- // Handle fallback to HELO if EHLO is rejected
- if (command === 'ehlo') {
- if (code.match(/^5/)) {
- // Handle fallback to HELO if EHLO is rejected
- if (!socket.xclient) {
- socket.send_command('HELO', self.config.get('me'));
- }
- else {
- socket.send_command('HELO', connection.hello_host);
- }
- return;
- }
- // Parse CAPABILITIES
- for (var i in response) {
- if (response[i].match(/^XCLIENT/)) {
- if(!socket.xclient) {
- // Just use the ADDR= key for now
- socket.send_command('XCLIENT', 'ADDR=' + connection.remote_ip);
- return;
- }
- }
- if (response[i].match(/^STARTTLS/)) {
- var key = self.config.get('tls_key.pem', 'data').join("\n");
- var cert = self.config.get('tls_cert.pem', 'data').join("\n");
- // Use TLS opportunistically if we found the key and certificate
- if (key && cert && (!/(true|yes|1)/i.exec(smtp_config.main.enable_tls))) {
- socket.on('secure', function () {
- socket.send_command('EHLO', self.config.get('me'));
- });
- socket.send_command('STARTTLS');
- return;
- }
- }
- }
- }
- if (command === 'xclient' && code.match(/^5/)) {
- // XCLIENT command was rejected (no permission?)
- // Carry on without XCLIENT
- command = 'helo';
- }
- else if (!(command === 'mail' || command === 'rcpt') && code.match(/^[45]/)) {
- // NOTE: recipients can be sent at both 'mail' *AND* 'rcpt'
- // command states if multiple recipients are present.
- // We ignore errors for both states as the DATA command will
- // be rejected by the remote end if there are no recipients.
- socket.send_command('RSET');
- return next(); // Fall through to other queue hooks here
- }
- switch (command) {
- case 'xclient':
- // If we are in XCLIENT mode, proxy the HELO/EHLO from the client
- socket.xclient = true;
- socket.send_command('EHLO', connection.hello_host);
- break;
- case 'starttls':
- var tls_options = { key: key, cert: cert };
- socket.upgrade(tls_options);
- break;
- case 'connect':
- socket.send_command('EHLO', self.config.get('me'));
- break;
- case 'ehlo':
- case 'helo':
- socket.send_command('MAIL', 'FROM:' + connection.transaction.mail_from);
- break;
- case 'mail':
- socket.send_command('RCPT', 'TO:' + recipients.shift());
- if (recipients.length) {
- // don't move to next state if we have more recipients
- command = 'mail';
- return;
- }
- break;
- case 'rcpt':
- socket.send_command('DATA');
- break;
- case 'data':
- command = 'databody';
- send_data();
- break;
- case 'dot':
- // Return the response from the forwarder back to the client
- // But add in our transaction UUID at the end of the line.
- next(OK, response + ' (' + connection.transaction.uuid + ')');
- socket.send_command('RSET');
- break;
- case 'rset':
- self.conn_idle(connection);
- break;
- default:
- throw new Error("Unknown command: " + command);
- }
- }
- }
- else {
- // Unrecognised response.
- connection.logerror(self, "Unrecognised response from upstream server: " + line);
- socket.end();
- return next();
- }
- });
- if (smtp_forward.pool_connection) {
- // If we used XCLIENT earlier; we *must* re-send it again
- // To update the proxy with the new client details.
- if (socket.xclient) {
- socket.send_command('XCLIENT', 'ADDR=' + connection.remote_ip);
- }
- else {
- socket.send_command('MAIL', 'FROM:' + connection.transaction.mail_from);
- }
- }
+ smtp_conn.on_data = function () {
+ smtp_conn.command = 'mailbody';
+ smtp_conn.send_data();
+ };
+
+ smtp_conn.start();
};
View
320 plugins/queue/smtp_proxy.js
@@ -1,315 +1,73 @@
-// Forward to an SMTP server as a proxy.
+// Proxy to an SMTP server
// Opens the connection to the ongoing SMTP server at MAIL FROM time
-// and passes back any errors seen on the ongoing server to the originating server.
+// and passes back any errors seen on the ongoing server to the
+// originating server.
-var sock = require('./line_socket');
var smtp_regexp = /^([0-9]{3})([ -])(.*)/;
exports.register = function () {
this.inherits('queue/conn_pool_base');
}
exports.hook_mail = function (next, connection, params) {
- connection.loginfo(this, "proxying");
- var self = this;
- var mail_from = params[0];
- var data_marker = 0;
- var config = self.config.get('smtp_proxy.ini');
- var host = (config.main.host) ? config.main.host : 'localhost';
- var port = (config.main.port) ? config.main.port : 25;
- var timeout = (config.main.timeout || config.main.timeout == 0) ?
- config.main.timeout : 300;
- var smtp_proxy = self.conn_get(connection, host, port, timeout);
- var in_write = false;
- var dot_pending = true;
-
- if (!smtp_proxy.pool_connection) {
- smtp_proxy.command = 'connect';
- }
-
- smtp_proxy.set_next = function (cb) {
- this.next_called = false;
-
- this.next = function (retval, msg) {
- this.next_called = true;
+ var config = this.config.get('smtp_proxy.ini');
+ connection.loginfo(this, "proxying to " + config.main.host + ":" + config.main.port);
+ var smtp_conn = this.smtp_conn_get(connection, config.main.host, config.main.port, config.main.timeout, config.main.enable_tls);
+ smtp_conn.next = next;
- if (retval && msg) {
- return cb(retval, msg);
- }
- else if(retval) {
- return cb(retval);
- }
- else {
- return cb();
- }
- };
- };
- smtp_proxy.set_next(next);
-
- // Call this in the case of socket error, or the socket throws an error.
- var socket_error = function (err) {
- connection.logdebug(self, "Ongoing connection failed: " + err);
+ var self = this;
- if (smtp_proxy) {
- smtp_proxy.next(DENYSOFT,'Proxy connection failed');
+ smtp_conn.on_error = function (code) {
+ var response_array = smtp_conn.response.slice();
+ if (smtp_conn.command !== 'rcpt') {
+ // errors are OK for rcpt, but nothing else
+ // this can also happen if the destination server
+ // times out, but that is okay.
+ connection.loginfo(self, "message denied, proxying failed");
+ smtp_conn.reset();
}
- self.conn_destroy(connection, smtp_proxy);
+ smtp_conn.call_next(code.match(/^4/) ? DENYSOFT : DENY, response_array);
+ return false;
};
- smtp_proxy.send_data = function () {
- var wrote_all = true;
-
- try {
- while (wrote_all &&
- (data_marker < connection.transaction.data_lines.length)) {
- var line = connection.transaction.data_lines[data_marker];
- data_marker++;
- connection.logdata(self, "C: " + line);
- // this protection is due to bug #
- in_write = true;
- wrote_all = smtp_proxy.socket.write(
- line.replace(/^\./, '..').replace(/\r?\n/g, '\r\n'));
- in_write = false;
- if (!wrote_all) {
- return;
- }
- }
- // we get here if wrote_all still true,
- // and we got to end of data_lines
- if (dot_pending) {
- dot_pending = false;
- smtp_proxy.socket.send_command('dot');
- }
- }
- catch (err) {
- socket_error(err);
- return;
- }
+ smtp_conn.on_mail = smtp_conn.on_rcpt = smtp_conn.on_data = function () {
+ smtp_conn.call_next();
}
- // Add socket event listeners.
- smtp_proxy.socket.on('drain', function() {
- if (dot_pending && smtp_proxy.command === 'mailbody') {
- process.nextTick(function () { smtp_proxy.send_data() });
- }
- });
-
- smtp_proxy.socket.on('error', socket_error);
-
- smtp_proxy.socket.on('timeout', function () {
- connection.logdebug(self, "Ongoing connection timed out");
- });
-
- smtp_proxy.socket.on('close', function (had_error) {
- connection.logdebug(self, "Ongoing connection closed");
- });
-
- smtp_proxy.socket.on('connect', function () {
- connection.logdebug(self, "Ongoing connection established");
- });
-
- smtp_proxy.socket.send_command = function (cmd, data) {
- var line = cmd + (data ? (' ' + data) : '');
-
- if (cmd === 'dot') {
- line = '.';
- }
-
- connection.logprotocol(self, "C: " + line);
-
- try {
- this.write(line + "\r\n");
- }
- catch (err) {
- socket_error(err);
- return;
- }
-
- smtp_proxy.command = cmd.toLowerCase();
- smtp_proxy.response = [];
- };
-
- smtp_proxy.socket.on('line', function (line) {
- var matches;
- connection.logprotocol(self, "S: " + line);
- if (matches = smtp_regexp.exec(line)) {
- var code = matches[1],
- cont = matches[2],
- rest = matches[3];
- smtp_proxy.response.push(rest);
- if (cont === ' ') {
- if (smtp_proxy.command === 'ehlo') {
- // Handle fallback to HELO if EHLO is rejected
- if (code.match(/^5/)) {
- if (smtp_proxy.xclient) {
- smtp_proxy.socket.send_command('HELO',
- connection.hello_host);
- }
- else {
- smtp_proxy.socket.send_command('HELO',
- self.config.get('me'));
- }
- return;
- }
- // Parse CAPABILITIES
- for (var i in smtp_proxy.response) {
- if (smtp_proxy.response[i].match(/^XCLIENT/)) {
- if (!smtp_proxy.xclient) {
- smtp_proxy.socket.send_command('XCLIENT',
- 'ADDR=' + connection.remote_ip);
- return;
- }
- }
- if (smtp_proxy.response[i].match(/^STARTTLS/)) {
- var key = self.config.get(
- 'tls_key.pem', 'data').join("\n");
- var cert = self.config.get(
- 'tls_cert.pem', 'data').join("\n");
- if (key && cert && (/(true|yes|1)/i.exec(
- smtp_proxy.config.main.enable_tls))) {
- this.on('secure', function () {
- smtp_proxy.socket.send_command('EHLO',
- self.config.get('me'));
- });
- smtp_proxy.socket.send_command('STARTTLS');
- return;
- }
- }
- }
- }
- if (smtp_proxy.command === 'xclient' && code.match(/^5/)) {
- // XCLIENT rejected; continue without it
- smtp_proxy.command = 'helo';
- }
- else if (code.match(/^[45]/)) {
- var response_array = smtp_proxy.response.slice();
- if (smtp_proxy.command !== 'rcpt') {
- // errors are OK for rcpt, but nothing else
- // this can also happen if the destination server
- // times out, but that is okay.
- connection.loginfo(self,
- "message denied, proxying failed");
- smtp_proxy.socket.send_command('RSET');
- }
-
- if (smtp_proxy) {
- return smtp_proxy.next(code.match(/^4/) ?
- DENYSOFT : DENY, response_array);
- }
- else {
- return;
- }
- }
- switch (smtp_proxy.command) {
- case 'xclient':
- smtp_proxy.xclient = true;
- smtp_proxy.socket.send_command('EHLO',
- connection.hello_host);
- break;
- case 'starttls':
- var tls_options = { key: key, cert: cert };
- smtp_proxy.socket.upgrade(tls_options);
- break;
- case 'connect':
- smtp_proxy.socket.send_command('EHLO',
- self.config.get('me'));
- break;
- case 'ehlo':
- case 'helo':
- smtp_proxy.socket.send_command('MAIL',
- 'FROM:' + mail_from);
- break;
- case 'mail':
- if (smtp_proxy) smtp_proxy.next();
- break;
- case 'rcpt':
- if (smtp_proxy) smtp_proxy.next();
- break;
- case 'data':
- if (smtp_proxy) smtp_proxy.next();
- break;
- case 'dot':
- connection.loginfo(self,
- "message delivered, proxying complete");
- if (smtp_proxy) {
- smtp_proxy.next(OK, smtp_proxy.response + ' (' +
- connection.transaction.uuid + ')');
- smtp_proxy.socket.send_command('RSET');
- }
- break;
- case 'rset':
- if (smtp_proxy && !smtp_proxy.next_called) {
- smtp_proxy.next();
- }
- self.conn_idle(connection);
- break;
- default:
- throw "Unknown command: " + smtp_proxy.command;
- }
- }
- }
- else {
- // Unrecognised response.
- connection.logerror(self,
- "Unrecognised response from upstream server: " + line);
- connection.loginfo(self, "message denied, proxying failed");
- smtp_proxy.socket.send_command('RSET');
- if (smtp_proxy) return smtp_proxy.next(DENYSOFT);
- }
- });
-
- if (smtp_proxy.pool_connection) {
- // If we used XCLIENT earlier; we *must* re-send it again
- // To update the proxy with the new client details.
- if (smtp_proxy.xclient) {
- smtp_proxy.socket.send_command('XCLIENT',
- 'ADDR=' + connection.remote_ip);
- }
- else {
- smtp_proxy.socket.send_command('MAIL', 'FROM:' + mail_from);
- }
- }
+ smtp_conn.start();
};
exports.hook_rcpt_ok = function (next, connection, recipient) {
- var smtp_proxy = connection.notes.conn;
- if (!smtp_proxy) return next();
- smtp_proxy.set_next(next);
- smtp_proxy.socket.send_command('RCPT', 'TO:' + recipient);
+ var smtp_conn = connection.notes.conn;
+ smtp_conn.next = next;
+ smtp_conn.send_command('RCPT', 'TO:' + recipient);
};
exports.hook_data = function (next, connection) {
- var smtp_proxy = connection.notes.conn;
- if (!smtp_proxy) return next();
- smtp_proxy.set_next(next);
- smtp_proxy.socket.send_command("DATA");
+ var smtp_conn = connection.notes.conn;
+ smtp_conn.next = next;
+ smtp_conn.send_command("DATA");
};
exports.hook_queue = function (next, connection) {
- var smtp_proxy = connection.notes.conn;
- if (!smtp_proxy) return next();
- smtp_proxy.command = 'mailbody';
- smtp_proxy.set_next(next);
- smtp_proxy.send_data();
+ var smtp_conn = connection.notes.conn;
+ smtp_conn.command = 'mailbody';
+ smtp_conn.next = next;
+ smtp_conn.send_data();
};
exports.hook_rset = function (next, connection) {
- this.rset_proxy(next, connection);
+ var smtp_conn = connection.notes.conn;
+ smtp_conn.reset();
+ next();
}
-exports.hook_quit = function (next, connection) {
- this.rset_proxy(next, connection);
-}
+exports.hook_quit = exports.hook_rset;
exports.hook_disconnect = function (next, connection) {
- // XXX: what if this happens durring data or queue?
- this.rset_proxy(next, connection);
-};
-
-exports.rset_proxy = function (next, connection) {
- var smtp_proxy = connection.notes.conn;
- if (!smtp_proxy) return next();
- smtp_proxy.set_next(next);
- smtp_proxy.socket.send_command("RSET");
+ var smtp_conn = connection.notes.conn;
+ smtp_conn.reset();
+ smtp_conn.call_next();
+ next();
};

0 comments on commit 9969655

Please sign in to comment.