use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class ZMailboxUtil method execute.
public ExecuteStatus execute(String[] argsIn) throws ServiceException, IOException {
mCommand = lookupCommand(argsIn[0]);
// shift them over for parser
String[] args = new String[argsIn.length - 1];
System.arraycopy(argsIn, 1, args, 0, args.length);
if (mCommand == null)
throw ZClientException.CLIENT_ERROR("Unknown command: (" + argsIn[0] + ") Type: 'help commands' for a list", null);
try {
mCommandLine = mParser.parse(mCommand.getOptions(), args, true);
args = mCommandLine.getArgs();
} catch (ParseException e) {
usage();
return ExecuteStatus.OK;
}
if (!mCommand.checkArgsLength(args)) {
usage();
return ExecuteStatus.OK;
}
if (mCommand != Command.EXIT && mCommand != Command.HELP && mCommand != Command.AUTHENTICATE && mCommand != Command.ADMIN_AUTHENTICATE && mCommand != Command.SELECT_MAILBOX && mCommand != Command.WHOAMI) {
if (mMbox == null) {
throw ZClientException.CLIENT_ERROR("no mailbox opened. select one with authenticate/adminAuthenticate/selectMailbox", null);
}
}
switch(mCommand) {
case AUTO_COMPLETE:
doAutoComplete(args);
break;
case AUTO_COMPLETE_GAL:
doAutoCompleteGal(args);
break;
case AUTHENTICATE:
doAuth(args);
break;
case ADD_INCOMING_FILTER_RULE:
doAddIncomingFilterRule(args);
break;
case ADD_OUTGOING_FILTER_RULE:
doAddOutgoingFilterRule(args);
break;
case ADD_MESSAGE:
doAddMessage(args);
break;
case ADMIN_AUTHENTICATE:
doAdminAuth(args);
break;
case CHECK_RIGHT:
doCheckRight(args);
break;
case CREATE_CONTACT:
String ccId = mMbox.createContact(lookupFolderId(folderOpt()), tagsOpt(), getContactMap(args, 0, !ignoreOpt())).getId();
stdout.println(ccId);
break;
case CREATE_IDENTITY:
mMbox.createIdentity(new ZIdentity(args[0], getMultiMap(args, 1)));
break;
case CREATE_FOLDER:
doCreateFolder(args);
break;
case CREATE_MOUNTPOINT:
doCreateMountpoint(args);
break;
case CREATE_SEARCH_FOLDER:
doCreateSearchFolder(args);
break;
case CREATE_SIGNATURE:
doCreateSignature(args);
break;
case CREATE_TAG:
ZTag ct = mMbox.createTag(args[0], tagColorOpt());
stdout.println(ct.getId());
break;
case DELETE_CONTACT:
mMbox.deleteContact(args[0]);
break;
case DELETE_CONVERSATION:
mMbox.deleteConversation(id(args[0]), param(args, 1));
break;
case DELETE_INCOMING_FILTER_RULE:
doDeleteIncomingFilterRule(args);
break;
case DELETE_OUTGOING_FILTER_RULE:
doDeleteOutgoingFilterRule(args);
break;
case DELETE_FOLDER:
mMbox.deleteFolder(lookupFolderId(args[0]));
break;
case DELETE_IDENTITY:
mMbox.deleteIdentity(args[0]);
break;
case DELETE_ITEM:
mMbox.deleteItem(id(args[0]), param(args, 1));
break;
case DELETE_MESSAGE:
mMbox.deleteMessage(id(args[0]));
break;
case DELETE_SIGNATURE:
mMbox.deleteSignature(lookupSignatureId(args[0]));
break;
case DELETE_TAG:
mMbox.deleteTag(lookupTag(args[0]).getId());
break;
case DUMPSTER_DELETE_ITEM:
mMbox.dumpsterDeleteItem(id(args[0]));
break;
case EMPTY_DUMPSTER:
mMbox.emptyDumpster();
break;
case EMPTY_FOLDER:
mMbox.emptyFolder(lookupFolderId(args[0]));
break;
case EXIT:
return ExecuteStatus.EXIT;
//break;
case FLAG_CONTACT:
mMbox.flagContact(id(args[0]), paramb(args, 1, true));
break;
case FLAG_CONVERSATION:
mMbox.flagConversation(id(args[0]), paramb(args, 1, true), param(args, 2));
break;
case FLAG_ITEM:
mMbox.flagItem(id(args[0]), paramb(args, 1, true), param(args, 2));
break;
case FLAG_MESSAGE:
mMbox.flagMessage(id(args[0]), paramb(args, 1, true));
break;
case GET_ALL_CONTACTS:
doGetAllContacts(args);
break;
case GET_CONTACTS:
doGetContacts(args);
break;
case GET_IDENTITIES:
doGetIdentities();
break;
case GET_SIGNATURES:
doGetSignatures();
break;
case GET_ALL_FOLDERS:
doGetAllFolders();
break;
case GET_ALL_TAGS:
doGetAllTags();
break;
case GET_APPOINTMENT_SUMMARIES:
doGetAppointmentSummaries(args);
break;
case GET_CONVERSATION:
doGetConversation(args);
break;
case GET_INCOMING_FILTER_RULES:
doGetIncomingFilterRules();
break;
case GET_OUTGOING_FILTER_RULES:
doGetOutgoingFilterRules();
break;
case GET_FOLDER:
doGetFolder(args);
break;
case GET_FOLDER_REQUEST:
doGetFolderRequest(args);
break;
case GET_FOLDER_GRANT:
doGetFolderGrant(args);
break;
case GET_MAILBOX_SIZE:
if (verboseOpt())
stdout.format("%d%n", mMbox.getSize());
else
stdout.format("%s%n", formatSize(mMbox.getSize()));
break;
case GET_MESSAGE:
doGetMessage(args);
break;
case GET_RIGHTS:
doGetRights(args);
break;
case GET_REST_URL:
doGetRestURL(args);
break;
case GRANT_RIGHT:
doGrantRight(args);
break;
case HELP:
doHelp(args);
break;
case IMPORT_URL_INTO_FOLDER:
mMbox.importURLIntoFolder(lookupFolderId(args[0]), args[1]);
break;
case LIST_RIGHTS:
doListRights();
break;
case MARK_CONVERSATION_READ:
mMbox.markConversationRead(id(args[0]), paramb(args, 1, true), param(args, 2));
break;
case MARK_ITEM_READ:
mMbox.markItemRead(id(args[0]), paramb(args, 1, true), param(args, 2));
break;
case MARK_FOLDER_READ:
mMbox.markFolderRead(lookupFolderId(args[0]));
break;
case MARK_MESSAGE_READ:
mMbox.markMessageRead(id(args[0]), paramb(args, 1, true));
break;
case MARK_CONVERSATION_SPAM:
mMbox.markConversationSpam(id(args[0]), paramb(args, 1, true), lookupFolderId(param(args, 2)), param(args, 3));
break;
case MARK_MESSAGE_SPAM:
mMbox.markMessageSpam(id(args[0]), paramb(args, 1, true), lookupFolderId(param(args, 2)));
break;
case MARK_TAG_READ:
mMbox.markTagRead(lookupTag(args[0]).getId());
break;
case MODIFY_CONTACT:
doModifyContact(args);
break;
case MODIFY_INCOMING_FILTER_RULE:
doModifyIncomingFilterRule(args);
break;
case MODIFY_OUTGOING_FILTER_RULE:
doModifyOutgoingFilterRule(args);
break;
case MODIFY_FOLDER_CHECKED:
mMbox.modifyFolderChecked(lookupFolderId(args[0]), paramb(args, 1, true));
break;
case MODIFY_FOLDER_COLOR:
mMbox.modifyFolderColor(lookupFolderId(args[0]), ZFolder.Color.fromString(args[1]));
break;
case MODIFY_FOLDER_EXCLUDE_FREE_BUSY:
mMbox.modifyFolderExcludeFreeBusy(lookupFolderId(args[0]), paramb(args, 1, true));
break;
case MODIFY_FOLDER_GRANT:
doModifyFolderGrant(args);
break;
case MODIFY_FOLDER_FLAGS:
mMbox.updateFolder(lookupFolderId(args[0]), null, null, null, null, args[1], null);
break;
case MODIFY_FOLDER_URL:
mMbox.modifyFolderURL(lookupFolderId(args[0]), args[1]);
break;
case MODIFY_IDENTITY:
mMbox.modifyIdentity(new ZIdentity(args[0], getMultiMap(args, 1)));
break;
case MODIFY_ITEM_FLAGS:
mMbox.updateItem(id(args[0]), null, null, args[1], null);
break;
case MODIFY_MOUNTPOINT_ENABLE_SHARED_REMINDER:
mMbox.enableSharedReminder(lookupFolderId(args[0]), paramb(args, 1, false));
break;
case MODIFY_SIGNATURE:
doModifySignature(args);
break;
case MODIFY_TAG_COLOR:
mMbox.modifyTagColor(lookupTag(args[0]).getId(), Color.fromString(args[1]));
break;
case MOVE_CONVERSATION:
mMbox.moveConversation(id(args[0]), lookupFolderId(param(args, 1)), param(args, 2));
break;
case MOVE_ITEM:
mMbox.moveItem(id(args[0]), lookupFolderId(param(args, 1)), param(args, 2));
break;
case MOVE_MESSAGE:
mMbox.moveMessage(id(args[0]), lookupFolderId(param(args, 1)));
break;
case MOVE_CONTACT:
mMbox.moveContact(id(args[0]), lookupFolderId(param(args, 1)));
break;
case NOOP:
doNoop(args);
break;
case POST_REST_URL:
doPostRestURL(args);
break;
case RECOVER_ITEM:
mMbox.recoverItem(id(args[0]), lookupFolderId(param(args, 1)));
break;
case RENAME_FOLDER:
mMbox.renameFolder(lookupFolderId(args[0]), args[1]);
break;
case RENAME_SIGNATURE:
doRenameSignature(args);
break;
case RENAME_TAG:
mMbox.renameTag(lookupTag(args[0]).getId(), args[1]);
break;
case REVOKE_RIGHT:
doRevokeRight(args);
break;
case SEARCH:
doSearch(args);
break;
case SEARCH_CONVERSATION:
doSearchConv(args);
break;
case SELECT_MAILBOX:
doSelectMailbox(args);
break;
case SYNC_FOLDER:
mMbox.syncFolder(lookupFolderId(args[0]));
break;
case TAG_CONTACT:
mMbox.tagContact(id(args[0]), lookupTag(args[1]).getId(), paramb(args, 2, true));
break;
case TAG_CONVERSATION:
mMbox.tagConversation(id(args[0]), lookupTag(args[1]).getId(), paramb(args, 2, true), param(args, 3));
break;
case TAG_ITEM:
mMbox.tagItem(id(args[0]), lookupTag(args[1]).getId(), paramb(args, 2, true), param(args, 3));
break;
case TAG_MESSAGE:
mMbox.tagMessage(id(args[0]), lookupTag(args[1]).getId(), paramb(args, 2, true));
break;
case WHOAMI:
dumpMailboxConnect();
break;
default:
throw ZClientException.CLIENT_ERROR("Unhandled command: (" + mCommand.name() + ")", null);
}
return ExecuteStatus.OK;
}
use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class ZMailboxUtil method lookupTagNames.
/**
* takes a list of ids, and trys to resolve them all to tag names
*
*/
private String lookupTagNames(String ids) throws ServiceException {
StringBuilder names = new StringBuilder();
for (String tid : ids.split(",")) {
ZTag tag = lookupTag(tid);
if (names.length() > 0) {
names.append(", ");
}
names.append(tag == null ? tid : tag.getName());
}
return names.toString();
}
use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class ZMailboxUtil method lookupTagIds.
/**
* takes a list of ids or names, and trys to resolve them all to valid tag ids
*
* @param idsOrNames
* @return
* @throws SoapFaultException
*/
private String lookupTagIds(String idsOrNames) throws ServiceException {
StringBuilder ids = new StringBuilder();
for (String t : idsOrNames.split(",")) {
ZTag tag = lookupTag(t);
if (ids.length() > 0) {
ids.append(",");
}
ids.append(tag.getId());
}
return ids.toString();
}
use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class TestFilter method testDateFiltering.
@Test
public void testDateFiltering() throws Exception {
// Before tomorrow.
ZTag tagBeforeTomorrow = mMbox.createTag(NAME_PREFIX + " before tomorrow", null);
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
conditions.add(new ZDateCondition(DateOp.BEFORE, new Date(System.currentTimeMillis() + Constants.MILLIS_PER_DAY)));
actions.add(new ZTagAction(tagBeforeTomorrow.getName()));
rules.add(new ZFilterRule("before tomorrow", true, false, conditions, actions));
// After yesterday.
ZTag tagAfterYesterday = mMbox.createTag(NAME_PREFIX + " after yesterday", null);
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZDateCondition(DateOp.AFTER, new Date(System.currentTimeMillis() - Constants.MILLIS_PER_DAY)));
actions.add(new ZTagAction(tagAfterYesterday.getName()));
rules.add(new ZFilterRule("after yesterday", true, false, conditions, actions));
// Save rules.
ZFilterRules zRules = new ZFilterRules(rules);
mMbox.saveIncomingFilterRules(zRules);
// Old message.
String[] recipients = new String[] { USER_NAME };
String subject = NAME_PREFIX + " testDateFiltering old";
String content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, new Date(System.currentTimeMillis() - (2 * Constants.MILLIS_PER_DAY)));
TestUtil.addMessageLmtp(recipients, USER_NAME, content);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZMessage msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
Set<String> tagIds = getTagIds(msg);
assertEquals(1, tagIds.size());
assertTrue(tagIds.contains(tagBeforeTomorrow.getId()));
// Current message.
subject = NAME_PREFIX + " testDateFiltering current";
content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
TestUtil.addMessageLmtp(recipients, USER_NAME, content);
msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
tagIds = getTagIds(msg);
assertEquals(2, tagIds.size());
assertTrue(tagIds.contains(tagAfterYesterday.getId()));
assertTrue(tagIds.contains(tagBeforeTomorrow.getId()));
// Future message.
subject = NAME_PREFIX + " testDateFiltering future";
content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, new Date(System.currentTimeMillis() + (2 * Constants.MILLIS_PER_DAY)));
TestUtil.addMessageLmtp(recipients, USER_NAME, content);
msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
tagIds = getTagIds(msg);
assertEquals(1, tagIds.size());
assertTrue(tagIds.contains(tagAfterYesterday.getId()));
// No date header (bug 44079).
subject = NAME_PREFIX + " testDateFiltering no date header";
content = removeHeader(TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null), "Date");
TestUtil.addMessageLmtp(recipients, USER_NAME, content);
msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
tagIds = getTagIds(msg);
assertEquals(2, tagIds.size());
assertTrue(tagIds.contains(tagAfterYesterday.getId()));
assertTrue(tagIds.contains(tagBeforeTomorrow.getId()));
}
use of com.zimbra.client.ZTag in project zm-mailbox by Zimbra.
the class TestFilter method testInvite.
@Test
public void testInvite() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
// Create tags.
String prefix = NAME_PREFIX + " testInvite ";
ZTag tagNoMethod = mbox.createTag(prefix + "no method", null);
ZTag tagAnyReply = mbox.createTag(prefix + "any reply", null);
ZTag tagAnyRequest = mbox.createTag(prefix + "any request", null);
ZTag tagRequestOrCancel = mbox.createTag(prefix + "request or cancel", null);
ZTag tagReply = mbox.createTag(prefix + "reply", null);
// Create filter rules that set tags based on conditions.
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
ZFilterCondition condition = new ZInviteCondition(true);
ZFilterAction action = new ZTagAction(tagNoMethod.getName());
rules.add(createRule("testInvite - no method", condition, action));
condition = new ZInviteCondition(true, ZInviteCondition.METHOD_ANYREPLY);
action = new ZTagAction(tagAnyReply.getName());
rules.add(createRule("testInvite - any reply", condition, action));
condition = new ZInviteCondition(true, ZInviteCondition.METHOD_ANYREQUEST);
action = new ZTagAction(tagAnyRequest.getName());
rules.add(createRule("testInvite - any request", condition, action));
condition = new ZInviteCondition(true, Arrays.asList(ZInviteCondition.METHOD_REQUEST, ZInviteCondition.METHOD_CANCEL));
action = new ZTagAction(tagRequestOrCancel.getName());
rules.add(createRule("testInvite - request or cancel", condition, action));
condition = new ZInviteCondition(true, ZInviteCondition.METHOD_REPLY);
action = new ZTagAction(tagReply.getName());
rules.add(createRule("testInvite - reply", condition, action));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Send an invite from user2 and check tags.
ZMailbox organizer = TestUtil.getZMailbox(REMOTE_USER_NAME);
String subject = NAME_PREFIX + " testInvite request 1";
Date startDate = new Date(System.currentTimeMillis() + Constants.MILLIS_PER_DAY);
Date endDate = new Date(startDate.getTime() + Constants.MILLIS_PER_HOUR);
TestUtil.createAppointment(organizer, subject, mbox.getName(), startDate, endDate);
// Get message and check tags.
ZMessage msg = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
Set<String> tagIds = getTagIds(msg);
assertTrue(tagIds.contains(tagNoMethod.getId()));
assertFalse(tagIds.contains(tagAnyReply.getId()));
assertTrue(tagIds.contains(tagAnyRequest.getId()));
assertTrue(tagIds.contains(tagRequestOrCancel.getId()));
assertFalse(tagIds.contains(tagReply.getId()));
// Now test filtering a reply to an invite. Send an invite to user2,
// and have user2 accept the appointment.
organizer = TestUtil.getZMailbox(USER_NAME);
mbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
subject = NAME_PREFIX + " testInvite request 2";
startDate = new Date(startDate.getTime() + Constants.MILLIS_PER_DAY);
endDate = new Date(endDate.getTime() + Constants.MILLIS_PER_DAY);
TestUtil.createAppointment(organizer, subject, mbox.getName(), startDate, endDate);
// Receive the invite and accept the appointment.
msg = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
subject = NAME_PREFIX + " testInvite reply";
TestUtil.sendInviteReply(mbox, msg.getId(), organizer.getName(), subject, ZMailbox.ReplyVerb.ACCEPT);
msg = TestUtil.waitForMessage(organizer, "in:inbox subject:\"" + subject + "\"");
// Check tags on the invite reply.
tagIds = getTagIds(msg);
assertTrue(tagIds.contains(tagNoMethod.getId()));
assertTrue(tagIds.contains(tagAnyReply.getId()));
assertFalse(tagIds.contains(tagAnyRequest.getId()));
assertFalse(tagIds.contains(tagRequestOrCancel.getId()));
assertTrue(tagIds.contains(tagReply.getId()));
}
Aggregations