Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switch to using the Address object for all MAIL_FROM and RCPT_TO values

  • Loading branch information...
commit 3a961bccd002c3295a72bbdb4eb14c54f50865ef 1 parent 4e56f9e
@baudehlo authored
View
11 connection.js
@@ -7,6 +7,7 @@ var plugins = require('./plugins');
var constants = require('./constants');
var rfc1869 = require('./rfc1869');
var haraka = require('./haraka');
+var Address = require('./address').Address;
var line_regexp = /^([^\n]*\n)/;
@@ -445,8 +446,10 @@ Connection.prototype.cmd_help = function() {
Connection.prototype.cmd_mail = function(line) {
var results;
+ var from;
try {
results = rfc1869.parse("mail", line);
+ from = new Address (results.shift());
}
catch (err) {
if (err.stack) {
@@ -459,7 +462,6 @@ Connection.prototype.cmd_mail = function(line) {
}
this.reset_transaction();
- var from = results.shift();
this.transaction.mail_from = from;
// Get rest of key=value pairs
@@ -479,8 +481,10 @@ Connection.prototype.cmd_rcpt = function(line) {
}
var results;
+ var recip;
try {
results = rfc1869.parse("rcpt", line);
+ recip = new Address(results.shift());
}
catch (err) {
if (err.stack) {
@@ -492,8 +496,7 @@ Connection.prototype.cmd_rcpt = function(line) {
return this.respond(501, "Command parsing failed");
}
- var recipient = results.shift();
- this.transaction.rcpt_to.push(recipient);
+ this.transaction.rcpt_to.push(recip);
// Get rest of key=value pairs
var params = {};
@@ -503,7 +506,7 @@ Connection.prototype.cmd_rcpt = function(line) {
params[kv[0]] = kv[1];
});
- plugins.run_hooks('rcpt', this, [recipient, params]);
+ plugins.run_hooks('rcpt', this, [recip, params]);
};
var _daynames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
View
4 plugins/block_me.js
@@ -22,12 +22,12 @@ exports.hook_data_post = function (next, connection) {
}
// Check recipient is the right one
- if (connection.transaction.rcpt_to[0].toLowerCase() != ('<' + recip + '>')) {
+ if (connection.transaction.rcpt_to[0].address().toLowerCase() != recip) {
return next();
}
// Check sender is in list
- var sender = connection.transaction.mail_from.replace(/^</, '').replace(/>$/, '');
+ var sender = connection.transaction.mail_from.address();
if (!utils.in_array(sender, senders)) {
return next(DENY, "You are not allowed to block mail, " + sender);
}
View
2  plugins/mail_from.blocklist.js
@@ -2,7 +2,7 @@
var utils = require('./utils');
exports.hook_mail = function (next, connection, params) {
- var mail_from = params[0].replace(/^</, '').replace(/>$/, '');
+ var mail_from = params[0].address();
var list = this.config.get('mail_from.blocklist', 'list');
if (utils.in_array(mail_from, list)) {
return next(DENY, "Mail from you is not allowed here");
View
10 plugins/mail_from.is_resolvable.js
@@ -5,18 +5,14 @@ var dns = require('dns');
exports.hook_mail = function(next, connection, params) {
var mail_from = params[0];
// Check for MAIL FROM without an @ first - ignore those here
- if (!mail_from.match(/@/)) {
+ if (!mail_from.host) {
return next();
}
- var matches = mail_from.match(/@([^@>]*)>?/);
- if (!matches) {
- this.logerror("FROM address does not parse: " + mail_from);
- return next(DENY, "FROM address does not parse");
- }
- var domain = matches[1];
+ var domain = mail_from.host;
var plugin = this;
+ // TODO: this is too simple I think - needs work on handling DNS errors
dns.resolveMx(domain, function(err, addresses) {
if (err && err.code != dns.NXDOMAIN) {
plugin.logerror("DNS Error: " + err);
View
2  plugins/mail_from.nobounces.js
@@ -3,7 +3,7 @@
exports.hook_mail = function (next, connection, params) {
var mail_from = params[0];
- if (mail_from === '<>') {
+ if (mail_from.isNull()) {
return next(DENY, "No bounces accepted here");
}
return next();
View
4 plugins/queue/qmail-queue.js
@@ -38,14 +38,14 @@ exports.hook_queue = function (next, connection) {
var buf = new Buffer(4096);
var p = 0;
buf[p++] = 70;
- var mail_from = connection.transaction.mail_from.replace(/</, '').replace(/>/, '');
+ var mail_from = connection.transaction.mail_from.address();
for (var i = 0; i < mail_from.length; i++) {
buf[p++] = mail_from.charCodeAt(i);
}
buf[p++] = 0;
connection.transaction.rcpt_to.forEach(function (rcpt) {
buf[p++] = 84;
- var rcpt_to = rcpt.replace(/</, '').replace(/>/, '');
+ var rcpt_to = rcpt.address();
for (var i = 0; i < rcpt_to.length; i++) {
buf[p++] = rcpt_to.charCodeAt(i);
}
View
10 plugins/rcpt_to.in_host_list.js
@@ -3,19 +3,13 @@
exports.hook_rcpt = function(next, connection, params) {
var rcpt = params[0];
// Check for RCPT TO without an @ first - ignore those here
- if (!rcpt.match(/@/)) {
+ if (!rcpt.host) {
return next();
}
this.loginfo("Checking if " + rcpt + " host is in host_list");
- var matches = rcpt.match(/@([^@>]*)>?/);
- if (!matches) {
- this.logerror("TO address does not parse: " + rcpt);
- return next(DENY, "TO address does not parse");
- }
-
- var domain = matches[1];
+ var domain = rcpt.host;
var host_list = this.config.get('host_list', 'list');
var allow_subdomain = this.config.get('host_list.ini', 'ini').main.allow_subdomains;
View
1  plugins/relay_all.js
@@ -7,5 +7,6 @@ exports.register = function() {
exports.confirm_all = function(next, connection, params) {
var recipient = params.shift();
this.loginfo("confirming recipient " + recipient);
+ connection.relaying = 1;
next(OK);
};
View
2  plugins/spamassassin.js
@@ -86,7 +86,7 @@ exports.hook_data_post = function (next, connection) {
socket.write("SYMBOLS SPAMC/1.3\r\n", function () {
socket.write("User: " + username + "\r\n\r\n", function () {
socket.write("X-Envelope-From: " +
- connection.transaction.mail_from.replace(/</, '').replace(/>/, '')
+ connection.transaction.mail_from.address()
+ "\r\n", function ()
{
send_data();

0 comments on commit 3a961bc

Please sign in to comment.
Something went wrong with that request. Please try again.