Created
April 14, 2021 14:23
-
-
Save ttsukagoshi/3cf305cef182569c681090fd50ebdf8b to your computer and use it in GitHub Desktop.
Parse the string of recipients returned by Gmail into raw email addresses. For example, if Gmail provides a recipient string in form of `George Washington <gwashington@potus.com>`, this function will return `gwashington@potus.com`
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
/** | |
* Parse the string of recipients returned by Gmail into raw email addresses. | |
* For example, if Gmail provides a recipient string in form of | |
* "George Washington <gwashington@potus.com>" | |
* this function will return | |
* "gwashington@potus.com" | |
* @param {string} gmailRecipients String of comma-separated recipients returned by GmailMessages.getTo(), .getCc(), or .getBcc() | |
* @returns The raw email addresses of gmailRecipients, without recipient name and angle brackets | |
*/ | |
function getRawEmail_(gmailRecipients) { | |
var regexp = /<([^\>]+)>/; | |
return gmailRecipients.split(',').map(recipient => { | |
let matchResult = recipient.match(regexp); | |
if (!matchResult) { | |
return recipient; | |
} else { | |
return matchResult[1]; | |
} | |
}).join(','); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment