Search in sources :

Example 1 with MailItemType

use of com.zimbra.common.mailbox.MailItemType in project zm-mailbox by Zimbra.

the class TestZClient method testZSearchParamsMailItemTypes.

@Test
public void testZSearchParamsMailItemTypes() throws Exception {
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_WEEK, 1);
    String msgId = TestUtil.addMessage(zmbox, "testZSearchParamsMailItemTypes message");
    ZAppointmentResult appt = TestUtil.createAppointment(zmbox, "testZSearchParamsMailItemTypes appointment", USER_NAME, new Date(), calendar.getTime());
    String apptId = appt.getCalItemId();
    Set<MailItemType> msgOnly = Sets.newHashSet(MailItemType.MESSAGE);
    Set<MailItemType> apptOnly = Sets.newHashSet(MailItemType.APPOINTMENT);
    Set<MailItemType> msgAndAppt = Sets.newHashSet(MailItemType.MESSAGE, MailItemType.APPOINTMENT);
    ZSearchParams params = new ZSearchParams("testZSearchParamsMailItemTypes");
    // search for messages only
    params.setMailItemTypes(msgOnly);
    List<ZSearchHit> results = zmbox.search(params).getHits();
    assertEquals(1, results.size());
    assertEquals(msgId, results.get(0).getId());
    // search for appointments only
    params.setMailItemTypes(apptOnly);
    results = zmbox.search(params).getHits();
    assertEquals(1, results.size());
    assertEquals(apptId, results.get(0).getId());
    // search for messages and appointments
    params.setMailItemTypes(msgAndAppt);
    results = zmbox.search(params).getHits();
    assertEquals(2, results.size());
}
Also used : ZSearchHit(com.zimbra.client.ZSearchHit) ZMailbox(com.zimbra.client.ZMailbox) ZSearchParams(com.zimbra.client.ZSearchParams) ZAppointmentResult(com.zimbra.client.ZMailbox.ZAppointmentResult) Calendar(java.util.Calendar) MailItemType(com.zimbra.common.mailbox.MailItemType) Date(java.util.Date) Test(org.junit.Test)

Example 2 with MailItemType

use of com.zimbra.common.mailbox.MailItemType in project zm-mailbox by Zimbra.

the class ImapHandler method copyOwnItems.

private void copyOwnItems(ImapMailboxStore selectedImapMboxStore, List<ImapMessage> batch, ItemId iidTarget, List<Integer> copyUIDs) throws ServiceException {
    List<Integer> copyMsgUids;
    try {
        MailItemType type = MailItemType.UNKNOWN;
        int[] mItemIds = new int[batch.size()];
        int counter = 0;
        for (ImapMessage curMsg : batch) {
            mItemIds[counter++] = curMsg.msgId;
            if (counter == 1) {
                type = curMsg.getMailItemType();
            } else if (curMsg.getMailItemType() != type) {
                type = MailItemType.UNKNOWN;
            }
        }
        // Can't use this across mailboxes as mItemIds is not mailbox aware
        copyMsgUids = selectedImapMboxStore.imapCopy(getContext(), mItemIds, type, iidTarget.getId());
    } catch (IOException e) {
        throw ServiceException.FAILURE("Caught IOException executing " + this, e);
    }
    if (copyMsgUids.size() != batch.size()) {
        throw ServiceException.FAILURE(String.format("mismatch between original (%s) and target (%s) count during IMAP COPY", batch.size(), copyMsgUids.size()), null);
    }
    if (copyUIDs != null) {
        copyUIDs.addAll(copyMsgUids);
    }
}
Also used : MailItemType(com.zimbra.common.mailbox.MailItemType) IOException(java.io.IOException)

Example 3 with MailItemType

use of com.zimbra.common.mailbox.MailItemType in project zm-mailbox by Zimbra.

the class ImapSessionManager method loadVirtualFolder.

/**
 * Fetches the messages contained within a search folder.  When a search folder is IMAP-visible, it appears in
 * folder listings, is SELECTable READ-ONLY, and appears to have all matching messages as its contents.
 * If it is not visible, it will be completely hidden from all IMAP commands.
 * @param octxt   Encapsulation of the authenticated user.
 * @param search  The search folder being exposed.
 */
private static List<ImapMessage> loadVirtualFolder(OperationContext octxt, SearchFolderStore search) throws ServiceException {
    List<ImapMessage> i4list = Lists.newArrayList();
    Set<MailItemType> types = ImapFolder.getMailItemTypeConstraint(search);
    if (types.isEmpty()) {
        return i4list;
    }
    MailboxStore mbox = search.getMailboxStore();
    ZimbraSearchParams params = mbox.createSearchParams(search.getQuery());
    params.setIncludeTagDeleted(true);
    params.setMailItemTypes(types);
    params.setZimbraSortBy(ZimbraSortBy.dateAsc);
    params.setLimit(1000);
    params.setZimbraFetchMode(ZimbraFetchMode.IMAP);
    try {
        ZimbraQueryHitResults zqr = mbox.searchImap(octxt, params);
        try {
            for (ZimbraQueryHit hit = zqr.getNext(); hit != null; hit = zqr.getNext()) {
                i4list.add(new ImapMessage(hit));
            }
        } finally {
            zqr.close();
        }
    } catch (ServiceException e) {
        throw e;
    } catch (Exception e) {
        throw ServiceException.FAILURE("failure opening search folder", e);
    }
    return i4list;
}
Also used : ZimbraQueryHitResults(com.zimbra.common.mailbox.ZimbraQueryHitResults) MailboxStore(com.zimbra.common.mailbox.MailboxStore) ZimbraSearchParams(com.zimbra.common.mailbox.ZimbraSearchParams) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZimbraQueryHit(com.zimbra.common.mailbox.ZimbraQueryHit) MailItemType(com.zimbra.common.mailbox.MailItemType) ServiceException(com.zimbra.common.service.ServiceException) MailboxInMaintenanceException(com.zimbra.cs.mailbox.MailServiceException.MailboxInMaintenanceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Aggregations

MailItemType (com.zimbra.common.mailbox.MailItemType)3 ZMailbox (com.zimbra.client.ZMailbox)1 ZAppointmentResult (com.zimbra.client.ZMailbox.ZAppointmentResult)1 ZSearchHit (com.zimbra.client.ZSearchHit)1 ZSearchParams (com.zimbra.client.ZSearchParams)1 MailboxStore (com.zimbra.common.mailbox.MailboxStore)1 ZimbraQueryHit (com.zimbra.common.mailbox.ZimbraQueryHit)1 ZimbraQueryHitResults (com.zimbra.common.mailbox.ZimbraQueryHitResults)1 ZimbraSearchParams (com.zimbra.common.mailbox.ZimbraSearchParams)1 ServiceException (com.zimbra.common.service.ServiceException)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 MailboxInMaintenanceException (com.zimbra.cs.mailbox.MailServiceException.MailboxInMaintenanceException)1 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 Test (org.junit.Test)1