Created
October 23, 2013 14:22
-
-
Save mguilherme/7119758 to your computer and use it in GitHub Desktop.
Extract Mail Recipients (name and mail) from a given String
This file contains hidden or 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
| public Map<String, String> extractRecipients(String content) { | |
| content = StringEscapeUtils.unescapeXml(content); | |
| Map<String, String> recipients = new HashMap<>(); | |
| Pattern pattern = Pattern.compile("(.*?)<([^>]+)>\\s*;?,?", Pattern.DOTALL); | |
| Matcher matcher = pattern.matcher(content); | |
| while(matcher.find()) { | |
| String name = matcher.group(1).replaceAll("[\\n\\r\"]+", "").trim(); | |
| String email = matcher.group(2).replaceAll("[\\n\\r\\s\"]+", "").trim(); | |
| recipients.put(name, email); | |
| } | |
| return recipients; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment