From e6ff44477b74f9fd7d0d335a0065f488ab173848 Mon Sep 17 00:00:00 2001 From: Christine Spang Date: Wed, 17 Apr 2013 17:28:11 -0400 Subject: [PATCH 1/5] Add support for arbitrary headers to email package. Ordering is not preserved since we're using a dictionary, but header ordering doesn't matter anyway. --- packages/email/email.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/email/email.js b/packages/email/email.js index d092305e68..985bdd4794 100644 --- a/packages/email/email.js +++ b/packages/email/email.js @@ -85,12 +85,12 @@ var smtpSend = function (mc) { * @param options.subject {String} RFC5322 "Subject:" line * @param options.text {String} RFC5322 mail body (plain text) * @param options.html {String} RFC5322 mail body (HTML) + * @param options.headers {Object} custom RFC5322 headers (dictionary) */ Email.send = function (options) { var mc = new MailComposer(); // setup message data - // XXX support arbitrary headers // XXX support attachments (once we have a client/server-compatible binary // Buffer class) mc.setMessageOption({ @@ -104,6 +104,10 @@ Email.send = function (options) { html: options.html }); + if (options.headers !== undefined) + for (var header in options.headers) + mc.addHeader(header, options.headers[header]); + maybeMakePool(); if (smtpPool) { From 0b74f9b8fa0d6f679932de9114cacbaeba9de9c8 Mon Sep 17 00:00:00 2001 From: Christine Spang Date: Wed, 17 Apr 2013 22:19:07 -0400 Subject: [PATCH 2/5] Make email tests include a custom header. I'd like to test that adding multiple headers is working fine too, but the current tests are already order-dependent. Fixing this properly would probably involve the tests depending on something like mailparser. --- packages/email/email_tests.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/email/email_tests.js b/packages/email/email_tests.js index 8327ce8aa8..b6fcf3026f 100644 --- a/packages/email/email_tests.js +++ b/packages/email/email_tests.js @@ -14,7 +14,8 @@ Tinytest.add("email - dev mode smoke test", function (test) { to: "bar@example.com", cc: ["friends@example.com", "enemies@example.com"], subject: "This is the subject", - text: "This is the body\nof the message\nFrom us." + text: "This is the body\nof the message\nFrom us.", + headers: {'X-Meteor-Test': 'a custom header'} }); // Note that we use the local "stream" here rather than Email._output_stream // in case a concurrent test run mutates Email._output_stream too. @@ -22,6 +23,7 @@ Tinytest.add("email - dev mode smoke test", function (test) { test.equal(stream.getContentsAsString("utf8"), "====== BEGIN MAIL #0 ======\n" + "MIME-Version: 1.0\r\n" + + "X-Meteor-Test: a custom header\r\n" + "From: foo@example.com\r\n" + "To: bar@example.com\r\n" + "Cc: friends@example.com, enemies@example.com\r\n" + From 17d81e64bc94da404d00cba2cc5291a3f9a40496 Mon Sep 17 00:00:00 2001 From: Christine Spang Date: Wed, 17 Apr 2013 23:14:23 -0400 Subject: [PATCH 3/5] Update documentation for Email.send. --- docs/client/api.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/client/api.js b/docs/client/api.js index cc0b3266f2..7f6bea72c2 100644 --- a/docs/client/api.js +++ b/docs/client/api.js @@ -1804,6 +1804,10 @@ Template.api.email_send = { {name: "html", type: "String", descr: rfc('mail body (HTML)') + }, + {name: "headers", + type: "Object", + descr: rfc('custom headers (dictionary)') } ] }; From bd0b88caed7b8e03da4948deb97a935d963f6e94 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Thu, 25 Apr 2013 17:06:06 -0700 Subject: [PATCH 4/5] Use underscore (to avoid prototype issues). --- packages/email/email.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/email/email.js b/packages/email/email.js index 985bdd4794..497ba51701 100644 --- a/packages/email/email.js +++ b/packages/email/email.js @@ -104,9 +104,9 @@ Email.send = function (options) { html: options.html }); - if (options.headers !== undefined) - for (var header in options.headers) - mc.addHeader(header, options.headers[header]); + _.each(options.headers, function (value, name) { + mc.addHeader(name, value); + }); maybeMakePool(); From ed4a962655b6b87433bb87995807335fc993db39 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Thu, 25 Apr 2013 17:07:16 -0700 Subject: [PATCH 5/5] update HISTORY --- History.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index c7ea3d5808..bcb2f238c3 100644 --- a/History.md +++ b/History.md @@ -14,6 +14,8 @@ * Upgrade CoffeeScript from 1.5.0 to 1.6.2. #972 +* `Email.send` has a new `headers` option to set arbitrary headers. #963 + * The `localstorage-polyfill` smart package has been replaced by a `localstorage` package, which defines a `Meteor._localStorage` API instead of trying to replace the DOM `window.localStorage` facility. (Now, apps can use @@ -22,7 +24,7 @@ * Support `appcache` on Chromium. #958 -Patches contributed by GitHub user awwx. +Patches contributed by GitHub users awwx and spang. ## v0.6.2.1