use of com.zimbra.cs.mime.ParsedContact 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.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ContactTest method semiColonAndCommaInName.
/**
* Bug 77746 Test that VCARD formatting escapes ';' and ',' chars which are part of name components
*/
@Test
public void semiColonAndCommaInName() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(ContactConstants.A_lastName, "Last");
fields.put(ContactConstants.A_firstName, "First ; SemiColon");
fields.put(ContactConstants.A_middleName, "Middle , Comma");
fields.put(ContactConstants.A_namePrefix, "Ms.");
Contact contact = mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
VCard vcard = VCard.formatContact(contact);
String vcardAsString = vcard.getFormatted();
String expectedPattern = "N:Last;First \\; SemiColon;Middle \\, Comma;Ms.;";
String assertMsg = String.format("Vcard\n%s\nshould contain string [%s]", vcardAsString, expectedPattern);
Assert.assertTrue(assertMsg, vcardAsString.contains(expectedPattern));
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ContactTest method getAttachmentContent.
/**
* Tests {@link Attachment#getContent()} (bug 36974).
*/
@Test
public void getAttachmentContent() 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 textAttachment = new Attachment(attachData, "text/plain", "customField", "text.txt");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
mbox.createContact(null, new ParsedContact(attrs, Lists.newArrayList(textAttachment)), Mailbox.ID_FOLDER_CONTACTS, null);
// Call getContent() on all attachments.
for (Contact contact : mbox.getContactList(null, Mailbox.ID_FOLDER_CONTACTS)) {
List<Attachment> attachments = contact.getAttachments();
for (Attachment attach : attachments) {
attach.getContent();
}
}
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ContactAction method handleContact.
private String handleContact(Map<String, Object> context, Element request, String operation) throws ServiceException, SoapFaultException {
Element action = request.getElement(MailConstants.E_ACTION);
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
// figure out which items are local and which ones are remote, and proxy accordingly
ArrayList<Integer> local = new ArrayList<Integer>();
HashMap<String, StringBuilder> remote = new HashMap<String, StringBuilder>();
partitionItems(zsc, action.getAttribute(MailConstants.A_ID), local, remote);
StringBuilder successes = proxyRemoteItems(action, remote, request, context);
if (!local.isEmpty()) {
String localResults;
if (operation.equals(OP_UPDATE)) {
// duplicating code from ItemAction.java for now...
String folderId = action.getAttribute(MailConstants.A_FOLDER, null);
ItemId iidFolder = new ItemId(folderId == null ? "-1" : folderId, zsc);
if (!iidFolder.belongsTo(mbox)) {
throw ServiceException.INVALID_REQUEST("cannot move item between mailboxes", null);
} else if (folderId != null && iidFolder.getId() <= 0) {
throw MailServiceException.NO_SUCH_FOLDER(iidFolder.getId());
}
String flags = action.getAttribute(MailConstants.A_FLAGS, null);
String[] tags = TagUtil.parseTags(action, mbox, octxt);
Color color = getColor(action);
ParsedContact pc = null;
if (!action.listElements(MailConstants.E_ATTRIBUTE).isEmpty()) {
Contact cn = local.size() == 1 ? mbox.getContactById(octxt, local.get(0)) : null;
Pair<Map<String, Object>, List<Attachment>> cdata = CreateContact.parseContact(action, zsc, octxt, cn);
pc = new ParsedContact(cdata.getFirst(), cdata.getSecond());
}
localResults = ContactActionHelper.UPDATE(zsc, octxt, mbox, local, iidFolder, flags, tags, color, pc).getResult();
} else {
throw ServiceException.INVALID_REQUEST("unknown operation: " + operation, null);
}
successes.append(successes.length() > 0 ? "," : "").append(localResults);
}
return successes.toString();
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ModifyContact method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
boolean replace = request.getAttributeBool(MailConstants.A_REPLACE, false);
boolean verbose = request.getAttributeBool(MailConstants.A_VERBOSE, true);
Element cn = request.getElement(MailConstants.E_CONTACT);
ItemId iid = new ItemId(cn.getAttribute(MailConstants.A_ID), zsc);
String tagsAttr = cn.getAttribute(MailConstants.A_TAG_NAMES, null);
String[] tags = (tagsAttr == null) ? null : TagUtil.decodeTags(tagsAttr);
Contact contact = mbox.getContactById(octxt, iid.getId());
ParsedContact pc;
if (replace) {
Pair<Map<String, Object>, List<Attachment>> cdata = CreateContact.parseContact(cn, zsc, octxt, contact);
pc = new ParsedContact(cdata.getFirst(), cdata.getSecond());
} else {
pc = CreateContact.parseContactMergeMode(cn, zsc, octxt, contact);
}
if (CreateContact.needToMigrateDlist(zsc)) {
CreateContact.migrateFromDlist(pc);
}
mbox.modifyContact(octxt, iid.getId(), pc);
if (tags != null) {
mbox.setTags(octxt, iid.getId(), MailItem.Type.CONTACT, MailItem.FLAG_UNCHANGED, tags);
}
Contact con = mbox.getContactById(octxt, iid.getId());
Element response = zsc.createElement(MailConstants.MODIFY_CONTACT_RESPONSE);
if (con != null) {
if (verbose)
ToXML.encodeContact(response, ifmt, octxt, con, true, null);
else
response.addElement(MailConstants.E_CONTACT).addAttribute(MailConstants.A_ID, con.getId());
}
return response;
}
Aggregations