Search in sources :

Example 1 with MsgContent

use of com.zimbra.soap.type.MsgContent 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)

Aggregations

Element (com.zimbra.common.soap.Element)1 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 Message (com.zimbra.cs.mailbox.Message)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 Invite (com.zimbra.cs.mailbox.calendar.Invite)1 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)1 ItemId (com.zimbra.cs.service.util.ItemId)1 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GetMsgRequest (com.zimbra.soap.mail.message.GetMsgRequest)1 MsgSpec (com.zimbra.soap.mail.type.MsgSpec)1 AttributeName (com.zimbra.soap.type.AttributeName)1 MsgContent (com.zimbra.soap.type.MsgContent)1 HashSet (java.util.HashSet)1