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());
}
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);
}
}
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;
}
Aggregations