use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ContactAutoCompleteTest method dash.
@Test
public void dash() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(ContactConstants.A_firstName, "Conf - Hillview");
fields.put(ContactConstants.A_lastName, "test.server-vmware - dash");
fields.put(ContactConstants.A_email, "test@zimbra.com");
mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
ContactAutoComplete autocomplete = new ContactAutoComplete(mbox.getAccount(), new OperationContext(mbox));
Assert.assertEquals(1, autocomplete.query("conf -", null, 100).entries.size());
Assert.assertEquals(1, autocomplete.query("conf - h", null, 100).entries.size());
Assert.assertEquals(1, autocomplete.query("test.server-vmware -", null, 100).entries.size());
Assert.assertEquals(1, autocomplete.query("test.server-vmware - d", null, 100).entries.size());
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class SyncTest method tags.
@Test
public void tags() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
mbox.beginTrackingSync();
// create one tag implicitly and one explicitly
ParsedContact pc = new ParsedContact(ImmutableMap.of(ContactConstants.A_firstName, "Bob", ContactConstants.A_lastName, "Smith"));
mbox.createContact(null, pc, Mailbox.ID_FOLDER_CONTACTS, new String[] { "bar" }).getId();
int tagId = mbox.createTag(null, "foo", new Color((byte) 4)).getId();
Element request = new Element.XMLElement(MailConstants.SYNC_REQUEST);
Map<String, Object> context = new HashMap<String, Object>();
context.put(SoapEngine.ZIMBRA_CONTEXT, new ZimbraSoapContext(AuthProvider.getAuthToken(acct), acct.getId(), SoapProtocol.Soap12, SoapProtocol.Soap12));
Element response = new Sync().handle(request, context);
String token = response.getAttribute(MailConstants.A_TOKEN);
// check that only the explicitly-created tag is returned in the sync response
Element tagFolder = null;
for (Element hidden : response.getElement(MailConstants.E_FOLDER).listElements(MailConstants.E_FOLDER)) {
if (hidden.getAttribute(MailConstants.A_NAME).equals("Tags")) {
tagFolder = hidden;
break;
}
}
Assert.assertNotNull("could not find Tags folder in initial sync response", tagFolder);
Assert.assertEquals("1 tag listed", 1, tagFolder.listElements(MailConstants.E_TAG).size());
Element t = tagFolder.listElements(MailConstants.E_TAG).get(0);
Assert.assertEquals("listed tag named 'foo'", "foo", t.getAttribute(MailConstants.A_NAME));
Assert.assertEquals("correct color for tag 'foo'", 4, t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR));
// change tag color and re-sync
mbox.setColor(null, tagId, MailItem.Type.TAG, (byte) 6);
// mbox.purge(MailItem.Type.TAG);
request = new Element.XMLElement(MailConstants.SYNC_REQUEST).addAttribute(MailConstants.A_TOKEN, token);
response = new Sync().handle(request, context);
Assert.assertFalse("sync token change after tag color", token.equals(response.getAttribute(MailConstants.A_TOKEN)));
token = response.getAttribute(MailConstants.A_TOKEN);
// make sure the modified tag is returned in the sync response
t = response.getOptionalElement(MailConstants.E_TAG);
Assert.assertNotNull("modified tag missing", t);
Assert.assertEquals("new color on serialized tag", 6, t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR));
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class Contact method generateIndexData.
@Override
public List<IndexDocument> generateIndexData() throws TemporaryIndexingException {
mMailbox.lock.lock();
try {
ParsedContact pc = new ParsedContact(this);
pc.analyze(mMailbox);
if (pc.hasTemporaryAnalysisFailure()) {
throw new TemporaryIndexingException();
}
return pc.getLuceneDocuments(mMailbox);
} catch (ServiceException e) {
ZimbraLog.index.error("Failed to index contact id=%d", getId());
return Collections.emptyList();
} finally {
mMailbox.lock.release();
}
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class Contact method reanalyze.
@Override
void reanalyze(Object data, long newSize) throws ServiceException {
if (!(data instanceof ParsedContact)) {
throw ServiceException.FAILURE("cannot reanalyze non-ParsedContact object", null);
}
ParsedContact pc = (ParsedContact) data;
markItemModified(Change.CONTENT | Change.DATE | Change.FLAGS);
fields = pc.getFields();
if (fields == null || fields.isEmpty()) {
throw ServiceException.INVALID_REQUEST("contact must have fields", null);
}
attachments = pc.getAttachments();
if (attachments != null && attachments.size() > 0) {
for (Attachment attach : attachments) {
//refresh the data handler. the content rev changes which can change the blob filename/locator.
//not safe to keep old data handler that may point to old blob
attach.mDataHandler = new DataHandler(new AttachmentDataSource(this, attach.mPartName));
}
}
mData.unsetFlag(Flag.FlagInfo.ATTACHED);
if (pc.hasAttachment()) {
mData.setFlag(Flag.FlagInfo.ATTACHED);
}
saveData(new DbMailItem(mMailbox).setSender(getFileAsString(fields)));
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ImportContacts method ImportCsvContacts.
public static List<ItemId> ImportCsvContacts(OperationContext oc, Mailbox mbox, ItemId iidFolder, List<Map<String, String>> csvContacts) throws ServiceException {
List<ItemId> createdIds = new LinkedList<ItemId>();
for (Map<String, String> contact : csvContacts) {
String[] tags = TagUtil.decodeTags(ContactCSV.getTags(contact));
Contact c = mbox.createContact(oc, new ParsedContact(contact), iidFolder.getId(), tags);
createdIds.add(new ItemId(c));
ContactGroup.MigrateContactGroup mcg = new ContactGroup.MigrateContactGroup(mbox);
mcg.migrate(c);
}
return createdIds;
}
Aggregations