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");
}
}
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;
}
}
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;
}
}
}
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;
}
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));
}
}
}
Aggregations