Search in sources :

Example 1 with ParsedContact

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);
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) Folder(com.zimbra.cs.mailbox.Folder)

Example 2 with ParsedContact

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);
    }
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) Mailbox(com.zimbra.cs.mailbox.Mailbox) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 3 with ParsedContact

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()));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) ParsedContact(com.zimbra.cs.mime.ParsedContact) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 4 with ParsedContact

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();
}
Also used : Account(com.zimbra.cs.account.Account) ParsedContact(com.zimbra.cs.mime.ParsedContact) HashMap(java.util.HashMap) DbConnection(com.zimbra.cs.db.DbPool.DbConnection) ParsedContact(com.zimbra.cs.mime.ParsedContact) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with ParsedContact

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());
    }
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) Attachment(com.zimbra.cs.mailbox.Contact.Attachment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ParsedContact (com.zimbra.cs.mime.ParsedContact)42 HashMap (java.util.HashMap)24 Test (org.junit.Test)23 Account (com.zimbra.cs.account.Account)18 Mailbox (com.zimbra.cs.mailbox.Mailbox)15 Contact (com.zimbra.cs.mailbox.Contact)12 OperationContext (com.zimbra.cs.mailbox.OperationContext)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 ItemId (com.zimbra.cs.service.util.ItemId)7 ServiceException (com.zimbra.common.service.ServiceException)6 Element (com.zimbra.common.soap.Element)6 ArrayList (java.util.ArrayList)6 Attachment (com.zimbra.cs.mailbox.Contact.Attachment)5 IOException (java.io.IOException)5 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 InputStream (java.io.InputStream)4 ContactGroup (com.zimbra.cs.mailbox.ContactGroup)3 Member (com.zimbra.cs.mailbox.ContactGroup.Member)3 CreateContact (com.zimbra.cs.redolog.op.CreateContact)3 ModifyContact (com.zimbra.cs.redolog.op.ModifyContact)3