Created
September 13, 2019 16:39
-
-
Save shanerk/a62029d5911b4e120373eb5c74d28e92 to your computer and use it in GitHub Desktop.
ParseEmailHeaders.cls
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
public with sharing class ParseEmailHeaders { | |
public Map<String, String> parseEmailHeaders(String headers) { | |
Map<String, String> headersMap = new Map<String, String>(); | |
List<String> rows = headers.split('\n'); | |
for (String row : rows) { | |
Integer div = row.indexOf(':'); | |
String rowKey = row.substring(0, div).trim(); | |
String rowValue = row.substring(div + 1, row.length()).trim(); | |
String existingValue = headersMap.get(rowKey); | |
if (existingValue != null) { | |
rowValue = existingValue + '; ' + rowValue; | |
} | |
headersMap.put(rowKey, rowValue); | |
} | |
return headersMap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment