use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.
the class AddressBookTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
assert (headers != null);
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
Mailbox mbox = ((ZimbraMailAdapter) mail).getMailbox();
List<InternetAddress> addrs = new ArrayList<InternetAddress>();
for (String header : headers) {
for (String value : mail.getHeader(header)) {
addrs.add(new InternetAddress(value));
}
}
try {
return mbox.index.existsInContacts(addrs);
} catch (IOException e) {
ZimbraLog.filter.error("Failed to lookup contacts", e);
}
return false;
}
use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.
the class ContactRankingTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException {
assert (headers != null);
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
Mailbox mbox = ((ZimbraMailAdapter) mail).getMailbox();
List<InternetAddress> addrs = new ArrayList<InternetAddress>();
for (String header : headers) {
for (String value : mail.getHeader(header)) {
addrs.add(new InternetAddress(value));
}
}
try {
ContactRankings ranking = new ContactRankings(mbox.getAccountId());
for (InternetAddress addr : addrs) {
if (ranking.query(addr.getAddress()) > 0) {
return true;
}
}
} catch (ServiceException e) {
ZimbraLog.filter.error("Failed to lookup ranking", e);
}
return false;
}
use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.
the class MeTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException {
assert (headers != null);
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
Mailbox mbox = ((ZimbraMailAdapter) mail).getMailbox();
List<InternetAddress> addrs = new ArrayList<InternetAddress>();
for (String header : headers) {
for (String value : mail.getHeader(header)) {
List<InternetAddress> inetAddrs = InternetAddress.parseHeader(value);
if (inetAddrs != null) {
addrs.addAll(inetAddrs);
}
}
}
try {
Account account = mbox.getAccount();
Set<String> me = AccountUtil.getEmailAddresses(account);
me.addAll(AccountUtil.getImapPop3EmailAddresses(account));
for (InternetAddress addr : addrs) {
String email = addr.getAddress();
if (email != null && me.contains(email.toLowerCase())) {
return true;
}
}
} catch (ServiceException e) {
ZimbraLog.filter.error("Failed to lookup my addresses", e);
}
return false;
}
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 MailboxTest method createAutoContactTestWhenMaxEntriesLimitIsReached.
@Test
public void createAutoContactTestWhenMaxEntriesLimitIsReached() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Collection<InternetAddress> addrs = new ArrayList<InternetAddress>();
addrs.add(new InternetAddress("user2@email.com"));
addrs.add(new InternetAddress("user3@email.com"));
addrs.add(new InternetAddress("user4@email.com"));
Provisioning prov = Provisioning.getInstance();
Account acct1 = Provisioning.getInstance().get(Key.AccountBy.id, MockProvisioning.DEFAULT_ACCOUNT_ID);
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraContactMaxNumEntries, Integer.toString(2));
prov.modifyAttrs(acct1, attrs);
List<Contact> contactList = mbox.createAutoContact(null, addrs);
assertEquals(2, contactList.size());
attrs.put(Provisioning.A_zimbraContactMaxNumEntries, Integer.toString(10));
prov.modifyAttrs(acct1, attrs);
addrs = new ArrayList<InternetAddress>();
addrs.add(new InternetAddress("user2@email.com"));
addrs.add(new InternetAddress("user3@email.com"));
addrs.add(new InternetAddress("user4@email.com"));
contactList = mbox.createAutoContact(null, addrs);
assertEquals(3, contactList.size());
}
Aggregations