Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support for XCLIENT extension #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,19 @@ SMTPServerConnection.prototype._onCommand = function(command, payload){
this._onCommandSTARTTLS();
break;

// Get info from proxy server
case "XCLIENT":
this._onCommandXCLIENT(payload.toString("utf-8").trim());
break;

// No operation
case "NOOP":
this._onCommandNOOP();
break;

// Display an error on anything else
default:
this.client.send("502 5.5.2 Error: command not recognized");
// this.client.send("502 5.5.2 Error: command not recognized");
}
};

Expand Down Expand Up @@ -624,6 +629,21 @@ SMTPServerConnection.prototype._onCommandEHLO = function(host){
}).join("\r\n"));
};

/**
* <p>No operation. Just returns OK.</p>
*/
SMTPServerConnection.prototype._onCommandXCLIENT = function(attributes){
var attr;
var pairs = attributes.split(" ");
var attributes_dict = {};
for (var i in pairs) {
attr = pairs[i].split("=");
attributes_dict[attr[0]] = attr[1];
}
this.envelope.xclient = attributes_dict;
this.client.send("220 success");
};

/**
* <p>No operation. Just returns OK.</p>
*/
Expand Down
41 changes: 41 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,47 @@ exports["EHLO setting"] = {
}
};

exports["XCLIENT extension"] = {
setUp: function (callback) {

this.smtp = new simplesmtp.createServer({disableDNSValidation: true});
this.smtp.listen(PORT_NUMBER, function(err){
if(err){
throw err;
}else{
callback();
}
});

},
tearDown: function (callback) {
this.smtp.end(callback);
},
"correct response": function(test) {
runClientMockup(PORT_NUMBER, "localhost", ["EHLO foo", "XCLIENT ADDR=127.0.0.2"], function(resp){
test.equal("220 success",resp.toString("utf-8").trim());
test.done();
});
},
"correct parse and save attributes": function(test) {
var messages = [
"EHLO foo",
"XCLIENT ADDR=127.0.0.1 LOGIN=user@example.org",
"EHLO foo",
"MAIL FROM:<john.doe@example.org>",
"RCPT TO:<jane.doe@example.org>",
"DATA"
]
this.smtp.on("startData", function(envelope){
test.ok("xclient" in envelope);
test.equal(envelope.xclient.ADDR, "127.0.0.1");
test.equal(envelope.xclient.LOGIN, "user@example.org");
test.done();
});
runClientMockup(PORT_NUMBER, "localhost", messages);
}
};

exports["Client disconnect"] = {

"Client disconnect": function(test){
Expand Down