Last active
November 13, 2015 19:16
-
-
Save Lewwwk/feca922f5c68175c4bf4 to your computer and use it in GitHub Desktop.
parseEmail - simple superscript plugin to parse and return an email address from an input string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var debug = require("debug")("parseEmail Plugin"); | |
var emailRegex = require("email-regex"); | |
exports.parseEmail = function(star, cb) { | |
// function to parse either a passed string or the entire message | |
var input; | |
if (typeof(star) === 'function') { | |
cb = star; | |
star = null; | |
// get 'original' message so that we don't lose .tld due to ss message processing | |
debug("No input provided. Processing original message: %s", this.message.original); | |
input = this.message.original; | |
} else { | |
debug("Using input provided: %s", star); | |
input = star; | |
} | |
var result = input.match(emailRegex()); | |
if (!result) { | |
debug("No email found."); | |
cb(null, ""); | |
} else { | |
debug("Found email: %s. Adding to message props", result); | |
this.message.props["email"] = result; | |
cb(null, ""); | |
} | |
}; |
I was using that as a generic helper that I can call whenever I need to grab an email. What I'm now trying to do is create a saveEmail plugin that calls this when I actually want to save an email. Definitely open to suggestions on better ways!
updated to handle either passed input (for if/when we can pass a wildcard) or the original message. Now adds the email to the message props instead of returning it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That looks good. I'm courious how you would use this in the actuall reply it seems a little restrictive.