Skip to content

Instantly share code, notes, and snippets.

@shanerk
Created September 13, 2019 16:39
Show Gist options
  • Save shanerk/a62029d5911b4e120373eb5c74d28e92 to your computer and use it in GitHub Desktop.
Save shanerk/a62029d5911b4e120373eb5c74d28e92 to your computer and use it in GitHub Desktop.
ParseEmailHeaders.cls
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