Skip to content

Make library compatible with Node 0.8.8 #25

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

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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) ###
Expand Down
2 changes: 1 addition & 1 deletion doc/smtp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions lib/smtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
});

Expand Down
19 changes: 13 additions & 6 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -172,4 +179,4 @@ function extend(target) {
}
}
return target;
}
}