Search in sources :

Example 11 with InternetAddress

use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.

the class ContactTest method existsInContacts.

@Test
public void existsInContacts() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    mbox.createContact(null, new ParsedContact(Collections.singletonMap(ContactConstants.A_email, "test1@zimbra.com")), Mailbox.ID_FOLDER_CONTACTS, null);
    MailboxTestUtil.index(mbox);
    Assert.assertTrue(mbox.index.existsInContacts(ImmutableList.of(new InternetAddress("Test <test1@zimbra.com>"), new InternetAddress("Test <test2@zimbra.com>"))));
    Assert.assertFalse(mbox.index.existsInContacts(ImmutableList.of(new InternetAddress("Test <test2@zimbra.com>"), new InternetAddress("Test <test3@zimbra.com>"))));
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Example 12 with InternetAddress

use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.

the class FolderAction method lookupEmailAddress.

public static NamedEntry lookupEmailAddress(String name) throws ServiceException {
    if (name.indexOf('<') > 0) {
        InternetAddress addr = new InternetAddress(name);
        name = addr.getAddress();
    }
    Provisioning prov = Provisioning.getInstance();
    NamedEntry nentry = prov.get(AccountBy.name, name);
    if (nentry == null) {
        nentry = prov.getGroup(Key.DistributionListBy.name, name);
    }
    return nentry;
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) InternetAddress(com.zimbra.common.mime.InternetAddress) Provisioning(com.zimbra.cs.account.Provisioning)

Example 13 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)

Example 14 with InternetAddress

use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.

the class MilterHandlerTest method testGetToCcAddressHeaderNonAscii1.

@Test
public void testGetToCcAddressHeaderNonAscii1() throws IOException {
    List<String> expctedEmails = new ArrayList<String>();
    expctedEmails.add("toadmin@example.com");
    expctedEmails.add("test@example.com");
    expctedEmails.add("test2@example.com");
    String to = "To" + '\0' + "Ré你好 <toadmin@example.com>,test@example.com,<test2@example.com>";
    MimeAddressHeader mh = MilterHandler.getToCcAddressHeader(to.getBytes("iso-8859-1"));
    Assert.assertEquals(3, mh.getAddresses().size());
    for (InternetAddress addrs : mh.getAddresses()) {
        expctedEmails.contains(addrs.getAddress());
    }
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) MimeAddressHeader(com.zimbra.common.mime.MimeAddressHeader) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with InternetAddress

use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.

the class Message method getSortRecipients.

@Override
public String getSortRecipients() {
    List<InternetAddress> iaddrs = com.zimbra.common.mime.InternetAddress.parseHeader(getRecipients());
    if (iaddrs == null || iaddrs.isEmpty()) {
        return null;
    }
    List<ParsedAddress> paddrs = new ArrayList<ParsedAddress>(iaddrs.size());
    for (InternetAddress iaddr : iaddrs) {
        paddrs.add(new ParsedAddress(iaddr));
    }
    return DbMailItem.normalize(ParsedAddress.getSortString(paddrs), DbMailItem.MAX_RECIPIENTS_LENGTH);
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) ArrayList(java.util.ArrayList) ParsedAddress(com.zimbra.cs.mime.ParsedAddress)

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