Permalink
Browse files

Changing the connect event to be on packet, rather then OK, as connec…

…t can return a 554 error code.

- Added 554 error code to errors.js
- Added unhandled error to errors.js
- Changed Connect to use a switch/case flow.
  • Loading branch information...
miksago committed Jan 15, 2010
1 parent da81453 commit e37deb013e80003f60946249e7e207c7ea155d50
Showing with 38 additions and 9 deletions.
  1. +31 −6 lib/smtp/client.js
  2. +7 −3 lib/smtp/errors.js
View
@@ -3,7 +3,21 @@
Author: Micheil Smith
Description:
- The SMTP Client
+ This files implements the raw protocol
+ that is SMTP. The version of SMTP used
+ is as defined in RFC2821.
+
+ Implements:
+ - SMTP: RFC821
+ - ESMTP: RFC2821
+ - SMTP Authentication: RFC4954
+ - SMTP 8Bit-Mime: RFC1652
+ - SMTP over SSL/TLS: RFC2487
+
+ Issues:
+ - SMTP over SSL/TLS does not work,
+ due to lack of TCP Client SSL/TLS
+ negotiation within node.js
===============================================*/
@@ -37,12 +51,21 @@ Client.prototype.connect = function(port, host){
this.socket = new tcp.createConnection(this.port, this.host);
this.socket.setEncoding("ascii");
- this.packetHandler.addOnce("ok", function(packet){
- if(packet.data[0].indexOf("ESMTP") > -1){
- client.esmtp = true;
+ this.packetHandler.addOnce("packet", function(packet){
+ switch(packet.status){
+ case "220":
+ if(packet.data[0].indexOf("ESMTP") > -1){
+ client.esmtp = true;
+ }
+ client.handshake();
+ break;
+ case "554":
+ throw SMTPError["554"];
+ break;
+ default:
+ throw SMTPError["unhandled"];
+ break;
}
-
- client.handshake();
});
this.socket.addListener("receive", function(data){
@@ -108,4 +131,6 @@ Client.prototype.ehlo = function(){
};
+
+
exports.Client = Client;
View
@@ -3,13 +3,17 @@
Author: Micheil Smith
Description:
- All the different client (and server)
- error codes to translate to human text.
+ Defines all the different client and
+ server error codes to translate them
+ to human text.
===============================================*/
var SMTPErrors = exports;
SMTPErrors.client = {
+ "unhandled": new Error("Received an unhandled status code"),
+ // numeric:
"504": new Error("Command parameter not implemented"),
- "550": new Error("Requested action not taken: mailbox unavailable")
+ "550": new Error("Requested action not taken: mailbox unavailable"),
+ "554": new Error("Transaction failed (Or, in the case of a connection-opening response, \"No SMTP service here\")")
};

0 comments on commit e37deb0

Please sign in to comment.