Search in sources :

Example 1 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class ProxyGroupMembership method toElement.

@Override
public Element toElement(DavContext ctxt, Element parent, boolean nameOnly) {
    Element group = super.toElement(ctxt, parent, true);
    if (nameOnly) {
        return group;
    }
    ArrayList<Pair<Mountpoint, ZFolder>> mps = getMountpoints(ctxt);
    for (Pair<Mountpoint, ZFolder> folder : mps) {
        try {
            short rights = ACL.stringToRights(folder.getSecond().getEffectivePerms());
            if ((rights & ACL.RIGHT_WRITE) > 0) {
                Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
                if (owner != null) {
                    group.addElement(DavElements.E_HREF).setText(UrlNamespace.getCalendarProxyWriteUrl(account, owner));
                }
            } else if ((rights & ACL.RIGHT_READ) > 0) {
                Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
                if (owner != null) {
                    group.addElement(DavElements.E_HREF).setText(UrlNamespace.getCalendarProxyReadUrl(account, owner));
                }
            }
        } catch (ServiceException se) {
            ZimbraLog.dav.warn("can't convert rights", se);
        }
    }
    return group;
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) Element(org.dom4j.Element) ZFolder(com.zimbra.client.ZFolder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) Pair(com.zimbra.common.util.Pair)

Example 2 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class FilterUtil method addMessage.

/**
     * Adds a message to the given folder.  Handles both local folders and mountpoints.
     * @return the id of the new message, or <tt>null</tt> if it was a duplicate
     */
public static ItemId addMessage(DeliveryContext context, Mailbox mbox, ParsedMessage pm, String recipient, String folderPath, boolean noICal, int flags, String[] tags, int convId, OperationContext octxt) throws ServiceException {
    // Do initial lookup.
    Pair<Folder, String> folderAndPath = mbox.getFolderByPathLongestMatch(octxt, Mailbox.ID_FOLDER_USER_ROOT, folderPath);
    Folder folder = folderAndPath.getFirst();
    String remainingPath = folderAndPath.getSecond();
    ZimbraLog.filter.debug("Attempting to file to %s, remainingPath=%s.", folder, remainingPath);
    if (folder instanceof Mountpoint) {
        Mountpoint mountpoint = (Mountpoint) folder;
        ZMailbox remoteMbox = getRemoteZMailbox(mbox, mountpoint);
        // Look up remote folder.
        String remoteAccountId = mountpoint.getOwnerId();
        ItemId id = mountpoint.getTarget();
        ZFolder remoteFolder = remoteMbox.getFolderById(id.toString());
        if (remoteFolder != null) {
            if (remainingPath != null) {
                remoteFolder = remoteFolder.getSubFolderByPath(remainingPath);
                if (remoteFolder == null) {
                    String msg = String.format("Subfolder %s of mountpoint %s does not exist.", remainingPath, mountpoint.getName());
                    throw ServiceException.FAILURE(msg, null);
                }
            }
        }
        // File to remote folder.
        if (remoteFolder != null) {
            byte[] content;
            try {
                content = pm.getRawData();
            } catch (Exception e) {
                throw ServiceException.FAILURE("Unable to get message content", e);
            }
            String msgId = remoteMbox.addMessage(remoteFolder.getId(), com.zimbra.cs.mailbox.Flag.toString(flags), null, 0, content, false);
            return new ItemId(msgId, remoteAccountId);
        } else {
            String msg = String.format("Unable to find remote folder %s for mountpoint %s.", remainingPath, mountpoint.getName());
            throw ServiceException.FAILURE(msg, null);
        }
    } else {
        if (!StringUtil.isNullOrEmpty(remainingPath)) {
            // Only part of the folder path matched.  Auto-create the remaining path.
            ZimbraLog.filter.info("Could not find folder %s.  Automatically creating it.", folderPath);
            folder = mbox.createFolder(octxt, folderPath, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
        }
        try {
            DeliveryOptions dopt = new DeliveryOptions().setFolderId(folder).setNoICal(noICal);
            dopt.setFlags(flags).setTags(tags).setConversationId(convId).setRecipientEmail(recipient);
            Message msg = mbox.addMessage(octxt, pm, dopt, context);
            if (msg == null) {
                return null;
            } else {
                return new ItemId(msg);
            }
        } catch (IOException e) {
            throw ServiceException.FAILURE("Unable to add message", e);
        }
    }
}
Also used : ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Message(com.zimbra.cs.mailbox.Message) SMTPMessage(com.sun.mail.smtp.SMTPMessage) MimeMessage(javax.mail.internet.MimeMessage) IOException(java.io.IOException) Folder(com.zimbra.cs.mailbox.Folder) ZFolder(com.zimbra.client.ZFolder) ItemId(com.zimbra.cs.service.util.ItemId) MessagingException(javax.mail.MessagingException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) SyntaxException(org.apache.jsieve.exception.SyntaxException) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions)

Example 3 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class TestJaxb method testGetFolderWithCacheContainingNullParent.

