Search in sources :

Example 1 with MailServiceException

use of com.zimbra.cs.mailbox.MailServiceException in project zm-mailbox by Zimbra.

the class SetVariableTest method testStringInterpretation.

@Test
public void testStringInterpretation() {
    try {
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        filterScript = "require [\"variables\"];\n" + "set \"a\" \"juMBlEd lETteRS\";\n" + "if header :matches \"Subject\" \"*\" {\n" + "  tag \"${d}\";\n" + "}\n";
        account.setMailSieveScript(filterScript);
        String raw = "From: sender@zimbra.com\n" + "To: test1@zimbra.com\n" + "Subject: Test\n" + "\n" + "Hello World.";
        try {
            List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
            Message msg = mbox.getMessageById(null, ids.get(0).getId());
        } catch (MailServiceException e) {
            String t = e.getArgumentValue("name");
            assertTrue(e.getCode().equals("mail.INVALID_NAME"));
            assertEquals("", t);
        }
        RuleManager.clearCachedRules(account);
        filterScript = "require [\"variables\"];\n" + "set \"a\" \"juMBlEd lETteRS\";\n" + "if header :matches \"Subject\" \"*\" {\n" + "  tag \"${}\";\n" + "}";
        account.setMailSieveScript(filterScript);
        try {
            List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        } catch (MailServiceException e) {
            String t = e.getArgumentValue("name");
            assertTrue(e.getCode().equals("mail.INVALID_NAME"));
            assertEquals("${}", t);
        }
        RuleManager.clearCachedRules(account);
        filterScript = "require [\"variables\"];\n" + "set \"ave\" \"juMBlEd lETteRS\";\n" + "if header :matches \"Subject\" \"*\" {\n" + "  tag \"${ave!}\";\n" + "}\n";
        account.setMailSieveScript(filterScript);
        try {
            List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        } catch (MailServiceException e) {
            String t = e.getArgumentValue("name");
            assertTrue(e.getCode().equals("mail.INVALID_NAME"));
            assertEquals("${ave!}", t);
        }
    } catch (Exception e) {
        fail("No exception should be thrown");
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) SyntaxException(org.apache.jsieve.exception.SyntaxException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Test(org.junit.Test)

Example 2 with MailServiceException

use of com.zimbra.cs.mailbox.MailServiceException in project zm-mailbox by Zimbra.

the class ImapCopyItem method redo.

@Override
public void redo() throws Exception {
    int mboxId = getMailboxId();
    Mailbox mbox = MailboxManager.getInstance().getMailboxById(mboxId);
    int i = 0, itemIds[] = new int[mDestIds.size()];
    for (int id : mDestIds.keySet()) {
        itemIds[i++] = id;
    }
    try {
        mbox.imapCopy(getOperationContext(), itemIds, type, mDestFolderId);
    } catch (MailServiceException e) {
        if (e.getCode() == MailServiceException.ALREADY_EXISTS) {
            mLog.info("Item is already in mailbox " + mboxId);
            return;
        } else
            throw e;
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 3 with MailServiceException

use of com.zimbra.cs.mailbox.MailServiceException in project zm-mailbox by Zimbra.

the class SaveDocument method redo.

@Override
public void redo() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
    try {
        ParsedDocument pd = new ParsedDocument(getAdditionalDataStream(), mFilename, mMimeType, System.currentTimeMillis(), mAuthor, mDescription, mDescEnabled);
        mbox.createDocument(getOperationContext(), getFolderId(), pd, type, getFlags());
    } catch (MailServiceException e) {
        if (e.getCode() == MailServiceException.ALREADY_EXISTS) {
            mLog.info("Document " + getMessageId() + " is already in mailbox " + mbox.getId());
            return;
        } else {
            throw e;
        }
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 4 with MailServiceException

use of com.zimbra.cs.mailbox.MailServiceException in project zm-mailbox by Zimbra.

the class CalSummaryCache method fetchCalendarItemData.

private static CalendarItemData fetchCalendarItemData(OperationContext octxt, Mailbox mbox, int folderId, int calItemId, long rangeStart, long rangeEnd) throws ServiceException {
    CalendarItem calItem = null;
    try {
        calItem = mbox.getCalendarItemById(octxt, calItemId);
    } catch (MailServiceException e) {
        if (!e.getCode().equals(MailServiceException.NO_SUCH_ITEM) && !e.getCode().equals(MailServiceException.NO_SUCH_APPT) && !e.getCode().equals(MailServiceException.NO_SUCH_TASK))
            throw e;
    // NO_SUCH_ITEM/APPT/TASK exception is an expected condition.  This happens when a calendar item
    // was hard deleted from a sync client.  Calendar cache doesn't process the delete notification
    // because the notification doesn't indicate which folder the item is getting deleted from.
    }
    CalendarItemData calItemData = null;
    // If folder is different, this item must have been moved out of our folder.  Ignore it.
    if (calItem != null && calItem.getFolderId() == folderId)
        calItemData = reloadCalendarItemOverRange(calItem, rangeStart, rangeEnd);
    return calItemData;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 5 with MailServiceException

use of com.zimbra.cs.mailbox.MailServiceException in project zm-mailbox by Zimbra.

the class GalSearchControl method doLocalGalAccountSync.

private void doLocalGalAccountSync(Account galAcct) throws ServiceException {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(galAcct);
    OperationContext octxt = new OperationContext(mbox);
    GalSearchResultCallback callback = mParams.getResultCallback();
    Domain domain = mParams.getDomain();
    GalMode galMode = domain.getGalMode();
    int changeId = mParams.getGalSyncToken().getChangeId(galAcct.getId());
    // bug 46608
    // sync local resources from first datasource if galMode is ldap
    // and zimbraGalAlwaysIncludeLocalCalendarResources is set for the domain
    boolean syncLocalResources = (galMode == GalMode.ldap && domain.isGalAlwaysIncludeLocalCalendarResources());
    Set<Integer> folderIds = new HashSet<Integer>();
    String syncToken = null;
    for (DataSource ds : galAcct.getAllDataSources()) {
        if (ds.getType() != DataSourceType.gal) {
            ZimbraLog.gal.trace("skipping datasource %s: wrong type %s expected %s", ds.getName(), ds.getType(), DataSourceType.gal);
            continue;
        }
        if (galMode != null) {
            if (!(galMode.isBoth() || galMode.toString().equals(ds.getAttr(Provisioning.A_zimbraGalType)))) {
                ZimbraLog.gal.debug("skipping datasource %s: wrong zimbraGalType %s expected %s", ds.getName(), ds.getAttr(Provisioning.A_zimbraGalType), galMode.toString());
                continue;
            }
        }
        int fid = ds.getFolderId();
        DataSourceItem folderMapping = DbDataSource.getMapping(ds, fid);
        if (folderMapping.md == null) {
            ZimbraLog.gal.debug("skipping datasource %s: no folder mapping", ds.getName());
            continue;
        }
        folderIds.add(fid);
        syncToken = LdapUtil.getEarlierTimestamp(syncToken, folderMapping.md.get(GalImport.SYNCTOKEN));
        if (syncLocalResources) {
            doLocalGalAccountSync(callback, mbox, octxt, changeId, folderIds, syncToken, mParams.getLimit(), Provisioning.A_zimbraAccountCalendarUserType, "RESOURCE");
            syncLocalResources = false;
        }
    }
    if (folderIds.isEmpty()) {
        throw ServiceException.FAILURE("no gal datasource with mapped folder found", null);
    }
    if (syncToken == null) {
        throw ServiceException.FAILURE("no gal datasource with sync token found", null);
    }
    doLocalGalAccountSync(callback, mbox, octxt, changeId, folderIds, syncToken, mParams.getLimit());
    List<Integer> deleted = null;
    if (callback.getResponse() != null && !callback.getResponse().getAttributeBool(MailConstants.A_QUERY_MORE) && changeId > 0) {
        try {
            deleted = mbox.getTombstones(changeId).getAllIds();
        } catch (MailServiceException e) {
            if (MailServiceException.MUST_RESYNC == e.getCode()) {
                ZimbraLog.gal.warn("sync token too old, deleted items will not be handled", e);
            } else {
                throw e;
            }
        }
    }
    if (deleted != null) {
        for (int itemId : deleted) {
            callback.handleDeleted(new ItemId(galAcct.getId(), itemId));
        }
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) GalMode(com.zimbra.common.account.ZAttrProvisioning.GalMode) ItemId(com.zimbra.cs.service.util.ItemId) DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource) Mailbox(com.zimbra.cs.mailbox.Mailbox) DataSourceItem(com.zimbra.cs.db.DbDataSource.DataSourceItem) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Domain(com.zimbra.cs.account.Domain) HashSet(java.util.HashSet)

Aggregations

MailServiceException (com.zimbra.cs.mailbox.MailServiceException)22 Mailbox (com.zimbra.cs.mailbox.Mailbox)18 OperationContext (com.zimbra.cs.mailbox.OperationContext)6 Folder (com.zimbra.cs.mailbox.Folder)4 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)4 ItemId (com.zimbra.cs.service.util.ItemId)4 ServiceException (com.zimbra.common.service.ServiceException)3 MailItem (com.zimbra.cs.mailbox.MailItem)3 ExportPeriodNotSpecifiedException (com.zimbra.cs.mailbox.MailServiceException.ExportPeriodNotSpecifiedException)3 ExportPeriodTooLongException (com.zimbra.cs.mailbox.MailServiceException.ExportPeriodTooLongException)3 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)3 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)3 UserServletException (com.zimbra.cs.service.UserServletException)3 IOException (java.io.IOException)3 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)2 Contact (com.zimbra.cs.mailbox.Contact)2 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)2 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)2 MailSender (com.zimbra.cs.mailbox.MailSender)2 SetCalendarItemData (com.zimbra.cs.mailbox.Mailbox.SetCalendarItemData)2