Search in sources :

Example 1 with AttributeName

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

the class SearchParams method parse.

/**
 * Parse the search parameters from a {@code <SearchRequest>} or similar element.
 *
 * @param request {@code <SearchRequest>} itself, or similar element ({@code <SearchConvRequest>}, etc)
 * @param requestedAccount account who's mailbox we should search in
 * @param zsc SoapContext of the request
 */
public static SearchParams parse(SearchParameters soapParams, ZimbraSoapContext zsc, String defaultQueryStr) throws ServiceException {
    SearchParams params = new SearchParams();
    params.requestContext = zsc;
    params.setHopCount(zsc.getHopCount());
    params.setCalItemExpandStart(MoreObjects.firstNonNull(soapParams.getCalItemExpandStart(), -1L));
    params.setCalItemExpandEnd(MoreObjects.firstNonNull(soapParams.getCalItemExpandEnd(), -1L));
    String query = soapParams.getQuery() == null ? defaultQueryStr : soapParams.getQuery();
    if (query == null) {
        throw ServiceException.INVALID_REQUEST("no query submitted and no default query found", null);
    }
    params.setQueryString(query);
    params.setInDumpster(MoreObjects.firstNonNull(soapParams.getInDumpster(), false));
    params.setQuick(MoreObjects.firstNonNull(soapParams.getQuick(), false));
    String types = soapParams.getSearchTypes() == null ? soapParams.getGroupBy() : soapParams.getSearchTypes();
    if (Strings.isNullOrEmpty(types)) {
        params.setTypes(EnumSet.of(params.isQuick() ? MailItem.Type.MESSAGE : MailItem.Type.CONVERSATION));
    } else {
        params.setTypes(types);
    }
    params.setSortBy(soapParams.getSortBy());
    if (soapParams.getSortBy() != null && query.toLowerCase().contains("is:unread") && isSortByReadFlag(SortBy.of(soapParams.getSortBy()))) {
        params.setSortBy(SortBy.DATE_DESC);
    } else {
        params.setSortBy(soapParams.getSortBy());
    }
    params.setIncludeTagDeleted(MoreObjects.firstNonNull(soapParams.getIncludeTagDeleted(), false));
    params.setIncludeTagMuted(MoreObjects.firstNonNull(soapParams.getIncludeTagMuted(), true));
    String allowableTasks = soapParams.getAllowableTaskStatus();
    if (allowableTasks != null) {
        params.allowableTaskStatuses = new HashSet<TaskHit.Status>();
        for (String task : Splitter.on(',').split(allowableTasks)) {
            try {
                TaskHit.Status status = TaskHit.Status.valueOf(task.toUpperCase());
                params.allowableTaskStatuses.add(status);
            } catch (IllegalArgumentException e) {
                ZimbraLog.index.debug("Skipping unknown task completion status: %s", task);
            }
        }
    }
    params.setInlineRule(ExpandResults.valueOf(soapParams.getFetch(), zsc));
    if (params.getInlineRule() != ExpandResults.NONE) {
        params.setMarkRead(MoreObjects.firstNonNull(soapParams.getMarkRead(), false));
        params.setMaxInlinedLength(MoreObjects.firstNonNull(soapParams.getMaxInlinedLength(), -1));
        params.setWantHtml(MoreObjects.firstNonNull(soapParams.getWantHtml(), false));
        params.setWantExpandGroupInfo(MoreObjects.firstNonNull(soapParams.getNeedCanExpand(), false));
        params.setNeuterImages(MoreObjects.firstNonNull(soapParams.getNeuterImages(), true));
        for (AttributeName hdr : soapParams.getHeaders()) {
            params.addInlinedHeader(hdr.getName());
        }
    }
    params.setWantRecipients(soapParams.getWantRecipients());
    CalTZInfoInterface calTZ = soapParams.getCalTz();
    if (calTZ != null) {
        params.setTimeZone(parseTimeZonePart(calTZ));
    }
    String locale = soapParams.getLocale();
    if (locale != null) {
        params.setLocale(parseLocale(locale));
    }
    params.setPrefetch(MoreObjects.firstNonNull(soapParams.getPrefetch(), true));
    String resultMode = soapParams.getResultMode();
    if (!Strings.isNullOrEmpty(resultMode)) {
        try {
            params.setFetchMode(Fetch.valueOf(resultMode.toUpperCase()));
        } catch (IllegalArgumentException e) {
            throw ServiceException.INVALID_REQUEST(String.format("Invalid %s \"%s\"", MailConstants.A_RESULT_MODE, resultMode), e);
        }
    }
    String field = params.getDefaultField();
    if (field != null) {
        params.setDefaultField(field);
    }
    params.setLimit(parseLimit(soapParams.getLimit()));
    params.setOffset(MoreObjects.firstNonNull(soapParams.getOffset(), 0));
    CursorInfo cursor = soapParams.getCursor();
    if (cursor != null) {
        params.parseCursor(cursor, zsc.getRequestedAccountId(), params);
    }
    if (soapParams instanceof MailSearchParams) {
        MailSearchParams mailParams = (MailSearchParams) soapParams;
        params.setFullConversation(ZmBoolean.toBool(mailParams.getFullConversation(), false));
        params.setWantContent(MoreObjects.firstNonNull(mailParams.getWantContent(), MsgContent.full));
        params.setIncludeMemberOf(mailParams.getIncludeMemberOf());
    }
    return params;
}
Also used : CursorInfo(com.zimbra.soap.type.CursorInfo) ZimbraSearchParams(com.zimbra.common.mailbox.ZimbraSearchParams) MailSearchParams(com.zimbra.soap.mail.type.MailSearchParams) AttributeName(com.zimbra.soap.type.AttributeName) CalTZInfoInterface(com.zimbra.soap.base.CalTZInfoInterface) MailSearchParams(com.zimbra.soap.mail.type.MailSearchParams)

