Search in sources :

Example 1 with ImapCursorInfo

use of com.zimbra.soap.mail.type.ImapCursorInfo in project zm-mailbox by Zimbra.

the class ZMailbox method fetchImapFolderChunk.

@VisibleForTesting
public OpenIMAPFolderResponse fetchImapFolderChunk(OpenIMAPFolderParams params) throws ServiceException {
    OpenIMAPFolderRequest req = new OpenIMAPFolderRequest();
    req.setFolderId(params.getFolderId().toString());
    req.setLimit(params.getLimit());
    if (params.getCursorId() != null) {
        req.setCursor(new ImapCursorInfo(params.getCursorId()));
    }
    return invokeJaxb(req);
}
Also used : OpenIMAPFolderRequest(com.zimbra.soap.mail.message.OpenIMAPFolderRequest) ImapCursorInfo(com.zimbra.soap.mail.type.ImapCursorInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ImapCursorInfo

use of com.zimbra.soap.mail.type.ImapCursorInfo in project zm-mailbox by Zimbra.

the class OpenImapFolder 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);
    OpenIMAPFolderRequest req = zsc.elementToJaxb(request);
    OpenIMAPFolderResponse resp = new OpenIMAPFolderResponse();
    ItemId folderId = new ItemId(req.getFolderId(), zsc);
    if (!folderId.belongsTo(mbox)) {
        ZimbraLog.imap.info("Proxying request: OpenImapFolder folder=%s", folderId);
        return proxyRequest(request, context, folderId.getAccountId());
    }
    int limit = req.getLimit();
    ImapCursorInfo cursor = req.getCursor();
    Integer cursorMsgId = null;
    if (cursor != null) {
        cursorMsgId = new ItemId(cursor.getId(), mbox.getAccountId()).getId();
    }
    Pair<List<ImapMessage>, Boolean> openFolderResults = mbox.openImapFolder(octxt, folderId.getId(), limit, cursorMsgId);
    List<ImapMessage> msgs = openFolderResults.getFirst();
    boolean hasMore = openFolderResults.getSecond();
    Integer msgId = null;
    for (ImapMessage msg : msgs) {
        msgId = msg.getMsgId();
        int imapUid = msg.getImapUid();
        String type = msg.getType().toString();
        int flags = msg.getFlags();
        String tags = msg.getTags() == null ? null : Joiner.on(",").join(msg.getTags());
        ImapMessageInfo info = new ImapMessageInfo(msgId, imapUid, type, flags, tags);
        resp.addImapMessageInfo(info);
    }
    if (hasMore && msgId != null) {
        resp.setCursor(new ImapCursorInfo(msgId.toString()));
    }
    resp.setHasMore(hasMore);
    return zsc.jaxbToElement(resp);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) OpenIMAPFolderResponse(com.zimbra.soap.mail.message.OpenIMAPFolderResponse) ImapMessage(com.zimbra.cs.imap.ImapMessage) ItemId(com.zimbra.cs.service.util.ItemId) Mailbox(com.zimbra.cs.mailbox.Mailbox) OpenIMAPFolderRequest(com.zimbra.soap.mail.message.OpenIMAPFolderRequest) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) List(java.util.List) ImapMessageInfo(com.zimbra.soap.mail.type.ImapMessageInfo) ImapCursorInfo(com.zimbra.soap.mail.type.ImapCursorInfo)

Example 3 with ImapCursorInfo

use of com.zimbra.soap.mail.type.ImapCursorInfo in project zm-mailbox by Zimbra.

the class ZMailbox method openImapFolder.

/**
 * Iterate OpenImapFolderRequests until all results have been returned
 * @param params
 * @return
 * @throws ServiceException
 */
public List<ImapMessageInfo> openImapFolder(ItemIdentifier folderId, int chunkSize) throws ServiceException {
    List<ImapMessageInfo> msgs = new ArrayList<ImapMessageInfo>();
    String cursorId = null;
    OpenIMAPFolderResponse folderInfo = null;
    do {
        OpenIMAPFolderParams params = new OpenIMAPFolderParams(folderId);
        params.setLimit(chunkSize);
        if (cursorId != null) {
            params.setCursorId(cursorId);
        }
        folderInfo = fetchImapFolderChunk(params);
        List<ImapMessageInfo> results = folderInfo.getImapMessageInfo();
        if (results.isEmpty()) {
            break;
        } else {
            ImapCursorInfo cursor = folderInfo.getCursor();
            if (cursor == null) {
                // fall back to last message of this results page
                cursorId = String.valueOf(results.get(results.size() - 1).getId());
            } else {
                cursorId = cursor.getId();
            }
            msgs.addAll(results);
        }
    } while (folderInfo.getHasMore());
    return msgs;
}
Also used : OpenIMAPFolderResponse(com.zimbra.soap.mail.message.OpenIMAPFolderResponse) ArrayList(java.util.ArrayList) ImapMessageInfo(com.zimbra.soap.mail.type.ImapMessageInfo) ImapCursorInfo(com.zimbra.soap.mail.type.ImapCursorInfo)

Aggregations

ImapCursorInfo (com.zimbra.soap.mail.type.ImapCursorInfo)3 OpenIMAPFolderRequest (com.zimbra.soap.mail.message.OpenIMAPFolderRequest)2 OpenIMAPFolderResponse (com.zimbra.soap.mail.message.OpenIMAPFolderResponse)2 ImapMessageInfo (com.zimbra.soap.mail.type.ImapMessageInfo)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImapMessage (com.zimbra.cs.imap.ImapMessage)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 ItemId (com.zimbra.cs.service.util.ItemId)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1