Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from whiteout-io/dev/fix-signature
Browse files Browse the repository at this point in the history
fix rfc compilation
  • Loading branch information
Tankred Hase committed Mar 6, 2014
2 parents 8a8e5ab + 1a92769 commit 8e2841b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
22 changes: 9 additions & 13 deletions src/mailbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ if (typeof module === 'object' && typeof define !== 'function') {

define(function(require) {
var Mailbuilder, Node,
mimelib = require('mimelib'),
VERSION = '0.0.1',
NAME = 'mailbuilder';
mimelib = require('mimelib');

/**
* Represents a MIME node, which contains content and information about the type of content it houses.
Expand Down Expand Up @@ -82,12 +80,10 @@ define(function(require) {
line += '; ' + key + '="' + i.parameters[key] + '"';
});

line += '\r\n';
mimeLines.push(line);
});

output += mimeLines.join('');
output += '\r\n';
output += mimeLines.join('\r\n') + '\r\n';

if (content) {
if (encoding === 'quoted-printable') {
Expand All @@ -102,18 +98,19 @@ define(function(require) {
content = content.replace(/^[ ]{7}/mg, '');
}

output += content;
output += '\r\n\r\n';
output += '\r\n' + content.trim();
}

if (this.nodes.length > 0) {
output += '\r\n';
this.nodes.forEach(function(node) {
output += '--' + multipartBoundary + '\r\n';
output += node.build();
output += '--' + multipartBoundary + '\r\n' + node.build() + '\r\n';
});
output += '--' + multipartBoundary + '--' + '\r\n\r\n';
output += '--' + multipartBoundary + '--';
}

output += '\r\n';

return output;
};

Expand All @@ -122,8 +119,7 @@ define(function(require) {
*/
Mailbuilder = function() {
this.envelope = {
'MIME-Version': '1.0',
'X-Mailer': NAME + '_' + VERSION
'MIME-Version': '1.0'
};

this.from = {};
Expand Down
19 changes: 9 additions & 10 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ define(function(require) {

expect(builder).to.exist;
expect(builder.envelope['MIME-Version']).to.equal('1.0');
expect(builder.envelope['X-Mailer']).to.equal('mailbuilder_0.0.1');
expect(builder.from).to.deep.equal({});
expect(builder.to).to.deep.equal([]);
expect(builder.cc).to.deep.equal([]);
Expand All @@ -45,7 +44,7 @@ define(function(require) {
bang: 'ow'
});

expect(Object.keys(builder.envelope).length).to.equal(5);
expect(Object.keys(builder.envelope).length).to.equal(4);
});
});

Expand Down Expand Up @@ -104,7 +103,7 @@ define(function(require) {
var node = builder.createNode(mime);
node.content = 'yaddayadda';

expect(node.build()).to.equal('Content-Type: text/plain; charset="utf-8"; name="yadda.txt"\r\nContent-Transfer-Encoding: 7bit\r\nContent-Description: yadda yadda foo foo\r\nContent-Disposition: attachment; filename="yadda.txt"\r\n\r\nyaddayadda\r\n\r\n');
expect(node.build()).to.equal('Content-Type: text/plain; charset="utf-8"; name="yadda.txt"\r\nContent-Transfer-Encoding: 7bit\r\nContent-Description: yadda yadda foo foo\r\nContent-Disposition: attachment; filename="yadda.txt"\r\n\r\nyaddayadda\r\n');
});

it('should build multipart nodes correctly', function() {
Expand Down Expand Up @@ -136,7 +135,7 @@ define(function(require) {
}]);
html.content = '<div>fiifaafooo</div>';

expect(node.build()).to.equal('Content-Type: multipart/alternative; boundary="foobarfoobarfoobarfoobarfoobar"\r\n\r\n--foobarfoobarfoobarfoobarfoobar\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nyaddayadda\r\n\r\n--foobarfoobarfoobarfoobarfoobar\r\nContent-Type: text/html\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<div>fiifaafooo</div>\r\n\r\n--foobarfoobarfoobarfoobarfoobar--\r\n\r\n');
expect(node.build()).to.equal('Content-Type: multipart/alternative; boundary="foobarfoobarfoobarfoobarfoobar"\r\n\r\n--foobarfoobarfoobarfoobarfoobar\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nyaddayadda\r\n\r\n--foobarfoobarfoobarfoobarfoobar\r\nContent-Type: text/html\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<div>fiifaafooo</div>\r\n\r\n--foobarfoobarfoobarfoobarfoobar--\r\n');
});

it('should build base64 nodes correctly', function() {
Expand All @@ -151,7 +150,7 @@ define(function(require) {
}]);
node.content = 'wellthisisanincrediblylongstringprobablysomesortofstringrepresentationofabrowserthingyohmyidonotnowwhattowritehere';

expect(node.build()).to.equal('Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\n\r\nd2VsbHRoaXNpc2FuaW5jcmVkaWJseWxvbmdzdHJpbmdwcm9iYWJseXNvbWVzb3J0b2ZzdHJpbmdy\r\nZXByZXNlbnRhdGlvbm9mYWJyb3dzZXJ0aGluZ3lvaG15aWRvbm90bm93d2hhdHRvd3JpdGVoZXJl\r\n\r\n\r\n');
expect(node.build()).to.equal('Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\n\r\nd2VsbHRoaXNpc2FuaW5jcmVkaWJseWxvbmdzdHJpbmdwcm9iYWJseXNvbWVzb3J0b2ZzdHJpbmdy\r\nZXByZXNlbnRhdGlvbm9mYWJyb3dzZXJ0aGluZ3lvaG15aWRvbm90bm93d2hhdHRvd3JpdGVoZXJl\r\n');
});

