Search in sources :

Example 61 with ItemIdFormatter

use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.

the class NoteAction method handleNote.

private String handleNote(Map<String, Object> context, Element request, String operation) throws ServiceException {
    Element action = request.getElement(MailConstants.E_ACTION);
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemId iid = new ItemId(action.getAttribute(MailConstants.A_ID), zsc);
    if (operation.equals(OP_EDIT)) {
        String content = action.getAttribute(MailConstants.E_CONTENT);
        mbox.editNote(octxt, iid.getId(), content);
    } else if (operation.equals(OP_REPOSITION)) {
        String strBounds = action.getAttribute(MailConstants.A_BOUNDS, null);
        mbox.repositionNote(octxt, iid.getId(), new Rectangle(strBounds));
    } else
        throw ServiceException.INVALID_REQUEST("unknown operation: " + operation, null);
    return new ItemIdFormatter(zsc).formatItemId(iid);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Mailbox(com.zimbra.cs.mailbox.Mailbox) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Rectangle(com.zimbra.cs.mailbox.Note.Rectangle) ItemId(com.zimbra.cs.service.util.ItemId)

Example 62 with ItemIdFormatter

use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.

the class ContactFolderFormatter method formatCallback.

@Override
public void formatCallback(UserServletContext context) throws UserServletException, ServiceException, IOException, ServletException {
    if (!(context.target instanceof Folder))
        throw UserServletException.notImplemented("can only handle Folders");
    Folder f = (Folder) context.target;
    if (f.getDefaultView() != MailItem.Type.CONTACT) {
        throw UserServletException.notImplemented("can only handle Contact Folders");
    }
    String v = context.params.get("t");
    Delimiter d = Delimiter.Field;
    if (v != null && v.equals("2"))
        d = Delimiter.Contact;
    v = context.params.get("all");
    boolean allContacts = false;
    if (v != null)
        allContacts = true;
    ItemIdFormatter ifmt = new ItemIdFormatter(context.getAuthAccount(), context.targetAccount, false);
    OutputStream out = new BufferedOutputStream(context.resp.getOutputStream());
    Iterator<? extends MailItem> contacts = null;
    contacts = this.getMailItems(context, 0, 0, 0);
    while (contacts.hasNext()) printContact(contacts.next(), out, ifmt, d);
    if (allContacts) {
        for (Folder folder : context.targetMailbox.getFolderList(context.opContext, SortBy.NONE)) {
            // local contact folders only
            if (folder == context.target || folder.getType() == MailItem.Type.MOUNTPOINT || folder.getDefaultView() != MailItem.Type.CONTACT) {
                continue;
            }
            for (MailItem item : this.getMailItemsFromFolder(context, folder, 0, 0, 0)) {
                printContact(item, out, ifmt, d);
            }
        }
    }
    out.flush();
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) Folder(com.zimbra.cs.mailbox.Folder) BufferedOutputStream(java.io.BufferedOutputStream)

Example 63 with ItemIdFormatter

use of com.zimbra.cs.service.util.ItemIdFormatter in project zm-mailbox by Zimbra.

the class SoapSession method putRefresh.

/** Serializes basic folder/tag structure to a SOAP response header.
     *  <p>
     *  Adds a &lt;refresh> block to the existing &lt;context> element.
     *  This &lt;refresh> block contains the basic folder, tag, and mailbox
     *  size information needed to display and update the web UI's overview
     *  pane.  The &lt;refresh> block is sent when a new session is created.
     *
     *  This API implicitly clears all cached notifications and therefore
     *  should only been used during session creation.
     * @param ctxt  An existing SOAP header <context> element
     * @param zsc   The SOAP request's encapsulated context */
public void putRefresh(Element ctxt, ZimbraSoapContext zsc) throws ServiceException {
    Mailbox mbox = mailbox;
    if (mbox == null) {
        return;
    }
    synchronized (sentChanges) {
        for (QueuedNotifications ntfn : sentChanges) {
            ntfn.clearMailboxChanges();
        }
    }
    Element eRefresh = ctxt.addUniqueElement(ZimbraNamespace.E_REFRESH);
    eRefresh.addAttribute(AccountConstants.E_VERSION, BuildInfo.FULL_VERSION, Element.Disposition.CONTENT);
    OperationContext octxt = DocumentHandler.getOperationContext(zsc, this);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    // dump current mailbox status (currently just size)
    ToXML.encodeMailbox(eRefresh, octxt, mbox);
    // dump all tags under a single <tags> parent
    List<Tag> tags = mbox.getTagList(octxt);
    if (tags != null && tags.size() > 0) {
        Element eTags = eRefresh.addUniqueElement(ZimbraNamespace.E_TAGS);
        for (Tag tag : tags) {
            if (tag != null && !(tag instanceof Flag)) {
                ToXML.encodeTag(eTags, ifmt, octxt, tag);
            }
        }
    }
    // first, get the user's folder hierarchy
    FolderNode root = mbox.getFolderTree(octxt, null, false);
    OperationContextData.setNeedGranteeName(octxt, false);
    GetFolder.encodeFolderNode(root, eRefresh, ifmt, octxt);
    // The Boolean of the Pair indicates whether the mountpoint is found to be broken
    Map<ItemId, Pair<Boolean, Element>> mountpoints = new HashMap<ItemId, Pair<Boolean, Element>>();
    // for mountpoints pointing to this host, get the serialized folder subhierarchy
    expandLocalMountpoints(octxt, root, eRefresh.getFactory(), mountpoints);
    // for mountpoints pointing to other hosts, get the folder structure from the remote server
    expandRemoteMountpoints(octxt, zsc, mountpoints);
    // graft in subfolder trees from the other user's mailbox, making sure that mountpoints reflect the counts (etc.) of the target folder
    if (!mountpoints.isEmpty()) {
        transferMountpointContents(eRefresh.getOptionalElement(MailConstants.E_FOLDER), octxt, mountpoints);
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) FolderNode(com.zimbra.cs.mailbox.Mailbox.FolderNode) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) Flag(com.zimbra.cs.mailbox.Flag) ItemId(com.zimbra.cs.service.util.ItemId) Mailbox(com.zimbra.cs.mailbox.Mailbox) Tag(com.zimbra.cs.mailbox.Tag) Pair(com.zimbra.common.util.Pair)

Aggregations

ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)63 Element (com.zimbra.common.soap.Element)56 Mailbox (com.zimbra.cs.mailbox.Mailbox)48 OperationContext (com.zimbra.cs.mailbox.OperationContext)46 ItemId (com.zimbra.cs.service.util.ItemId)44 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)44 Account (com.zimbra.cs.account.Account)21 ServiceException (com.zimbra.common.service.ServiceException)16 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)14 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)11 Folder (com.zimbra.cs.mailbox.Folder)11 Message (com.zimbra.cs.mailbox.Message)11 HashMap (java.util.HashMap)11 MailItem (com.zimbra.cs.mailbox.MailItem)10 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)8 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 MessagingException (javax.mail.MessagingException)7 MimeMessage (javax.mail.internet.MimeMessage)7