Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Message text is not required if at least 1 attachment is inlined html #61

Merged
merged 1 commit into from

2 participants

@ruado1987

Currently it is required to specify the message text even though the message content is inlined html. This pull request eliminates this restriction by allowing message text to be undeclared if at least 1 attachment is inlined html.

@eleith
Owner

thank you very much. and a test, perfect PR

@eleith eleith merged commit 8f78dea into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 15, 2013
This page is out of date. Refresh to see the latest.
Showing with 48 additions and 10 deletions.
  1. +19 −1 smtp/client.js
  2. +29 −9 test/message.js
View
20 smtp/client.js
@@ -75,7 +75,7 @@ Client.prototype =
if(!(msg instanceof message.Message)
&& msg.from
&& (msg.to || msg.cc || msg.bcc)
- && msg.text)
+ && (msg.text || this._containsInlinedHtml(msg.attachment)))
msg = message.create(msg);
if(msg instanceof message.Message)
@@ -109,6 +109,24 @@ Client.prototype =
callback(new Error("message is not a valid Message instance"), msg);
},
+ _containsInlinedHtml: function(attachment) {
+ if (Array.isArray(attachment)) {
+ return attachment.some((function(ctx) {
+ return function(att) {
+ return ctx._isAttachmentInlinedHtml(att);
+ };
+ })(this));
+ } else {
+ return this._isAttachmentInlinedHtml(attachment);
+ }
+ },
+
+ _isAttachmentInlinedHtml: function(attachment) {
+ return attachment &&
+ (attachment.data || attachment.path) &&
+ attachment.alternative === true;
+ },
+
_sendsmtp: function(stack, next)
{
var self = this;
View
38 test/message.js
@@ -22,10 +22,10 @@ describe("messages", function()
});
});
- server.send(message, function(err)
+ server.send(message, function(err, message)
{
if(err)
- throw err;
+ throw err;
});
};
@@ -128,15 +128,14 @@ describe("messages", function()
{
subject: "this is a test TEXT+HTML+DATA message from emailjs",
from: "obama@gmail.com",
- to: "mitt@gmail.com",
- text: "hello friend if you are seeing this, you can not view html emails. it is attached inline.",
+ to: "mitt@gmail.com",
attachment: {data:html, alternative:true}
};
send(message, function(mail)
{
expect(mail.html).to.equal(html);
- expect(mail.text).to.equal(message.text + "\n");
+ expect(mail.text).to.not.equal(message.text + "\n");
expect(mail.headers.subject).to.equal(message.subject);
expect(mail.headers.from).to.equal(message.from);
expect(mail.headers.to).to.equal(message.to);
@@ -152,14 +151,13 @@ describe("messages", function()
subject: "this is a test TEXT+HTML+FILE message from emailjs",
from: "thomas@gmail.com",
to: "nikolas@gmail.com",
- text: "hello friend if you are seeing this, you can not view html emails. it is attached inline.",
attachment: {path:path.join(__dirname, "attachments/smtp.html"), alternative:true}
};
send(headers, function(mail)
{
expect(mail.html).to.equal(html);
- expect(mail.text).to.equal(headers.text + "\n");
+ expect(mail.text).to.not.equal(headers.text + "\n");
expect(mail.headers.subject).to.equal(headers.subject);
expect(mail.headers.from).to.equal(headers.from);
expect(mail.headers.to).to.equal(headers.to);
@@ -176,7 +174,6 @@ describe("messages", function()
subject: "this is a test TEXT+HTML+IMAGE message from emailjs",
from: "ninja@gmail.com",
to: "pirate@gmail.com",
- text: "hello friend if you are seeing this, you can not view html emails. it is attached inline.",
attachment:
{
path: path.join(__dirname, "attachments/smtp2.html"),
@@ -197,7 +194,7 @@ describe("messages", function()
{
expect(mail.attachments[0].content.toString("base64")).to.equal(image.toString("base64"));
expect(mail.html).to.equal(html);
- expect(mail.text).to.equal(headers.text + "\n");
+ expect(mail.text).to.not.equal(headers.text + "\n");
expect(mail.headers.subject).to.equal(headers.subject);
expect(mail.headers.from).to.equal(headers.from);
expect(mail.headers.to).to.equal(headers.to);
@@ -205,6 +202,29 @@ describe("messages", function()
});
});
+ it("html data and attachment", function(done) {
+ var html = fs.readFileSync(path.join(__dirname, "attachments/smtp.html"), "utf-8");
+ var headers =
+ {
+ subject: "this is a test TEXT+HTML+FILE message from emailjs",
+ from: "thomas@gmail.com",
+ to: "nikolas@gmail.com",
+ attachment: [
+ {path:path.join(__dirname, "attachments/smtp.html"), alternative:true},
+ {path:path.join(__dirname, "attachments/smtp.gif")}
+ ]
+ };
+
+ send(headers, function(mail) {
+ expect(mail.html).to.equal(html);
+ expect(mail.text).to.not.equal(headers.text + "\n");
+ expect(mail.headers.subject).to.equal(headers.subject);
+ expect(mail.headers.from).to.equal(headers.from);
+ expect(mail.headers.to).to.equal(headers.to);
+ done();
+ });
+ });
+
it("attachment", function(done)
{
var pdf = fs.readFileSync(path.join(__dirname, "attachments/smtp.pdf"));
Something went wrong with that request. Please try again.