Permalink
Browse files

Update lib/server/proto.js

Added ehlo and starttls
  • Loading branch information...
1 parent a43b230 commit 0ed0b5471926232f764813b9f902d2f27a3c1ae4 @NodePing NodePing committed Dec 21, 2012
Showing with 42 additions and 0 deletions.
  1. +42 −0 lib/server/proto.js
View
@@ -41,6 +41,48 @@ Client.prototype.helo = function (hostname, cb) {
this.queue.push(cb);
};
+Client.prototype.ehlo = function (hostname, cb) {
+ if (typeof hostname === 'function') {
+ cb = hostname;
+ hostname = undefined;
+ }
+ this.stream.write(
+ 'EHLO'
+ + (hostname !== undefined ? ' ' + hostname : '')
+ + '\r\n'
+ );
+ this.queue.push(cb);
+};
+
+Client.prototype.starttls = function (cb) {
+ if (typeof hostname === 'function') {
+ cb = hostname;
+ hostname = undefined;
+ }
+ this.stream.write(
+ 'STARTTLS'
+ + '\r\n'
+ );
+ this.queue.push(function(err,code,lines){
+ // Upgrade connection to TLS
+ if(err){
+ cb(err, code, lines);
+ return true;
+ }
+ if(code == 220){
+ var clear = require('./starttls').starttls(Client.stream, false, function() {
+ if (!clear.authorized)
+ cb(new Error('STARTTLS: failed to secure stream'));
+ else {
+ cb(false, 220,'STARTTLS success', clear);
+ }
+ });
+ }else{
+ cb('Unable to STARTTLS', code, lines);
+ }
+ });
+};
+
Client.prototype.to = function (addr, ext, cb) {
if (typeof ext === 'function') {
cb = ext;

0 comments on commit 0ed0b54

Please sign in to comment.