Skip to content
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 [email protected]",
"EHLO foo",
"MAIL FROM:<[email protected]>",
"RCPT TO:<[email protected]>",
"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, "[email protected]");
test.done();
});
runClientMockup(PORT_NUMBER, "localhost", messages);
}
};

exports["Client disconnect"] = {

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