@Test
public void testGetFolderWithCacheContainingNullParent() throws Exception {
    TestUtil.createAccount(USER_NAME);
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder f1 = TestUtil.createFolder(zmbox, FOLDER_F1);
    ZFolder f2 = TestUtil.createFolder(zmbox, SUB_FOLDER_F2);
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    OperationContext octxt = new OperationContext(mbox);
    ItemId f1ItemId = new ItemId(mbox, Integer.parseInt(f1.getId()));
    ItemId f2ItemId = new ItemId(mbox, Integer.parseInt(f2.getId()));
    // ItemId rootItemId = new ItemId(mbox, Mailbox.ID_FOLDER_USER_ROOT);
    // mbox.getFolderTree(octxt, rootItemId, false);
    Folder f1folder = mbox.getFolderById(octxt, f1ItemId.getId());
    Folder f2folder = mbox.getFolderById(octxt, f2ItemId.getId());
    // Bug 100588 f1folder/f2folder will have been retrieved from the folder cache.  Deliberately poison it
    // by setting the parent folder to null, and ensure that can still successfully do a GetFolderRequest
    f1folder.setParent(null);
    f2folder.setParent(null);
    GetFolderResponse gfResp = zmbox.invokeJaxb(new GetFolderRequest());
    Assert.assertNotNull("GetFolderResponse null", gfResp);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) ZMailbox(com.zimbra.client.ZMailbox) GetFolderResponse(com.zimbra.soap.mail.message.GetFolderResponse) GetFolderRequest(com.zimbra.soap.mail.message.GetFolderRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) ZFolder(com.zimbra.client.ZFolder) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 4 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class TestImap method testStoreTagsDirty.

@Test
public void testStoreTagsDirty() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    List<ZTag> tags = mbox.getAllTags();
    assertTrue(tags == null || tags.size() == 0);
    String tagName = "T1";
    final String tagName2 = "T2";
    ZTag tag = mbox.getTag(tagName);
    if (tag == null) {
        tag = mbox.createTag(tagName, Color.blue);
    }
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals("T1", tags.get(0).getName());
    String folderName = "newfolder1";
    ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
    mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
    MailboxInfo info = connection.select("INBOX");
    assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
    assertFalse("INBOX contain unexpected flag " + tagName2, info.getFlags().isSet(tagName2));
    Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
    assertEquals(1, data.size());
    Iterator<Long> it = data.keySet().iterator();
    Long seq = it.next();
    assertTrue("flag not set on first message", data.get(seq).getFlags().isSet(tagName));
    ImapRequest req = connection.newRequest("STORE", seq + "", "+FLAGS", tagName2);
    req.setResponseHandler(new ResponseHandler() {

        @Override
        public void handleResponse(ImapResponse res) throws Exception {
            if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
                Flags flags = (Flags) res.getData();
                assertTrue(flags.isSet(tagName2));
            }
        }
    });
    req.sendCheckStatus();
}
Also used : ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ImapRequest(com.zimbra.cs.mailclient.imap.ImapRequest) ZTag(com.zimbra.client.ZTag) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) Flags(com.zimbra.cs.mailclient.imap.Flags) ServiceException(com.zimbra.common.service.ServiceException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Test(org.junit.Test)

Example 5 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class TestImapImport method compare.

private void compare(ZMailbox mbox1, ZFolder folder1, ZMailbox mbox2, ZFolder folder2) throws Exception {
    assertNotNull(mbox1);
    assertNotNull(folder1);
    assertNotNull(mbox2);
    assertNotNull(folder2);
    // Recursively compare children
    for (ZFolder child1 : folder1.getSubFolders()) {
        if (isMailFolder(child1)) {
            ZFolder child2 = folder2.getSubFolderByPath(child1.getName());
            String msg = String.format("Could not find folder %s/%s for %s", folder2.getPath(), child1.getName(), mbox2.getName());
            assertNotNull(msg, child2);
            compare(mbox1, child1, mbox2, child2);
        }
    }
    assertEquals("Message count doesn't match (folder1 = " + folder1 + ", folder2 = " + folder2 + ")", folder1.getMessageCount(), folder2.getMessageCount());
    // Compare folders as long as neither one is the user root
    if (!(folder1.getPath().equals("/") || folder2.getPath().equals("/"))) {
        List<ZMessage> msgs1 = TestUtil.search(mbox1, "in:" + folder1.getPath());
        List<ZMessage> msgs2 = TestUtil.search(mbox2, "in:" + folder2.getPath());
        compareMessages(msgs1, msgs2);
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFolder(com.zimbra.client.ZFolder)

Aggregations

ZFolder (com.zimbra.client.ZFolder)84 ZMailbox (com.zimbra.client.ZMailbox)54 Folder (com.zimbra.cs.mailbox.Folder)21 Test (org.junit.Test)21 ServiceException (com.zimbra.common.service.ServiceException)19 Account (com.zimbra.cs.account.Account)19 Mailbox (com.zimbra.cs.mailbox.Mailbox)17 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)17 SearchFolder (com.zimbra.cs.mailbox.SearchFolder)13 ItemId (com.zimbra.cs.service.util.ItemId)13 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)12 ZMessage (com.zimbra.client.ZMessage)10 ZMountpoint (com.zimbra.client.ZMountpoint)9 AccountServiceException (com.zimbra.cs.account.AccountServiceException)9 ZAuthToken (com.zimbra.common.auth.ZAuthToken)7 ArrayList (java.util.ArrayList)7 ZDataSource (com.zimbra.client.ZDataSource)6 ZSearchFolder (com.zimbra.client.ZSearchFolder)6 Provisioning (com.zimbra.cs.account.Provisioning)6 AuthToken (com.zimbra.cs.account.AuthToken)5