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>"))));
}
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;
}
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()]);
}
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());
}
}
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);
}
Aggregations