use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class AbstractIndexStoreTest method createContact.
private Contact createContact(Mailbox mbox, String firstName, String lastName, String email) throws ServiceException {
Folder folder = mbox.getFolderById(null, Mailbox.ID_FOLDER_CONTACTS);
Map<String, Object> fields;
fields = ImmutableMap.<String, Object>of(ContactConstants.A_firstName, firstName, ContactConstants.A_lastName, lastName, ContactConstants.A_email, email);
return mbox.createContact(null, new ParsedContact(fields), folder.getId(), null);
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ModifyContact method redo.
@Override
public void redo() throws ServiceException {
Mailbox mailbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
InputStream in = null;
try {
in = getAdditionalDataStream();
ParsedContact pc = new ParsedContact(mFields, in);
mailbox.modifyContact(getOperationContext(), mId, pc);
} catch (IOException e) {
throw ServiceException.FAILURE("Redo error", e);
} finally {
ByteUtil.closeStream(in);
}
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class AddressBookTestTest method filter.
@Test
public void filter() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
mbox.createContact(null, new ParsedContact(Collections.<String, Object>singletonMap(ContactConstants.A_email, "test1@zimbra.com")), Mailbox.ID_FOLDER_CONTACTS, null);
account.setMailSieveScript("if addressbook :in \"From\" { tag \"Priority\"; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("Priority", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ContactTest method tooLongSender.
@Test
public void tooLongSender() throws Exception {
Account account = Provisioning.getInstance().getAccountByName("testCont@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(ContactConstants.A_firstName, Strings.repeat("F", 129));
Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
DbConnection conn = DbPool.getConnection(mbox);
Assert.assertEquals(Strings.repeat("F", 128), DbUtil.executeQuery(conn, "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?", mbox.getId(), contact.getId()).getString(1));
fields.put(ContactConstants.A_firstName, null);
fields.put(ContactConstants.A_lastName, Strings.repeat("L", 129));
mbox.modifyContact(null, contact.getId(), new ParsedContact(fields));
Assert.assertEquals(Strings.repeat("L", 128), DbUtil.executeQuery(conn, "SELECT sender FROM mboxgroup1.mail_item WHERE mailbox_id = ? AND id = ?", mbox.getId(), contact.getId()).getString(1));
conn.closeQuietly();
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ContactTest method createInvalidImageAttachment.
/**
* Tests Invalid image attachment (bug 71868).
*/
@Test
public void createInvalidImageAttachment() throws Exception {
// Create a contact with an attachment.
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("fullName", "Get Attachment Content");
byte[] attachData = "attachment 1".getBytes();
Attachment attachment = new Attachment(attachData, "image/png", "image", "file1.png");
try {
ParsedContact pc = new ParsedContact(attrs, Lists.newArrayList(attachment));
Assert.fail("Expected INVALID_IMAGE exception");
} catch (ServiceException se) {
Assert.assertEquals("check the INVALID_IMAGE exception", "mail.INVALID_IMAGE", se.getCode());
}
}
Aggregations