Skip to content

Commit

Permalink
Changes as suggested by baudehlo: LMTP trigger moved to notes.using_l…
Browse files Browse the repository at this point in the history
…mtp; Changed domains lookup ini to queue/smtp_forward syntax; cleared debug logging
  • Loading branch information
Peter Janotta committed Feb 9, 2014
1 parent 0618422 commit 20c1866
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
3 changes: 0 additions & 3 deletions .gitignore
@@ -1,4 +1 @@
node_modules node_modules
outbound.js~
docs/plugins/queue/lmtp.md~
plugins/queue/lmtp.js~
19 changes: 12 additions & 7 deletions docs/plugins/queue/lmtp.md
Expand Up @@ -6,14 +6,19 @@ This plugin delivers mails to inbound domains via LMTP/SMTP.
Configuration Configuration
------------- -------------


* `config/delivery_domains` * `config/lmtp.ini`
This config file provides server address and port of LMTP/SMTP server to deliver for specific inbound domains This config file provides server address and port of LMTP server to deliver for different inbound domains.
Syntax is equal to those used for the queue/smtp_forward plugin.


Example: Example:


[example.com] ; defaults
priority=0 host=localhost
exchange=127.0.0.1
port=24 port=24
isLMTP=1 #isLMTP=0 assumes SMTP
[example.com]
; Goes elsewhere
host=10.1.1.1
port=2400



22 changes: 9 additions & 13 deletions outbound.js
Expand Up @@ -894,7 +894,7 @@ HMailItem.prototype.try_deliver_host = function (mx) {
var socket = sock.connect({port: port, host: host, localAddress: mx.bind}); var socket = sock.connect({port: port, host: host, localAddress: mx.bind});
var self = this; var self = this;
var processing_mail = true; var processing_mail = true;
if (mx.isLMTP) this.loginfo('Using LMTP for host ' + mx.exchange); if (this.notes.using_lmtp) this.loginfo('Using LMTP for host ' + mx.exchange);


this.loginfo("Attempting to deliver to: " + host + ":" + port + " (" + delivery_queue.length() + ") (" + temp_fail_queue.length() + ")"); this.loginfo("Attempting to deliver to: " + host + ":" + port + " (" + delivery_queue.length() + ") (" + temp_fail_queue.length() + ")");


Expand All @@ -915,7 +915,7 @@ HMailItem.prototype.try_deliver_host = function (mx) {


socket.setTimeout(300 * 1000); // TODO: make this configurable socket.setTimeout(300 * 1000); // TODO: make this configurable


var command = mx.isLMTP ? 'connectlmtp' : 'connect'; var command = this.notes.using_lmtp ? 'connectlmtp' : 'connect';
var response = []; var response = [];


var recipients = this.todo.rcpt_to.map(function (a) { return new Address (a.original) }); var recipients = this.todo.rcpt_to.map(function (a) { return new Address (a.original) });
Expand Down Expand Up @@ -977,7 +977,7 @@ HMailItem.prototype.try_deliver_host = function (mx) {
// Set this flag so we don't try STARTTLS again if it // Set this flag so we don't try STARTTLS again if it
// is incorrectly offered at EHLO once we are secured. // is incorrectly offered at EHLO once we are secured.
secured = true; secured = true;
socket.send_command(mx.isLMTP ? 'LHLO' : 'EHLO', config.get('me')); socket.send_command(self.notes.using_lmtp ? 'LHLO' : 'EHLO', config.get('me'));
}); });
this.send_command('STARTTLS'); this.send_command('STARTTLS');
} }
Expand All @@ -993,11 +993,8 @@ HMailItem.prototype.try_deliver_host = function (mx) {
} }


