Permalink
Browse files

Changes as suggested by baudehlo: LMTP trigger moved to notes.using_l…

…mtp; Changed domains lookup ini to queue/smtp_forward syntax; cleared debug logging
  • Loading branch information...
1 parent 0618422 commit 20c1866531ba38a66419fb912333f2338734d608 Peter Janotta committed Feb 9, 2014
Showing with 31 additions and 32 deletions.
  1. +0 −3 .gitignore
  2. +12 −7 docs/plugins/queue/lmtp.md
  3. +9 −13 outbound.js
  4. +10 −9 plugins/queue/lmtp.js
View
@@ -1,4 +1 @@
node_modules
-outbound.js~
-docs/plugins/queue/lmtp.md~
-plugins/queue/lmtp.js~
View
@@ -6,14 +6,19 @@ This plugin delivers mails to inbound domains via LMTP/SMTP.
Configuration
-------------
-* `config/delivery_domains`
- This config file provides server address and port of LMTP/SMTP server to deliver for specific inbound domains
+* `config/lmtp.ini`
+ 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.com]
- priority=0
- exchange=127.0.0.1
+
+ ; defaults
+ host=localhost
port=24
- isLMTP=1 #isLMTP=0 assumes SMTP
+
+ [example.com]
+ ; Goes elsewhere
+ host=10.1.1.1
+ port=2400
+
View
@@ -894,7 +894,7 @@ HMailItem.prototype.try_deliver_host = function (mx) {
var socket = sock.connect({port: port, host: host, localAddress: mx.bind});
var self = this;
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() + ")");
@@ -915,7 +915,7 @@ HMailItem.prototype.try_deliver_host = function (mx) {
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 recipients = this.todo.rcpt_to.map(function (a) { return new Address (a.original) });
@@ -977,7 +977,7 @@ HMailItem.prototype.try_deliver_host = function (mx) {
// Set this flag so we don't try STARTTLS again if it
// is incorrectly offered at EHLO once we are secured.
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');
}
@@ -993,11 +993,8 @@ HMailItem.prototype.try_deliver_host = function (mx) {
}
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++) {
- self.loginfo('checking against: ' + verified_rcpts[i].format());
if (rcpt_address.format() === verified_rcpts[i].format()) {
- self.loginfo('equal');
verified_rcpts.splice(i,1);
if (!verified_rcpts.length) {
socket.all_rcpts_done(true);
@@ -1009,7 +1006,6 @@ HMailItem.prototype.try_deliver_host = function (mx) {
}
socket.all_rcpts_done = function (success) {
- if(success) self.loginfo('All rcpts verified');
if (fail_recips.length) {
self.refcount++;
exports.split_to_new_recipients(self, fail_recips.map(map_recips), "Some recipients temporarily failed", function (hmail) {
@@ -1062,15 +1058,15 @@ HMailItem.prototype.try_deliver_host = function (mx) {
if (code.match(/^4/)) {
if (/^rcpt/.test(command) || (command === 'dot' && mx.isLMTP)) {
// 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: ' +
code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' '));
(function () {
var o = {};
o[last_recip] = code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' ');
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 {
var reason = response.join(' ');
@@ -1084,16 +1080,16 @@ HMailItem.prototype.try_deliver_host = function (mx) {
// EHLO command was rejected; fall-back to HELO
return socket.send_command('HELO', config.get('me'));
}
- if (/^rcpt/.test(command) || (command === 'dot' && mx.isLMTP)) {
- if(command === 'dot' && mx.isLMTP) last_recip = get_done_rcpt(rest);
+ if (/^rcpt/.test(command) || (command === 'dot' && self.notes.using_lmtp)) {
+ if(command === 'dot' && self.notes.using_lmtp) last_recip = get_done_rcpt(rest);
self.lognotice('recipient ' + last_recip + ' rejected: ' +
code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' '));
(function() {
var o = {};
o[last_recip] = code + ' ' + ((extc) ? extc + ' ' : '') + response.join(' ');
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 {
var reason = response.join(' ');
@@ -1132,7 +1128,7 @@ HMailItem.prototype.try_deliver_host = function (mx) {
if (last_recip && code.match(/^250/))
{
ok_recips++;
- if (mx.isLMTP) verified_rcpts.push(last_recip);
+ if (self.notes.using_lmtp) verified_rcpts.push(last_recip);
}
if (!recipients.length) {
if (ok_recips) {
View
@@ -4,18 +4,19 @@
var outbound = require('./outbound');
-//get_mx hook
exports.hook_get_mx = function (next, hmail, domain) {
- //TODO: allow arrays of mx objects; currently only one mx object per domain
- var domains_ini = this.config.get('delivery_domains.ini', 'ini');
- if (domain in domains_ini) {
- next(OK, domains_ini[domain]);
- }
- else {
- next(CONT);
- }
+ if (!hmail.todo.notes.using_lmtp) return next();
+ var config = this.config.get('lmtp.ini', 'ini');
+ var section = config[domain] || config.main;
+ var mx = {
+ priority: 0,
+ exchange: section.host || '127.0.0.1',
+ port: section.port || 24,
+ };
+ return next(OK, mx);
}
exports.hook_queue = function (next, connection) {
+ connection.transaction.notes.using_lmtp = true;
outbound.send_email(connection.transaction, next);
}

0 comments on commit 20c1866

Please sign in to comment.