Search in sources :

Example 1 with Contact

use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.

the class ContactCSV method toCSV.

public void toCSV(String format, String locale, Character separator, Iterator<? extends MailItem> contacts, StringBuilder sb) throws ParseException, ServiceException {
    if (knownFormats == null) {
        return;
    }
    CsvFormat fmt = getFormat(format, locale);
    if (separator != null) {
        fieldSeparator = separator;
    } else {
        String delimKey = fmt.key();
        Character formatDefaultDelim = delimiterInfo.get(delimKey);
        if (formatDefaultDelim != null) {
            LOG.debug("toCSV choosing %c from <delimiter> matching %s", formatDefaultDelim, delimKey);
            fieldSeparator = formatDefaultDelim;
        }
    }
    LOG.debug("toCSV Requested=[format=\"%s\" locale=\"%s\" delim=\"%c\"] Actual=[%s delim=\"%c\"]", format, locale, separator, fmt, fieldSeparator);
    if (fmt == null) {
        return;
    }
    if (fmt.allFields()) {
        ArrayList<Map<String, String>> allContacts = new ArrayList<Map<String, String>>();
        HashSet<String> fields = new HashSet<String>();
        while (contacts.hasNext()) {
            Object obj = contacts.next();
            if (obj instanceof Contact) {
                Contact c = (Contact) obj;
                if (c.isContactGroup()) {
                    HashMap<String, String> nContacts = new HashMap<String, String>();
                    //first add all the fields and values
                    nContacts.putAll(c.getFields());
                    //remove groupMemeber
                    nContacts.remove(ContactConstants.A_groupMember);
                    //then re-calculate the dlist as in 7.X
                    ContactGroup cg = ContactGroup.init(c, false);
                    String strs = cg.migrateToDlist(mbox, octxt);
                    nContacts.put(ContactConstants.A_dlist, strs);
                    allContacts.add(nContacts);
                    fields.addAll(nContacts.keySet());
                } else {
                    allContacts.add(c.getFields());
                    fields.addAll(c.getFields().keySet());
                }
            }
        }
        ArrayList<String> allFields = new ArrayList<String>();
        allFields.addAll(fields);
        Collections.sort(allFields);
        addFieldDef(allFields, sb);
        for (Map<String, String> contactMap : allContacts) {
            toCSVContact(allFields, contactMap, sb);
        }
        return;
    }
    if (!fmt.hasNoHeaders()) {
        addFieldDef(fmt, sb);
    }
    while (contacts.hasNext()) {
        Object c = contacts.next();
        if (c instanceof Contact) {
            toCSVContact(fmt, (Contact) c, sb);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Contact(com.zimbra.cs.mailbox.Contact) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with Contact

use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.

the class ImapSession method handleModify.

private void handleModify(int changeId, Change chg, AddedItems added) {
    if (chg.what instanceof Tag && (chg.why & Change.NAME) != 0) {
        mFolder.handleTagRename(changeId, (Tag) chg.what, chg);
    } else if (chg.what instanceof Folder && ((Folder) chg.what).getId() == mFolderId) {
        Folder folder = (Folder) chg.what;
        if ((chg.why & Change.FLAGS) != 0 && (folder.getFlagBitmask() & Flag.BITMASK_DELETED) != 0) {
            //                mailbox accessed by sending a untagged BYE response."
            if (handler != null) {
                handler.close();
            }
        } else if ((chg.why & (Change.FOLDER | Change.NAME)) != 0) {
            mFolder.handleFolderRename(changeId, folder, chg);
        }
    } else if (chg.what instanceof Message || chg.what instanceof Contact) {
        MailItem item = (MailItem) chg.what;
        boolean inFolder = mIsVirtual || item.getFolderId() == mFolderId;
        if (!inFolder && (chg.why & Change.FOLDER) == 0) {
            return;
        }
        mFolder.handleItemUpdate(changeId, chg, added);
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Message(com.zimbra.cs.mailbox.Message) DirtyMessage(com.zimbra.cs.imap.ImapFolder.DirtyMessage) Tag(com.zimbra.cs.mailbox.Tag) Folder(com.zimbra.cs.mailbox.Folder) Contact(com.zimbra.cs.mailbox.Contact)

Example 3 with Contact

use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.

the class AbstractIndexStoreTest method phraseQueryWithStopWord.

@Test
public void phraseQueryWithStopWord() throws Exception {
    ZimbraLog.test.debug("--->TEST phraseQueryWithStopWord");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    createContact(mbox, "Non", "Match", "nOn.MaTchiNg@zimbra.com");
    Contact contact2 = createContact(mbox, "First", "Last", "f.last@zimbra.com", "1066 and all that with William the conqueror and others");
    createContact(mbox, "Given", "Surname", "GiV.SurN@zimbra.com");
    // Make sure all indexing has been done
    mbox.index.indexDeferredItems();
    IndexStore index = mbox.index.getIndexStore();
    ZimbraIndexSearcher searcher = index.openSearcher();
    PhraseQuery pquery = new PhraseQuery();
    // Lower case required for each term for Lucene
    pquery.add(new Term(LuceneFields.L_CONTENT, "william"));
    // pquery.add(new Term(LuceneFields.L_CONTENT, "the")); - excluded because it is a stop word
    pquery.add(new Term(LuceneFields.L_CONTENT, "conqueror"));
    ZimbraTopDocs result = searcher.search(pquery, 100);
    Assert.assertNotNull("searcher.search result object", result);
    ZimbraLog.test.debug("Result for search [hits=%d]:%s", result.getTotalHits(), result.toString());
    Assert.assertEquals("Number of hits", 1, result.getTotalHits());
    String expected1Id = String.valueOf(contact2.getId());
    String match1Id = getBlobIdForResultDoc(searcher, result, 0);
    Assert.assertEquals("Mailbox Blob ID of match", expected1Id, match1Id);
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) PhraseQuery(org.apache.lucene.search.PhraseQuery) MultiPhraseQuery(org.apache.lucene.search.MultiPhraseQuery) Term(org.apache.lucene.index.Term) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Example 4 with Contact

use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.

the class AbstractIndexStoreTest method termRangeQuery.

@Test
public void termRangeQuery() throws Exception {
    ZimbraLog.test.debug("--->TEST termRangeQuery");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Contact contact1 = createContact(mbox, "James", "Peters", "abc@zimbra.com");
    Contact contact2 = createContact(mbox, "a", "bcd", "abcd@zimbra.com");
    createContact(mbox, "aa", "bcd", "aaaa@zimbra.com");
    createContact(mbox, "aa", "bcd", "zzz@zimbra.com");
    // Make sure all indexing has been done
    mbox.index.indexDeferredItems();
    IndexStore index = mbox.index.getIndexStore();
    ZimbraIndexSearcher searcher = index.openSearcher();
    TermRangeQuery query = new TermRangeQuery(LuceneFields.L_FIELD, "email:aba@zimbra.com", "email:abz@zimbra.com", false, true);
    ZimbraTopDocs result = searcher.search(query, 100);
    Assert.assertNotNull("searcher.search result object", result);
    ZimbraLog.test.debug("Result for search %s", result.toString());
    Assert.assertEquals("Number of hits", 2, result.getTotalHits());
    List<String> expecteds = Lists.newArrayList();
    List<String> matches = Lists.newArrayList();
    matches.add(getBlobIdForResultDoc(searcher, result, 0));
    matches.add(getBlobIdForResultDoc(searcher, result, 1));
    expecteds.add(String.valueOf(contact1.getId()));
    expecteds.add(String.valueOf(contact2.getId()));
    Collections.sort(matches);
    Collections.sort(expecteds);
    Assert.assertEquals("Match Blob ID", expecteds.get(0), matches.get(0));
    Assert.assertEquals("Match Blob ID", expecteds.get(1), matches.get(1));
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Example 5 with Contact

use of com.zimbra.cs.mailbox.Contact in project zm-mailbox by Zimbra.

the class AbstractIndexStoreTest method multiPhraseQuery.

@Test
public void multiPhraseQuery() throws Exception {
    ZimbraLog.test.debug("--->TEST multiPhraseQuery");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    createContact(mbox, "Non", "Match", "nOn.MaTchiNg@zimbra.com");
    Contact contact1 = createContact(mbox, "Paul", "AA", "aa@example.net", "Software Development Engineer");
    createContact(mbox, "Jane", "BB", "bb@example.net", "Software Planning Engineer");
    Contact contact2 = createContact(mbox, "Peter", "CC", "cc@example.net", "Software Dev Engineer");
    createContact(mbox, "Avril", "DD", "dd@example.net", "Software Architectural Engineer");
    Contact contact3 = createContact(mbox, "Leo", "EE", "ee@example.net", "Software Developer Engineer");
    Contact contact4 = createContact(mbox, "Wow", "DD", "dd@example.net", "Softly Development Engineer");
    createContact(mbox, "Given", "Surname", "GiV.SurN@zimbra.com");
    // Make sure all indexing has been done
    mbox.index.indexDeferredItems();
    IndexStore index = mbox.index.getIndexStore();
    ZimbraIndexSearcher searcher = index.openSearcher();
    MultiPhraseQuery pquery = new MultiPhraseQuery();
    // Lower case required for each term for Lucene
    Term[] firstWords = { new Term(LuceneFields.L_CONTENT, "softly"), new Term(LuceneFields.L_CONTENT, "software") };
    pquery.add(firstWords);
    Term[] secondWords = { new Term(LuceneFields.L_CONTENT, "dev"), new Term(LuceneFields.L_CONTENT, "development"), new Term(LuceneFields.L_CONTENT, "developer") };
    pquery.add(secondWords);
    pquery.add(new Term(LuceneFields.L_CONTENT, "engineer"));
    ZimbraTopDocs result = searcher.search(pquery, 100);
    Assert.assertNotNull("searcher.search result object", result);
    ZimbraLog.test.debug("Result for search [hits=%d]:%s", result.getTotalHits(), result.toString());
    Assert.assertEquals("Number of hits", 4, result.getTotalHits());
    List<String> expecteds = Lists.newArrayList();
    List<String> matches = Lists.newArrayList();
    matches.add(getBlobIdForResultDoc(searcher, result, 0));
    matches.add(getBlobIdForResultDoc(searcher, result, 1));
    matches.add(getBlobIdForResultDoc(searcher, result, 2));
    matches.add(getBlobIdForResultDoc(searcher, result, 3));
    expecteds.add(String.valueOf(contact1.getId()));
    expecteds.add(String.valueOf(contact2.getId()));
    expecteds.add(String.valueOf(contact3.getId()));
    expecteds.add(String.valueOf(contact4.getId()));
    Collections.sort(matches);
    Collections.sort(expecteds);
    for (int ndx = 0; ndx < 4; ndx++) {
        Assert.assertEquals("Match Blob ID", expecteds.get(0), matches.get(0));
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) MultiPhraseQuery(org.apache.lucene.search.MultiPhraseQuery) Term(org.apache.lucene.index.Term) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Aggregations

Contact (com.zimbra.cs.mailbox.Contact)52 Mailbox (com.zimbra.cs.mailbox.Mailbox)32 ParsedContact (com.zimbra.cs.mime.ParsedContact)26 Test (org.junit.Test)23 OperationContext (com.zimbra.cs.mailbox.OperationContext)13 HashMap (java.util.HashMap)13 ZMailbox (com.zimbra.client.ZMailbox)10 ContactGroup (com.zimbra.cs.mailbox.ContactGroup)10 MailItem (com.zimbra.cs.mailbox.MailItem)10 ItemId (com.zimbra.cs.service.util.ItemId)10 ServiceException (com.zimbra.common.service.ServiceException)9 ArrayList (java.util.ArrayList)9 ZContact (com.zimbra.client.ZContact)8 Folder (com.zimbra.cs.mailbox.Folder)7 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)7 Term (org.apache.lucene.index.Term)7 Element (com.zimbra.common.soap.Element)6 Account (com.zimbra.cs.account.Account)6 Message (com.zimbra.cs.mailbox.Message)6 List (java.util.List)6