socket.rcpt_done = function (rcpt_address) { socket.rcpt_done = function (rcpt_address) {
self.loginfo('confirmed rcpt_address: ' + rcpt_address.format());
for(var i=0, j=verified_rcpts.length; i<j; i++) { for(var i=0, j=verified_rcpts.length; i<j; i++) {
self.loginfo('checking against: ' + verified_rcpts[i].format());
if (rcpt_address.format() === verified_rcpts[i].format()) { if (rcpt_address.format() === verified_rcpts[i].format()) {
self.loginfo('equal');
verified_rcpts.splice(i,1); verified_rcpts.splice(i,1);
if (!verified_rcpts.length) { if (!verified_rcpts.length) {
socket.all_rcpts_done(true); socket.all_rcpts_done(true);
Expand All @@ -1009,7 +1006,6 @@ HMailItem.prototype.try_deliver_host = function (mx) {
} }


socket.all_rcpts_done = function (success) { socket.all_rcpts_done = function (success) {
if(success) self.loginfo('All rcpts verified');
if (fail_recips.length) { if (fail_recips.length) {
self.refcount++; self.refcount++;
exports.split_to_new_recipients(self, fail_recips.map(map_recips), "Some recipients temporarily failed", function (hmail) { exports.split_to_new_recipients(self, fail_recips.map(map_recips), "Some recipients temporarily failed", function (hmail) {
Expand Down Expand Up @@ -1062,15 +1058,15 @@ HMailItem.prototype.try_deliver_host = function (mx) {
if (code.match(/^4/)) { if (code.match(/^4/)) {
if (/^rcpt/.test(command) || (command === 'dot' && mx.isLMTP)) { if (/^rcpt/.test(command) || (command === 'dot' && mx.isLMTP)) {
// this recipient was rejected // this recipient was rejected
if(command === 'dot' && mx.isLMTP) last_recip = get_done_rcpt(rest); if(command === 'dot' && self.notes.using_lmtp) last_recip = get_done_rcpt(rest);
self.lognotice('recipient ' + last_recip + ' deferred: ' + self.lognotice('recipient ' + last_recip + ' deferred: ' +
code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' ')); code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' '));
(function () { (function () {
var o = {}; var o = {};
o[last_recip] = code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' '); o[last_recip] = code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' ');
fail_recips.push(o); fail_recips.push(o);
})(); })();
if(command === 'dot' && mx.isLMTP) socket.rcpt_done(last_recip); if(command === 'dot' && self.notes.using_lmtp) socket.rcpt_done(last_recip);
} }
else { else {
var reason = response.join(' '); var reason = response.join(' ');
Expand All @@ -1084,16 +1080,16 @@ HMailItem.prototype.try_deliver_host = function (mx) {
// EHLO command was rejected; fall-back to HELO // EHLO command was rejected; fall-back to HELO
return socket.send_command('HELO', config.get('me')); return socket.send_command('HELO', config.get('me'));
} }
if (/^rcpt/.test(command) || (command === 'dot' && mx.isLMTP)) { if (/^rcpt/.test(command) || (command === 'dot' && self.notes.using_lmtp)) {
if(command === 'dot' && mx.isLMTP) last_recip = get_done_rcpt(rest); if(command === 'dot' && self.notes.using_lmtp) last_recip = get_done_rcpt(rest);
self.lognotice('recipient ' + last_recip + ' rejected: ' + self.lognotice('recipient ' + last_recip + ' rejected: ' +
code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' ')); code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' '));
(function() { (function() {
var o = {}; var o = {};
o[last_recip] = code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' '); o[last_recip] = code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' ');
bounce_recips.push(o); bounce_recips.push(o);
})(); })();
if (command === 'dot' && mx.isLMTP) socket.rcpt_done(last_recip); if (command === 'dot' && self.notes.using_lmtp) socket.rcpt_done(last_recip);
} }
else { else {
var reason = response.join(' '); var reason = response.join(' ');
Expand Down Expand Up @@ -1132,7 +1128,7 @@ HMailItem.prototype.try_deliver_host = function (mx) {
if (last_recip && code.match(/^250/)) if (last_recip && code.match(/^250/))
{ {
ok_recips++; ok_recips++;
if (mx.isLMTP) verified_rcpts.push(last_recip); if (self.notes.using_lmtp) verified_rcpts.push(last_recip);
} }
if (!recipients.length) { if (!recipients.length) {
if (ok_recips) { if (ok_recips) {
Expand Down
19 changes: 10 additions & 9 deletions plugins/queue/lmtp.js
Expand Up @@ -4,18 +4,19 @@


var outbound = require('./outbound'); var outbound = require('./outbound');


//get_mx hook
exports.hook_get_mx = function (next, hmail, domain) { exports.hook_get_mx = function (next, hmail, domain) {
//TODO: allow arrays of mx objects; currently only one mx object per domain if (!hmail.todo.notes.using_lmtp) return next();
var domains_ini = this.config.get('delivery_domains.ini', 'ini'); var config = this.config.get('lmtp.ini', 'ini');
if (domain in domains_ini) { var section = config[domain] || config.main;
next(OK, domains_ini[domain]); var mx = {
} priority: 0,
else { exchange: section.host || '127.0.0.1',
next(CONT); port: section.port || 24,
} };
return next(OK, mx);
} }


exports.hook_queue = function (next, connection) { exports.hook_queue = function (next, connection) {
connection.transaction.notes.using_lmtp = true;
outbound.send_email(connection.transaction, next); outbound.send_email(connection.transaction, next);
} }

0 comments on commit 20c1866

Please sign in to comment.