36 while (
$c=readdir(
$d)) {
37 if (substr(
$c,0,1)==
".")
continue;
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";
71 $email=preg_replace(
"#_([^_]*)$#",
"@$1",
$user);
73 for(
$i=0;
$i<count($rules);
$i++) {
74 list($rules[
$i][
"conds"],$rules[
$i][
"actionparam"])=
describe($rules[
$i]);
91 echo
"ERROR: Can't open '$user' in '$SIEVEROOT' for writing\n";
93 echo
"OK: writing sieve script for $user (".count($rules).
" rules)\n";
95 $avelsieveversion=array(
"major" => 1,
"minor"=>9,
"release" => 9,
"string" =>
"1.9.9");
96 fputs(
$f,
'# This script has been automatically generated by avelsieve
97 # (Sieve Mail Filters Plugin for Squirrelmail)
98 # Warning: If you edit this manually, then the changes will not
99 # be reflected in the users\' front-end!
100 #AVELSIEVE_VERSION'.urlencode(base64_encode(serialize($avelsieveversion))).
'
101 #AVELSIEVE_CREATED'.time().
'
102 #AVELSIEVE_MODIFIED'.time().
'
103 require ["fileinto","envelope","reject","vacation","imap4flags","relational","comparator-i;ascii-numeric","regex","body","date"];
105 foreach($rules as $rule) {
106 if ($rule[
"type"]==2)
continue;
112 $avelrule[
"condition"]=
"and";
114 if (!count($rule[
"conds"])) {
117 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"all");
121 foreach($conds as $cond) {
122 if (!$first) $script.=
",\n";
127 $script.=
'header :contains "Subject" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
128 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"Subject",
"matchtype" =>
"contains",
"headermatch" => $cond[1] );
131 $script.=
'header :contains "From" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
132 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"From",
"matchtype" =>
"contains",
"headermatch" => $cond[1] );
135 $script.=
'address :contains ["to", "cc"] "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
136 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"address",
"address" =>
"toorcc",
"matchtype" =>
"contains",
"addressmatch" => $cond[1] );
139 $script.=
'header :contains "List-Post" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
140 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"List-Post",
"matchtype" =>
"contains",
"headermatch" => $cond[1] );
143 $script.=
'header :contains "List-Id" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
144 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"List-Id",
"matchtype" =>
"contains",
"headermatch" => $cond[1] );
147 $script.=
'header :contains "X-Spam-Status" "Yes"';
148 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"header",
"header" =>
"X-Spam-Status",
"matchtype" =>
"contains",
"headermatch" =>
"Yes" );
151 $script.=
'envelope :contains "to" "'.str_replace(
'"',
'\\"',$cond[1]).
'"';
152 $avelrule[
"cond"][]=array(
"kind" =>
"message",
"type" =>
"envelope",
"envelope" =>
"to",
"matchtype" =>
"contains",
"envelopematch" => $cond[1] );
160 switch($rule[
"type"]) {
162 $script.=
'fileinto "'.str_replace(
'"',
'\\"',$rule[
"actionparam"]).
'";
165 $avelrule[
"action"] = 5;
166 $avelrule[
"folder"] = $rule[
"actionparam"];
167 $avelrule[
"stop"] =
"on";
173 $avelrule[
"action"] = 2;
174 $avelrule[
"stop"] =
"on";
177 $script.=
'redirect "'.str_replace(
'"',
'\\"',$rule[
"actionparam"]).
'";
179 $avelrule[
"action"] = 4;
180 $avelrule[
"redirectemail"] = $rule[
"actionparam"];
183 $script.=
'vacation :days 7 :addresses ["'.$email.
'"@ :subject "Auto Reply" text:
184 '.str_replace(
"\\'",
"'",@file_get_contents(
$ROOT.
"/".$u.
"/".
$user.
"/".
$user.
".txt")).
'
188 $avelrule[
"action"] = 6;
189 $avelrule[
"vac_addresses"] = $email;
190 $avelrule[
"vac_subject"] =
"Auto Reply";
191 $avelrule[
"vac_days"] = 7;
192 $avelrule[
"vac_message"] = @file_get_contents(
$ROOT.
"/".$u.
"/".
$user.
"/".
$user.
".txt");
197 fputs(
$f,
"#START_SIEVE_RULE".urlencode(base64_encode(serialize($avelrule))).
"END_SIEVE_RULE\n");
221 echo
"ERROR: can't read rules for $user\n";
235 $u=substr(
$user,0,1);
236 if (!file_exists(
ALTERNC_MAIL.
"/$u/$user/.procmailrc")) {
240 $state=0; $rulenum=0; $ligne=0;
246 if ($state==1 && !ereg(
"^# RuleEnd$",$s)) {
247 $res[$rulenum][
"rule"][
$res[$rulenum][
"count"]++]=$s;
250 if ($state==1 && ereg(
"^# RuleEnd$",$s)) {
255 if ($state==0 && ereg(
"^# RuleType ([0-9][0-9]) -- (.*)?$",$s,
$r)) {
257 $res[$rulenum][
"type"]=
$r[1];
258 $res[$rulenum][
"name"]=
$r[2];
259 $res[$rulenum][
"count"]=0;
262 if (!
$found && $state!=0) {
281 switch ($rule[
"type"]) {
284 while ($rule[
"rule"][
$i]!=
"* !^FROM_DAEMON" && $rule[
"rule"][
$i]!=
"") {
285 $cond[]=$rule[
"rule"][
$i];
291 while (substr($rule[
"rule"][
$i],0,1)==
"*") {
292 $cond[]=$rule[
"rule"][
$i];
302 for(
$i=0;
$i<count($cond);
$i++) {
303 if (ereg(
"^\\* \\^Subject\\.\\*(.*)$",$cond[
$i],
$t)) {
304 $conds[]=array( 0,
$t[1] );
306 if (ereg(
"^\\* \\^From\\.\\*(.*)$",$cond[
$i],
$t)) {
307 $conds[]=array( 1,
$t[1] );
309 if (ereg(
"^\\* \\^TO_(.*)$",$cond[
$i],
$t)) {
310 $conds[]=array( 2,
$t[1] );
312 if (ereg(
"^\\* \\^List-Post: (.*)$",$cond[
$i],
$t)) {
313 $conds[]=array( 3,
$t[1] );
315 if (ereg(
"^\\* \\^List-Id: (.*)$",$cond[
$i],
$t)) {
316 $conds[]=array( 4,
$t[1] );
318 if (ereg(
"^\\* \\^X-Spam-Status: Yes$",$cond[
$i])) {
321 if (ereg(
"^\\* \\^Delivered-To:\\.\\*(.*)$",$cond[
$i],
$t)) {
322 $conds[]=array( 6,
$t[1] );
328 switch ($rule[
"type"]) {
330 $actionparam=$rule[
"rule"][count($rule[
"rule"])-2];
333 $actionparam = substr($rule[
"rule"][count($rule[
"rule"])-2],0,15);
336 return array($conds,$actionparam);
349 0 =>
"Le sujet du message contient ...",
350 1 =>
"L'expediteur du message est contient ...",
351 2 =>
"L'un des destinataires du message contient ...",
352 3 =>
"L'en-tete 'List-Post' du message est ...",
353 4 =>
"L'en-tete 'List-Id' du message est ...",
354 5 =>
"SpamAssassin considere qu'il s'agit d'un Spam",
355 6 =>
"L'en-tete 'Delivered-To' du message contient ...",
358 1 =>
"Move the message to this folder",
359 2 =>
"Filter the message through SpamAssassin",
360 3 =>
"Discard the message (for good !)",
361 4 =>
"Forward the mail to",
368 include_once(
'/usr/share/alternc/panel/class/local.php');
parseOneProcmail($user)
Parse ONE procmailrc, and write its sieve rules.
procmail2sieve()
MAIN FUNCTION Read all the mail folders and search for .procmailrc's.
readrules($user="")
Read rules, fill an array from m_procmail.php original file yeah I know, ereg() is deprecated ;)
describe($rule)
Take ONE rule array, extract properly returns one array with the conditions (which are arrays with Co...
foreach($domaines_user as $domaine) $t