Search in sources :

Example 16 with InternetAddress

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()]);
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ServiceException(com.zimbra.common.service.ServiceException) InternetAddress(com.zimbra.common.mime.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) LmtpAddress(com.zimbra.cs.lmtpserver.LmtpAddress) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) LinkedList(java.util.LinkedList)

Aggregations

InternetAddress (com.zimbra.common.mime.InternetAddress)16 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)6 ServiceException (com.zimbra.common.service.ServiceException)5 MimeAddressHeader (com.zimbra.common.mime.MimeAddressHeader)3 Account (com.zimbra.cs.account.Account)3 DummyMailAdapter (com.zimbra.cs.filter.DummyMailAdapter)3 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Provisioning (com.zimbra.cs.account.Provisioning)2 ParsedAddress (com.zimbra.cs.mime.ParsedAddress)2 ParsedContact (com.zimbra.cs.mime.ParsedContact)2 HashMap (java.util.HashMap)2 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 Group (com.zimbra.cs.account.Group)1 MockProvisioning (com.zimbra.cs.account.MockProvisioning)1 NamedEntry (com.zimbra.cs.account.NamedEntry)1 BrowseTerm (com.zimbra.cs.index.BrowseTerm)1 TermFieldEnumeration (com.zimbra.cs.index.ZimbraIndexReader.TermFieldEnumeration)1