From 1ee40902cb68ff0262d124dce866afc09127c25a Mon Sep 17 00:00:00 2001 From: Mark Huetsch Date: Thu, 29 Nov 2012 03:59:43 +0800 Subject: [PATCH 1/2] Change domain to domainName. Makes the library compatible with Node 0.8.8. --- README.md | 2 +- doc/smtp.md | 2 +- lib/index.js | 2 +- lib/smtp.js | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 29ffd56..1c08b91 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Other options: + `secure`: `true`, `false`, or crypto credentials (default: `true`) + `port`: server listens on this port (default: 587 or 25) - + `domain`: the domain of the sender (default: `os.hostname()`) + + `domainName`: the domain of the sender (default: `os.hostname()`) + `mimeTransport`: `7BIT` or `8BITMIME` (default: `8BITMIME`) ### Mail.message(headers) ### diff --git a/doc/smtp.md b/doc/smtp.md index 89f79a9..5148a1d 100644 --- a/doc/smtp.md +++ b/doc/smtp.md @@ -6,7 +6,7 @@ The SMTP client library is similar in spirit to Node's `http` module. It doesn't provide safety features like address validation, header escaping, or body wrapping. The `Client` class extends `net.Stream`. -### createClient(port, host, [domain=`hostname -f`, secure=true]) ### +### createClient(port, host, [domainName=`hostname -f`, secure=true]) ### Return a new `Client` object. The `port` and `host` are required. The optional `secure` parameter can be `true`, `false`, or a crypto diff --git a/lib/index.js b/lib/index.js index e371502..030249d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,7 +20,7 @@ function Mail(opt) { return new Mail(opt); this.options = opt = opt || {}; - opt.domain = opt.domain || OS.hostname(); + opt.domainName = opt.domainName || OS.hostname(); }; Mail.prototype.message = function message(headers) { diff --git a/lib/smtp.js b/lib/smtp.js index 4d88fb9..908c90c 100644 --- a/lib/smtp.js +++ b/lib/smtp.js @@ -33,7 +33,7 @@ function Client(opt) { } this.port = opt.port || (this.useTLS ? 587 : 25); - this.domain = opt.domain; + this.domainName = opt.domainName; if (opt.username) this.setLogin(opt.username, opt.password); @@ -44,7 +44,7 @@ function Client(opt) { Client.prototype.mail = function(from, to) { var self = this; - this.domain = this.domain || OS.hostname(); + this.domainName = this.domainName || OS.hostname(); process.nextTick(function() { self.connect(); @@ -57,8 +57,8 @@ Client.prototype.mail = function(from, to) { Client.prototype.connect = function() { var self = this; - if (!this.domain) - this.emit('error', new Error('Missing required domain.')); + if (!this.domainName) + this.emit('error', new Error('Missing required domainName.')); else if (this.sock.readyState != 'closed') this.emit('error', new Error('Session already started.')); else { @@ -184,7 +184,7 @@ Client.prototype.command = function(name, args, callback) { Client.prototype.hello = function(ready) { var self = this; - self.command('ehlo', self.domain, function() { + self.command('ehlo', self.domainName, function() { U.aEach(arguments, extend, ready); }); From 6140d1e70b31d77f0794bbb986598e1cab37c35e Mon Sep 17 00:00:00 2001 From: Mark Huetsch Date: Tue, 18 Dec 2012 14:40:44 +0800 Subject: [PATCH 2/2] Allow unicode email headers (email addresses, subject lines, etc), as per RFC 6532 --- lib/util.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/util.js b/lib/util.js index f8d0a7a..1947815 100644 --- a/lib/util.js +++ b/lib/util.js @@ -48,12 +48,19 @@ function foldHeader(name, value, safe) { return result; } -// [Header Fields](http://tools.ietf.org/html/rfc5322#section-2.2) +// [Header Fields](http://tools.ietf.org/html/rfc6532#section-3.2) function escapeHeader(value, safe) { - // A header value is allowed to be a printable ASCII character, a - // tab, or a space. Anything else is elided into a safe character - // (space by default). - return value.replace(/[^ \t\w!"#\$%&'\(\)\*\+,\-\.\/:;<=>\?@\[\\\]\^`\{\|\}\~\]]+/gm, safe || ' '); + // Per RFC 5322, A header value is allowed to be a printable ASCII + // character, a tab, or a space. Anything else is elided into a + // safe character (space by default). + //return value.replace(/[^ \t\w!"#\$%&'\(\)\*\+,\-\.\/:;<=>\?@\[\\\]\^`\{\|\}\~\]]+/gm, safe || ' '); + + // Updated to with RFC 6532: + // Per the RFC Header values are now allowed to be any legal UTF-8 + // string. Javascript strings are unicode by default, so if + // something is a Javascript string, it should also be able to be + // legally encoded into UTF-8. There is nothing to escape. + return value; } // [Line Length Limits](http://tools.ietf.org/html/rfc5322#section-2.1.1) @@ -172,4 +179,4 @@ function extend(target) { } } return target; -} \ No newline at end of file +}