Skip to content

Commit 6816253

Browse files
committed
v0.2.2: support 8-bit mime transport
1 parent db7b3ce commit 6816253

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests:
2+
expresso test/*

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,19 @@ Use the mailer to send messages:
3737

3838
## Mail(options) ##
3939

40-
Create a new mailer that can be used to send messages. Possible
41-
settings include:
40+
Create a new mailer that can be used to send messages. Common options
41+
include:
4242

4343
+ `port`: server listens on this port (default: 587 or 25)
4444
+ `host`: server hostname
45-
+ `domain`: the domain of the sender (default: `os.hostname()`)
46-
+ `secure`: `true`, `false`, or crypto credentials (default: false)
4745
+ `username`: user for server authentication
48-
+ `password`: password for server authentication
46+
+ `password`: password for server authentication,
47+
48+
Other options:
49+
50+
+ `secure`: `true`, `false`, or crypto credentials (default: `true`)
51+
+ `domain`: the domain of the sender (default: `os.hostname()`)
52+
+ `mimeTransport`: `7BIT` or `8BITMIME` (default: `8BITMIME`)
4953

5054
### Mail.message(headers) ###
5155

@@ -77,8 +81,9 @@ version `v0.4.3`. A working subset of these RFCs are supported:
7781

7882
+ [Internet Message Format](http://tools.ietf.org/html/rfc5322)
7983
+ [Simple Mail Transfer Protocol](http://tools.ietf.org/html/rfc5321)
80-
+ [Authentication Extension](http://www.faqs.org/rfcs/rfc2554.html)
84+
+ [Authentication Extension](http://tools.ietf.org/html/rfc2554)
8185
+ [SMTP Transport Layer Security](http://tools.ietf.org/html/rfc3207)
86+
+ [8-bit MIME Transport](http://tools.ietf.org/html/rfc6152)
8287

8388
There is not currently support for MIME.
8489

lib/smtp.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Client.prototype.reset = function(wait) {
9292
var self = this,
9393
replies = [];
9494

95-
this.session = {};
95+
this.session = { use8BITMIME: undefined };
9696

9797
U.eachLine(this.sock, function(line) {
9898
var probe;
@@ -283,6 +283,30 @@ Client.prototype.authLOGIN = function(username, password, next) {
283283
return this;
284284
};
285285

286+
// ### 8BITMIME Extension ###
287+
288+
// Default to sending 8BITMIME even if the server doesn't advertise
289+
// support for it. If the server does advertise support, add BODY to
290+
// the `MAIL FROM` command.
291+
//
292+
// To require a 7BIT body, use the `mimeTransport: '7BIT` option.
293+
//
294+
// See: <http://cr.yp.to/smtp/8bitmime.html>, <http://tools.ietf.org/html/rfc6152>
295+
296+
Client.prototype.smtp8BITMIME = function(next) {
297+
this.session.use8BITMIME = true;
298+
next();
299+
};
300+
301+
Client.prototype.mimeTransport = function() {
302+
return this.session.use8BITMIME && (this.options.mimeTransport || '8BITMIME');
303+
};
304+
305+
// Only require 7bit encoding if it's explicitly requested.
306+
Client.prototype.require7Bit = function() {
307+
return this.options.mimeTransport == '7BIT';
308+
};
309+
286310

287311
// ## Reply ##
288312

@@ -328,7 +352,10 @@ function ClientTransaction(client, from, to) {
328352
client.once('ready', sendFrom);
329353

330354
function sendFrom() {
331-
client.command('mail from:', '<' + from + '>', function() {
355+
var transport = client.mimeTransport(),
356+
args = '<' + from + '>' + (transport ? ' BODY=' + transport : '');
357+
358+
client.command('mail from:', args, function() {
332359
U.aEach(to, sendTo, data);
333360
});
334361
}
@@ -357,7 +384,7 @@ ClientTransaction.prototype.write = function(data) {
357384
this.client.emit('error', new Error('The transaction has ended.'));
358385
return this;
359386
}
360-
else if ((this.session.bits != 8) && !U.is7Bit(data)) {
387+
else if (this.client.require7Bit() && !U.is7Bit(data)) {
361388
this.client.emit('error', new Error('Data must be 7-bit ASCII.'));
362389
return this;
363390
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mail",
33
"description": "This SMTP client library for Node.JS helps you send email safely and easily.",
4-
"version": "0.2.1",
4+
"version": "0.2.2",
55
"author": "Ben Weaver <[email protected]>",
66
"contributors": [],
77
"dependencies": {

0 commit comments

Comments
 (0)