zimbra-api / soap-api

Zimbra SOAP client in PHP language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to add new filter rule?

vijaydwivedics opened this issue · comments

Hello everyone,
here i am facing a problem on Zimbra API,
here i want to add filter rule, but am nothing found any documentation related to this.

issue resolved.

#40 (comment)

as the library lacks of examples it would be great if you can share how you accomplished your result. thanks

define filter types and variables

$name = "test";
$index = mt_rand(1, 100);
$header = "Received";
$part = "";

$comparison = "contains";
$value = "is,0,6";

$value1 = "test@test.com";

$where = null;
$date = null;
$time = null;
$method = "not_contains";
$size = null;
$folder = null;

$flag = "read";
$tag = "mark";
$address = "test@test.com";
$content = null;
$max = null;
$subject = null;
$headers =  null;

$addressBookTest = new \Zimbra\Mail\Struct\AddressBookTest($index, $header, true);
$addressTest = new \Zimbra\Mail\Struct\AddressTest($index, $header, $part, $comparison, $value, true, true);
$attachmentTest = new \Zimbra\Mail\Struct\AttachmentTest($index, true);
$bodyTest = new \Zimbra\Mail\Struct\BodyTest($index, $value1, true, true);
$bulkTest = new \Zimbra\Mail\Struct\BulkTest($index, true);
$contactRankingTest = new \Zimbra\Mail\Struct\ContactRankingTest($index, $header, true);
$conversationTest = new \Zimbra\Mail\Struct\ConversationTest($index, $where, false);
$currentDayOfWeekTest = new \Zimbra\Mail\Struct\CurrentDayOfWeekTest($index, $value, true);
$currentTimeTest = new \Zimbra\Mail\Struct\CurrentTimeTest($index, $comparison, $time, true);
$dateTest = new \Zimbra\Mail\Struct\DateTest($index, $comparison, $date, true);
$facebookTest = new \Zimbra\Mail\Struct\FacebookTest($index, true);
$flaggedTest = new \Zimbra\Mail\Struct\FlaggedTest($index, $flag, true);
$headerExistsTest = new \Zimbra\Mail\Struct\HeaderExistsTest($index, $header, true);
$headerTest = new \Zimbra\Mail\Struct\HeaderTest($index, $header, $comparison, $value, true, true);
$importanceTest = new \Zimbra\Mail\Struct\ImportanceTest($index, Importance::HIGH(), true);
$inviteTest = new \Zimbra\Mail\Struct\InviteTest($index, [$method], true);
$linkedinTest = new \Zimbra\Mail\Struct\LinkedInTest($index, true);
$listTest = new \Zimbra\Mail\Struct\ListTest($index, true);
$meTest = new \Zimbra\Mail\Struct\MeTest($index, $header, true);
$mimeHeaderTest = new \Zimbra\Mail\Struct\MimeHeaderTest($index, $header, $comparison, $value, true, true);
$sizeTest = new \Zimbra\Mail\Struct\SizeTest($index, $comparison, $size, true);
$socialcastTest = new \Zimbra\Mail\Struct\SocialcastTest($index, true);
$trueTest = new \Zimbra\Mail\Struct\TrueTest($index, true);
$twitterTest = new \Zimbra\Mail\Struct\TwitterTest($index, true);
  
$tests = [
	$addressBookTest,
	$addressTest,
	$attachmentTest,
	$bodyTest,
	$bulkTest,
	$contactRankingTest,
	$conversationTest,
	$currentDayOfWeekTest,
	$currentTimeTest,
	$dateTest,
	$facebookTest,
	$flaggedTest,
	$headerExistsTest,
	$headerTest,
	$importanceTest,
	$inviteTest,
	$linkedinTest,
	$listTest,
	$meTest,
	$mimeHeaderTest,
	$sizeTest,
	$socialcastTest,
	$trueTest,
	$twitterTest
];

Here you don't need to use all for example,
I need only to filter "header" so i am using
$tests = [
$headerTest
];

variables should be defined according to this condition

{conditions}:
address "comma-separated-header-names" all|localpart|domain is|not_is|contains|not_contains|matches|not_matches [case_sensitive] "value"
addressbook in|not_in "header-name"
attachment exists|not_exists
body contains|not_contains [case_sensitive] "text"
bulk [not]
conversation where|not_where started|participated
current_day_of_week is|not_is "comma-separated-days(0=Sun,6=Sat)"
current_time before|not_before|after|not_after "HHmm"
date before|not_before|after|not_after "YYYYMMDD"
facebook [not]
flagged [not] "flag"
header "comma-separated-names" is|not_is|contains|not_contains|matches|not_matches [case_sensitive] "value"
header "comma-separated-names" exists|not_exists
importance is|not_is high|normal|low
invite exists|not_exists
linkedin [not]
list [not]
me in|not_in "header-name"
mime_header "name" is|not_is|contains|not_contains|matches|not_matches [case_sensitive] "value"
ranking in|not_in "header-name"
size under|not_under|over|not_over "1|1K|1M"
socialcast [not]
twitter [not]
{/conditions}

and then do this

$filterTests = new \Zimbra\Mail\Struct\FilterTests(FilterCondition::ANY_OF(), $tests);
$actionKeep = new \Zimbra\Mail\Struct\KeepAction($index);
$actionDiscard = new \Zimbra\Mail\Struct\DiscardAction($index);
$actionFileInto = new \Zimbra\Mail\Struct\FileIntoAction($index, $folder);
$actionFlag = new \Zimbra\Mail\Struct\FlagAction($index, $flag);
$actionTag = new \Zimbra\Mail\Struct\TagAction($index, $tag);
$actionRedirect = new \Zimbra\Mail\Struct\RedirectAction($index, $address);
$actionReply = new \Zimbra\Mail\Struct\ReplyAction($index, $content);
$actionNotify = new \Zimbra\Mail\Struct\NotifyAction($index, $content, $address, $subject, $max, $headers);
$actionStop = new \Zimbra\Mail\Struct\StopAction($index);

$actions = [
	$actionKeep,
	$actionDiscard,
	$actionFileInto,
	$actionFlag,
	$actionTag,
	$actionRedirect,
	$actionReply,
	$actionNotify,
	$actionStop
];

Same is here you need only use which action you need on filter
Example : here i need only 3 action flag, redirect, and stop
$actions = [
$actionFlag,
$actionRedirect,
$actionStop
];

$filterActions = new \Zimbra\Mail\Struct\FilterActions($actions);
$filterRule = new \Zimbra\Mail\Struct\FilterRule($name, true, $filterTests, $filterActions);
$filterRules = new \Zimbra\Mail\Struct\FilterRules([$filterRule]);

$resp = $api->modifyFilterRules($filterRules, "add filter rule");

To find error must use try{}catch(e){}