it('should build base64 nodes correctly with typed arrays', function() {
Expand All @@ -166,7 +165,7 @@ define(function(require) {
}]);
node.content = str2arr('wellthisisanincrediblylongstringprobablysomesortofstringrepresentationofabrowserthingyohmyidonotnowwhattowritehere');

expect(node.build()).to.equal('Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\n\r\nd2VsbHRoaXNpc2FuaW5jcmVkaWJseWxvbmdzdHJpbmdwcm9iYWJseXNvbWVzb3J0b2ZzdHJpbmdy\r\nZXByZXNlbnRhdGlvbm9mYWJyb3dzZXJ0aGluZ3lvaG15aWRvbm90bm93d2hhdHRvd3JpdGVoZXJl\r\n\r\n\r\n');
expect(node.build()).to.equal('Content-Type: text/plain\r\nContent-Transfer-Encoding: base64\r\n\r\nd2VsbHRoaXNpc2FuaW5jcmVkaWJseWxvbmdzdHJpbmdwcm9iYWJseXNvbWVzb3J0b2ZzdHJpbmdy\r\nZXByZXNlbnRhdGlvbm9mYWJyb3dzZXJ0aGluZ3lvaG15aWRvbm90bm93d2hhdHRvd3JpdGVoZXJl\r\n');
});

it('should build quoted-printable nodes correctly', function() {
Expand All @@ -181,7 +180,7 @@ define(function(require) {
}]);
node.content = 'Interested in having a direct impact on hundreds of millions of users? Join Mozilla, and become part of a global community that’s helping to build a brighter future for the Web.';

expect(node.build()).to.equal('Content-Type: text/plain\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nInterested in having a direct impact on hundreds of millions of users=3F =\r\nJoin Mozilla, and become part of a global community that=E2=80=99s helping =\r\nto build a brighter future for the Web.\r\n\r\n');
expect(node.build()).to.equal('Content-Type: text/plain\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nInterested in having a direct impact on hundreds of millions of users=3F =\r\nJoin Mozilla, and become part of a global community that=E2=80=99s helping =\r\nto build a brighter future for the Web.\r\n');
});

it('should build nodes with other encodings with line breaks after 76 chars correctly', function() {
Expand All @@ -196,7 +195,7 @@ define(function(require) {
}]);
node.content = '1qazxsw23edcvfr45tgbnhy67ujmki89olp01qazxsw23edcvfr45tgbnhy67ujmki89olp01qazxsw23edcvfr45tgbnhy67ujmki89olp01qazxsw23edcvfr45tgbnhy67ujmki89olp0';

expect(node.build()).to.equal('Content-Type: text/plain\r\nContent-Transfer-Encoding: 7bit\r\n\r\n1qazxsw23edcvfr45tgbnhy67ujmki89olp01qazxsw23edcvfr45tgbnhy67ujmki89olp01qaz\r\nxsw23edcvfr45tgbnhy67ujmki89olp01qazxsw23edcvfr45tgbnhy67ujmki89olp0\r\n\r\n');
expect(node.build()).to.equal('Content-Type: text/plain\r\nContent-Transfer-Encoding: 7bit\r\n\r\n1qazxsw23edcvfr45tgbnhy67ujmki89olp01qazxsw23edcvfr45tgbnhy67ujmki89olp01qaz\r\nxsw23edcvfr45tgbnhy67ujmki89olp01qazxsw23edcvfr45tgbnhy67ujmki89olp0\r\n');
});
});

Expand All @@ -206,7 +205,7 @@ define(function(require) {
builder.addTo('lala@tralala.de');
builder.setSubject('¡Hola, señor!');

expect(builder.build()).to.equal('MIME-Version: 1.0\r\nX-Mailer: mailbuilder_0.0.1\r\nFrom: fred@foo.com\r\nTo: lala@tralala.de\r\nSubject: =?UTF-8?Q?=C2=A1Hola,_se=C3=B1or!?=\r\n');
expect(builder.build()).to.equal('MIME-Version: 1.0\r\nFrom: fred@foo.com\r\nTo: lala@tralala.de\r\nSubject: =?UTF-8?Q?=C2=A1Hola,_se=C3=B1or!?=\r\n');
});

it('should build nodes', function() {
Expand Down Expand Up @@ -242,7 +241,7 @@ define(function(require) {
}]);
html.content = '<div>fiifaafooo</div>';

expect(builder.build()).to.equal('MIME-Version: 1.0\r\nX-Mailer: mailbuilder_0.0.1\r\nFrom: fred@foo.com\r\nTo: lala@tralala.de\r\nSubject: Interesting subject\r\nContent-Type: multipart/alternative; boundary="foobarfoobarfoobarfoobarfoobar"\r\n\r\n--foobarfoobarfoobarfoobarfoobar\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nyaddayadda\r\n\r\n--foobarfoobarfoobarfoobarfoobar\r\nContent-Type: text/html\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<div>fiifaafooo</div>\r\n\r\n--foobarfoobarfoobarfoobarfoobar--\r\n\r\n');
expect(builder.build()).to.equal('MIME-Version: 1.0\r\nFrom: fred@foo.com\r\nTo: lala@tralala.de\r\nSubject: Interesting subject\r\nContent-Type: multipart/alternative; boundary="foobarfoobarfoobarfoobarfoobar"\r\n\r\n--foobarfoobarfoobarfoobarfoobar\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nyaddayadda\r\n\r\n--foobarfoobarfoobarfoobarfoobar\r\nContent-Type: text/html\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n<div>fiifaafooo</div>\r\n\r\n--foobarfoobarfoobarfoobarfoobar--\r\n');
});
});

Expand Down

0 comments on commit 8e2841b

Please sign in to comment.