Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add support for formatted addresses. #43

Closed
wants to merge 10 commits into
from

Conversation

Projects
None yet
3 participants

Added support for address input in "name" <address> format.

NOTE: 3rd times the charm.. finally got the .gitattributes setup correctly, checked in the addition to .gitignore.

Michael J. Ryan added some commits Oct 16, 2012

Michael J. Ryan Add support for formatted addresses
Adding support for formatted '"name" <address>' blocks for from/to/bcc
which will convert formatted addresses into the expected format.
4adf896
Michael J. Ryan Revert "Add support for formatted addresses"
This reverts commit 4adf896.
0fbd3ed
Michael J. Ryan Add support for formatted addresses.
Add support for formatted addresses '"name" <address>' formatting.

(note: fix line endings from prior commit)
4b5e3ac
Michael J. Ryan Revert "Add support for formatted addresses."
This reverts commit 4b5e3ac.
a631065
Michael J. Ryan Add support for formatted addresses
support '"name" <address>' formatted input.

(3rd time... hopefully without the line ending problem(s)
19a9fe7
Michael J. Ryan ignore localized .gitattributes 4ace19d
Michael J. Ryan removed left over line
had ghost line in prior commit.
a56e7fb

Sorry for the sloppy commit structure... this is my first localized fork/fix/pull request.. and have been using c9 for my other github project.

@theycallmeswift theycallmeswift and 1 other commented on an outdated diff Oct 16, 2012

@@ -294,5 +297,78 @@ Email.prototype.hasFiles = function() {
return _(this.files).size() > 0;
};
+/**
+ * This method will normalize any formatted addresses ('"name" <address>')
+ */
+Email.prototype.handleFormattedAddresses = function(){
+ handleFromFmt(this);
+ handleToFmt(this);
+ handleBccFmt(this);
+}
+
+//converts a formatted from address into separate name/address parts
+function handleFromFmt(email) {
+ if (email.fromname) return; //nothing to do - already has name set
+ if (!fmt.test(email.from)) return; //nothing to do - not formatted
+ var anp = getAddressNamePair(email.from);
+console.log("FROM");
@theycallmeswift

theycallmeswift Oct 16, 2012

Contributor

These console.logs need to go

@tracker1

tracker1 Oct 16, 2012

My bad... was checking that it worked...

@theycallmeswift theycallmeswift commented on the diff Oct 16, 2012

lib/email.js
@@ -294,5 +297,78 @@ Email.prototype.hasFiles = function() {
return _(this.files).size() > 0;
};
+/**
+ * This method will normalize any formatted addresses ('"name" <address>')
+ */
+Email.prototype.handleFormattedAddresses = function(){
+ handleFromFmt(this);
+ handleToFmt(this);
+ handleBccFmt(this);
@theycallmeswift

theycallmeswift Oct 16, 2012

Contributor

Wouldn't it be easier just to check the format when they add a to, from, or bcc?

@tracker1

tracker1 Oct 16, 2012

Was thinking this could be safer, leaving it until the end, since the properties could be edited directly, as opposed to calling this before send.

@theycallmeswift theycallmeswift commented on the diff Oct 16, 2012

lib/email.js
+
+//converts a formatted from address into separate name/address parts
+function handleFromFmt(email) {
+ if (email.fromname) return; //nothing to do - already has name set
+ if (!fmt.test(email.from)) return; //nothing to do - not formatted
+ var anp = getAddressNamePair(email.from);
+console.log("FROM");
+console.dir(anp);
+ email.from = anp[0];
+ if (anp.length > 1) email.fromname = anp[1];
+}
+
+//converts any formatted bcc addresses into just the address part
+function handleBccFmt(email) {
+ if (!email.bcc) return;
+ var bcc = (email.bcc instanceof Array) ? email.bcc : [email.bcc];
@theycallmeswift

theycallmeswift Oct 16, 2012

Contributor

instanceof Array isn't reliable. Use the underscore isArray function.

Contributor

theycallmeswift commented Oct 16, 2012

Hey, thanks for your pull request. I left some initial comments that you should address. Also, we're going to need tests for this stuff before I can merge.

Michael J. Ryan added some commits Oct 19, 2012

Michael J. Ryan remove console logging 07e0309
Michael J. Ryan use underscore's _.isArray instead of instanceof 40ede25
Michael J. Ryan Added unit tests...
added unit test
added code to trim addr & name
c521639

note: I put the unit tests for this outside the rest of the email.test.js so that it could be tested distinctly, I can merge them into email.test.js if you prefer.

Just wanted to ping on this, haven't seen any feedback since the unit tests were added etc.

Contributor

motdotla commented Aug 22, 2013

Hey @tracker1, I'm sorry I've haven't gotten back on this.

Looking over things with a fresh mind, it is something we are considering. However, I think it should be something that builds upon the to array and toname array. I'm making a mental note to attack it. Until then, I am closing it.

My recommendation until then would be to write your own bit of code that splits the formatted address, and then populates the to array and toname array in the email object.

@motdotla motdotla closed this Aug 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment