use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.
the class ZimbraMailAdapter method parseAddresses.
@Override
public Address[] parseAddresses(String headerName) {
MimeMessage msg;
try {
msg = handler.getMimeMessage();
} catch (ServiceException e) {
ZimbraLog.filter.warn("Unable to get MimeMessage.", e);
return FilterAddress.EMPTY_ADDRESS_ARRAY;
}
String[] hdrValues = null;
try {
hdrValues = msg.getHeader(headerName);
} catch (MessagingException e) {
ZimbraLog.filter.warn("Unable to get headers named '%s'", headerName, e);
}
if (hdrValues == null) {
return FilterAddress.EMPTY_ADDRESS_ARRAY;
}
List<Address> retVal = new LinkedList<Address>();
for (String hdrValue : hdrValues) {
for (InternetAddress addr : InternetAddress.parseHeader(hdrValue)) {
String emailAddr = addr.getAddress();
emailAddr = StringEscapeUtils.unescapeJava(emailAddr);
if (emailAddr != null && emailAddr.contains("@"))
retVal.add(new FilterAddress(emailAddr));
}
}
return retVal.toArray(new Address[retVal.size()]);
}
Aggregations