Example 2 with AttributeName

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

the class GetMsg 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);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    GetMsgRequest req = zsc.elementToJaxb(request);
    MsgSpec msgSpec = req.getMsg();
    ItemId iid = new ItemId(msgSpec.getId(), zsc);
    String part = msgSpec.getPart();
    MsgContent wantContent = msgSpec.getWantContent();
    wantContent = wantContent == null ? MsgContent.full : wantContent;
    boolean raw = msgSpec.getRaw() != null ? msgSpec.getRaw() : false;
    boolean alwaysUseContentUrl = msgSpec.getUseContentUrl() != null ? msgSpec.getUseContentUrl() : false;
    boolean read = msgSpec.getMarkRead() != null ? msgSpec.getMarkRead() : false;
    int maxSize = msgSpec.getMaxInlinedLength() != null ? msgSpec.getMaxInlinedLength() : 0;
    boolean wantHTML = msgSpec.getWantHtml() != null ? msgSpec.getWantHtml() : false;
    boolean neuter = msgSpec.getNeuter() != null ? msgSpec.getNeuter() : true;
    Set<String> headers = null;
    for (AttributeName hdr : msgSpec.getHeaders()) {
        if (headers == null)
            headers = new HashSet<String>();
        headers.add(hdr.getName());
    }
    boolean needGroupInfo = msgSpec.getNeedCanExpand() != null ? msgSpec.getNeedCanExpand() : false;
    Element response = zsc.createElement(MailConstants.GET_MSG_RESPONSE);
    if (iid.hasSubpart()) {
        // calendar item
        CalendarItem calItem = getCalendarItem(octxt, mbox, iid);
        if (raw) {
            throw ServiceException.INVALID_REQUEST("Cannot request RAW formatted subpart message", null);
        } else {
            String recurIdZ = msgSpec.getRecurIdZ();
            if (recurIdZ == null) {
                // If not specified, try to get it from the Invite.
                int invId = iid.getSubpartId();
                Invite[] invs = calItem.getInvites(invId);
                if (invs.length > 0) {
                    RecurId rid = invs[0].getRecurId();
                    if (rid != null)
                        recurIdZ = rid.getDtZ();
                }
            }
            ToXML.encodeInviteAsMP(response, ifmt, octxt, calItem, recurIdZ, iid, part, maxSize, wantHTML, neuter, headers, false, needGroupInfo);
        }
    } else {
        Message msg = getMsg(octxt, mbox, iid, read);
        int fields = ToXML.NOTIFY_FIELDS;
        if (msgSpec.getWantImapUid()) {
            fields |= Change.IMAP_UID;
        }
        if (msgSpec.getWantModifiedSequence()) {
            fields |= Change.MODSEQ;
        }
        if (raw) {
            ToXML.encodeMessageAsMIME(response, ifmt, octxt, msg, part, false, /* mustInline */
            alwaysUseContentUrl, /* mustNotInline */
            false, /* serializeType */
            fields);
        } else {
            ToXML.encodeMessageAsMP(response, ifmt, octxt, msg, part, maxSize, wantHTML, neuter, headers, false, /* serializeType */
            needGroupInfo, LC.mime_encode_missing_blob.booleanValue(), wantContent, fields);
        }
    }
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Message(com.zimbra.cs.mailbox.Message) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) MsgContent(com.zimbra.soap.type.MsgContent) GetMsgRequest(com.zimbra.soap.mail.message.GetMsgRequest) Element(com.zimbra.common.soap.Element) RecurId(com.zimbra.cs.mailbox.calendar.RecurId) MsgSpec(com.zimbra.soap.mail.type.MsgSpec) ItemId(com.zimbra.cs.service.util.ItemId) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AttributeName(com.zimbra.soap.type.AttributeName) Invite(com.zimbra.cs.mailbox.calendar.Invite) HashSet(java.util.HashSet)

