protected Map<String, Object> extractHeadersFromMail(Message mailMessage, Exchange exchange) throws MessagingException {
Map<String, Object> answer = new HashMap<String, Object>();
Enumeration names = mailMessage.getAllHeaders();
while (names.hasMoreElements()) {
Header header = (Header)names.nextElement();
String[] value = mailMessage.getHeader(header.getName());
if (headerFilterStrategy != null
&& !headerFilterStrategy.applyFilterToExternalHeaders(header.getName(), value, exchange)) {
// toLowerCase() for doing case insensitive search
if (value.length == 1) {
CollectionHelper.appendValue(answer, header.getName().toLowerCase(), value[0]);
} else {
CollectionHelper.appendValue(answer, header.getName().toLowerCase(), value);
}
}
}
return answer;