36 while (
$c=readdir(
$d)) {
37 if (substr(
$c,0,1)==
".")
continue;
38 if (is_dir($ROOT.
"/".
$c)) {
40 $e=@opendir($ROOT.
"/".
$c);
42 while ($f=readdir($e)) {
43 if (substr($f,0,1)==
".")
continue;
44 if (is_file($ROOT.
"/".
$c.
"/".$f.
"/.procmailrc")) {
51 echo
"ERROR: Cannot open ".$ROOT.
"/".
$c.
"\n";
58 echo
"FATAL: cannot open ".$ROOT.
"\n";
70 $email=preg_replace(
"#_([^_]*)$#",
"@$1",
$user);
72 for(
$i=0;
$i<count($rules);
$i++) {
73 list($rules[
$i][
"conds"],$rules[$i][
"actionparam"])=
describe($rules[$i]);
80 @mkdir($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve");
81 @mkdir($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve/tmp");
82 $uid=fileowner($SIEVEROOT.
"/".$u.
"/".
$user);
83 chown($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve",
$uid);
84 chgrp($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve",
"vmail");
85 chown($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve/tmp",
$uid);
86 chgrp($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve/tmp",
"vmail");
88 $f=fopen($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve/tmp/phpscript.sieve",
"wb");
90 echo
"ERROR: Can't open '$user' in '$SIEVEROOT' for writing\n";
92 echo
"OK: writing sieve script for $user (".count($rules).
" rules)\n";
94 $avelsieveversion=array(
"major" => 1,
"minor"=>9,
"release" => 9,
"string" =>
"1.9.9");
95 fputs($f,
'# This script has been automatically generated by avelsieve
96 # (Sieve Mail Filters Plugin for Squirrelmail)
97 # Warning: If you edit this manually, then the changes will not
98 # be reflected in the users\' front-end!
99 #AVELSIEVE_VERSION'.urlencode(base64_encode(serialize($avelsieveversion))).
'
100 #AVELSIEVE_CREATED'.time().
'
101 #AVELSIEVE_MODIFIED'.time().
'
102 require ["fileinto","envelope","reject","vacation","imap4flags","relational","comparator-i;ascii-numeric","regex","body","date"];
104 foreach($rules as $rule) {
105 if ($rule[
"type"]==2)
continue;
111 $avelrule[
"condition"]=
"and";
113 if (!count($rule[
"conds"])) {
116 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"all");
120 foreach($conds as $cond) {
121 if (!$first) $script.=
",\n";
126 $script.=
'header :contains "Subject" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
127 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"Subject",
"matchtype" =>
"contains",
"headermatch" => $cond[1] );
130 $script.=
'header :contains "From" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
131 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"From",
"matchtype" =>
"contains",
"headermatch" => $cond[1] );
134 $script.=
'address :contains ["to", "cc"] "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
135 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"address",
"address" =>
"toorcc",
"matchtype" =>
"contains",
"addressmatch" => $cond[1] );
138 $script.=
'header :contains "List-Post" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
139 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"List-Post",
"matchtype" =>
"contains",
"headermatch" => $cond[1] );
142 $script.=
'header :contains "List-Id" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
143 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"List-Id",
"matchtype" =>
"contains",
"headermatch" => $cond[1] );
146 $script.=
'header :contains "X-Spam-Status" "Yes"';
147 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"X-Spam-Status",
"matchtype" =>
"contains",
"headermatch" =>
"Yes" );
150 $script.=
'envelope :contains "to" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
151 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"envelope",
"envelope" =>
"to",
"matchtype" =>
"contains",
"envelopematch" => $cond[1] );
159 switch($rule[
"type"]) {
161 $script.=
'fileinto "'.str_replace(
'"',
'\\"',$rule[
"actionparam"]).
'";
164 $avelrule[
"action"] = 5;
165 $avelrule[
"folder"] = $rule[
"actionparam"];
166 $avelrule[
"stop"] =
"on";
172 $avelrule[
"action"] = 2;
173 $avelrule[
"stop"] =
"on";
176 $script.=
'redirect "'.str_replace(
'"',
'\\"',$rule[
"actionparam"]).
'";
178 $avelrule[
"action"] = 4;
179 $avelrule[
"redirectemail"] = $rule[
"actionparam"];
182 $script.=
'vacation :days 7 :addresses ["'.$email.
'"@ :subject "Auto Reply" text:
183 '.str_replace(
"\\'",
"'",@file_get_contents(
$ROOT.
"/".$u.
"/".
$user.
"/".
$user.
".txt")).
'
187 $avelrule[
"action"] = 6;
188 $avelrule[
"vac_addresses"] = $email;
189 $avelrule[
"vac_subject"] =
"Auto Reply";
190 $avelrule[
"vac_days"] = 7;
191 $avelrule[
"vac_message"] = @file_get_contents(
$ROOT.
"/".$u.
"/".
$user.
"/".
$user.
".txt");
196 fputs($f,
"#START_SIEVE_RULE".urlencode(base64_encode(serialize($avelrule))).
"END_SIEVE_RULE\n");
211 @unlink($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve/phpscript.sieve");
213 $SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve/tmp/phpscript.sieve",
214 $SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve/phpscript.sieve"
216 chown($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve/phpscript.sieve",
$uid);
217 chgrp($SIEVEROOT.
"/".$u.
"/".
$user.
"/sieve/phpscript.sieve",
"vmail");
220 echo
"ERROR: can't read rules for $user\n";
234 $u=substr(
$user,0,1);
235 if (!file_exists(
ALTERNC_MAIL.
"/$u/$user/.procmailrc")) {
239 $state=0; $rulenum=0; $ligne=0;
245 if ($state==1 && !ereg(
"^# RuleEnd$",$s)) {
246 $res[$rulenum][
"rule"][
$res[$rulenum][
"count"]++]=$s;
249 if ($state==1 && ereg(
"^# RuleEnd$",$s)) {
254 if ($state==0 && ereg(
"^# RuleType ([0-9][0-9]) -- (.*)?$",$s,
$r)) {
256 $res[$rulenum][
"type"]=
$r[1];
257 $res[$rulenum][
"name"]=
$r[2];
258 $res[$rulenum][
"count"]=0;
261 if (!
$found && $state!=0) {
280 switch ($rule[
"type"]) {
283 while ($rule[
"rule"][
$i]!=
"* !^FROM_DAEMON" && $rule[
"rule"][
$i]!=
"") {
284 $cond[]=$rule[
"rule"][
$i];
290 while (substr($rule[
"rule"][
$i],0,1)==
"*") {
291 $cond[]=$rule[
"rule"][
$i];
301 for(
$i=0;
$i<count($cond);
$i++) {
302 if (ereg(
"^\\* \\^Subject\\.\\*(.*)$",$cond[
$i],
$t)) {
303 $conds[]=array( 0,
$t[1] );
305 if (ereg(
"^\\* \\^From\\.\\*(.*)$",$cond[$i],
$t)) {
306 $conds[]=array( 1,
$t[1] );
308 if (ereg(
"^\\* \\^TO_(.*)$",$cond[$i],
$t)) {
309 $conds[]=array( 2,
$t[1] );
311 if (ereg(
"^\\* \\^List-Post: (.*)$",$cond[$i],
$t)) {
312 $conds[]=array( 3,
$t[1] );
314 if (ereg(
"^\\* \\^List-Id: (.*)$",$cond[$i],
$t)) {
315 $conds[]=array( 4,
$t[1] );
317 if (ereg(
"^\\* \\^X-Spam-Status: Yes$",$cond[$i])) {
320 if (ereg(
"^\\* \\^Delivered-To:\\.\\*(.*)$",$cond[$i],
$t)) {
321 $conds[]=array( 6,
$t[1] );
327 switch ($rule[
"type"]) {
329 $actionparam=$rule[
"rule"][count($rule[
"rule"])-2];
332 $actionparam = substr($rule[
"rule"][count($rule[
"rule"])-2],0,15);
335 return array($conds,$actionparam);
348 0 =>
"Le sujet du message contient ...",
349 1 =>
"L'expediteur du message est contient ...",
350 2 =>
"L'un des destinataires du message contient ...",
351 3 =>
"L'en-tete 'List-Post' du message est ...",
352 4 =>
"L'en-tete 'List-Id' du message est ...",
353 5 =>
"SpamAssassin considere qu'il s'agit d'un Spam",
354 6 =>
"L'en-tete 'Delivered-To' du message contient ...",
357 1 =>
"Move the message to this folder",
358 2 =>
"Filter the message through SpamAssassin",
359 3 =>
"Discard the message (for good !)",
360 4 =>
"Forward the mail to",
367 include_once(
'/usr/share/alternc/panel/class/local.php');