Example 3 with AttributeName

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

the class GetContacts 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);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    Account mRequestedAcct = getRequestedAccount(zsc);
    Account mAuthedAcct = getAuthenticatedAccount(zsc);
    GetContactsRequest req = zsc.elementToJaxb(request);
    boolean sync = req.getSync() == null ? false : req.getSync();
    boolean derefContactGroupMember = req.getDerefGroupMember();
    String folderIdStr = req.getFolderId();
    int folderId = ALL_FOLDERS;
    if (folderIdStr != null) {
        ItemId iidFolder = new ItemId(folderIdStr, zsc);
        if (iidFolder.belongsTo(mbox))
            folderId = iidFolder.getId();
        else
            throw ServiceException.FAILURE("Got remote folderId: " + folderIdStr + " but did not proxy", null);
    }
    SortBy sort = SortBy.of(req.getSortBy());
    if (sort == null) {
        sort = SortBy.NONE;
    }
    ArrayList<String> attrs = null;
    ArrayList<String> memberAttrs = null;
    ArrayList<ItemId> ids = null;
    // MailConstants.A_ATTRIBUTE_NAME
    List<AttributeName> reqAttrs = req.getAttributes();
    if (reqAttrs != null && reqAttrs.size() > 0) {
        attrs = new ArrayList<String>();
        for (AttributeName attrName : reqAttrs) {
            attrs.add(attrName.getName());
        }
    }
    // MailConstants.E_CONTACT_GROUP_MEMBER_ATTRIBUTE
    reqAttrs = req.getMemberAttributes();
    if (reqAttrs != null && reqAttrs.size() > 0) {
        memberAttrs = new ArrayList<String>();
        for (AttributeName attrName : reqAttrs) {
            memberAttrs.add(attrName.getName());
        }
    }
    // MailConstants.E_CONTACT
    List<Id> contactIds = req.getContacts();
    if (contactIds != null && contactIds.size() > 0) {
        ids = new ArrayList<ItemId>();
        for (Id target : contactIds) {
            String idStr = target.getId();
            if (idStr.indexOf(",") > 0) {
                // comma-separated IDs. TODO: deprecate this use-case
                String[] toks = idStr.split(",");
                for (int i = 0; i < toks.length; i++) {
                    ids.add(new ItemId(toks[i], zsc));
                }
            } else {
                ids.add(new ItemId(idStr, zsc));
            }
        }
    }
    long maxMembers = DEFAULT_MAX_MEMBERS;
    boolean returnHiddenAttrs = false;
    if (attrs == null) {
        returnHiddenAttrs = req.getReturnHiddenAttrs();
        maxMembers = (req.getMaxMembers() == null) ? DEFAULT_MAX_MEMBERS : req.getMaxMembers();
    }
    boolean returnCertInfo = req.getReturnCertInfo();
    Map<String, Set<String>> memberOfMap = null;
    if (req.getIncludeMemberOf()) {
        memberOfMap = ContactMemberOfMap.getMemberOfMap(mbox, octxt);
    }
    Element response = zsc.createElement(MailConstants.GET_CONTACTS_RESPONSE);
    // want to return modified date only on sync-related requests
    int fields = ToXML.NOTIFY_FIELDS;
    if (sync) {
        fields |= Change.CONFLICT;
    }
    if (req.getWantImapUid()) {
        fields |= Change.IMAP_UID;
    }
    // for perf reason, derefContactGroupMember is not supported in this mode
    if (derefContactGroupMember) {
        if (ids == null) {
            throw ServiceException.INVALID_REQUEST(MailConstants.A_DEREF_CONTACT_GROUP_MEMBER + " is supported only when specific contact ids are specified", null);
        }
    }
    if (ids != null) {
        ArrayList<Integer> local = new ArrayList<Integer>();
        HashMap<String, StringBuffer> remote = new HashMap<String, StringBuffer>();
        partitionItems(zsc, ids, local, remote);
        if (remote.size() > 0) {
            if (folderId > 0)
                throw ServiceException.INVALID_REQUEST("Cannot specify a folder with mixed-mailbox items", null);
            List<Element> responses = proxyRemote(request, remote, context);
            for (Element e : responses) response.addNonUniqueElement(e);
        }
        if (local.size() > 0) {
            boolean migrateDlist = CreateContact.needToMigrateDlist(zsc);
            for (int id : local) {
                Contact con = mbox.getContactById(octxt, id);
                if (con != null && (folderId == ALL_FOLDERS || folderId == con.getFolderId())) {
                    ContactGroup contactGroup = null;
                    String migratedDlist = null;
                    if (migrateDlist) {
                        ContactGroup cg = ContactGroup.init(con, false);
                        if (cg != null) {
                            migratedDlist = cg.migrateToDlist(con.getMailbox(), octxt);
                        }
                    } else if (derefContactGroupMember) {
                        contactGroup = ContactGroup.init(con, false);
                        if (contactGroup != null) {
                            contactGroup.derefAllMembers(con.getMailbox(), octxt, zsc.getResponseProtocol());
                        }
                    }
                    ToXML.encodeContact(response, ifmt, octxt, con, contactGroup, memberAttrs, false, /* summary */
                    attrs, fields, migratedDlist, returnHiddenAttrs, maxMembers, returnCertInfo, ContactMemberOfMap.setOfMemberOf(zsc.getRequestedAccountId(), id, memberOfMap), mRequestedAcct, mAuthedAcct);
                }
            }
        }
    } else {
        for (Contact con : mbox.getContactList(octxt, folderId, sort)) {
            if (con != null) {
                ToXML.encodeContact(response, ifmt, octxt, con, null, null, false, /* summary */
                attrs, fields, null, returnHiddenAttrs, maxMembers, returnCertInfo, ContactMemberOfMap.setOfMemberOf(zsc.getRequestedAccountId(), con.getId(), memberOfMap));
            }
        }
    }
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Set(java.util.Set) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) HashMap(java.util.HashMap) SortBy(com.zimbra.cs.index.SortBy) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) ItemId(com.zimbra.cs.service.util.ItemId) GetContactsRequest(com.zimbra.soap.mail.message.GetContactsRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) AttributeName(com.zimbra.soap.type.AttributeName) OperationContext(com.zimbra.cs.mailbox.OperationContext) Contact(com.zimbra.cs.mailbox.Contact) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Id(com.zimbra.soap.type.Id) ItemId(com.zimbra.cs.service.util.ItemId) ContactGroup(com.zimbra.cs.mailbox.ContactGroup)

Aggregations

AttributeName (com.zimbra.soap.type.AttributeName)3 Element (com.zimbra.common.soap.Element)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 ItemId (com.zimbra.cs.service.util.ItemId)2 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 ZimbraSearchParams (com.zimbra.common.mailbox.ZimbraSearchParams)1 Account (com.zimbra.cs.account.Account)1 SortBy (com.zimbra.cs.index.SortBy)1 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)1 Contact (com.zimbra.cs.mailbox.Contact)1 ContactGroup (com.zimbra.cs.mailbox.ContactGroup)1 Message (com.zimbra.cs.mailbox.Message)1 Invite (com.zimbra.cs.mailbox.calendar.Invite)1 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)1 CalTZInfoInterface (com.zimbra.soap.base.CalTZInfoInterface)1 GetContactsRequest (com.zimbra.soap.mail.message.GetContactsRequest)1 GetMsgRequest (com.zimbra.soap.mail.message.GetMsgRequest)1 MailSearchParams (com.zimbra.soap.mail.type.MailSearchParams)1