diff --git a/.gitattributes b/.gitattributes index 1626d777..5c095e3c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -586,6 +586,7 @@ squirrelmail/Makefile -text squirrelmail/alternc_changepass/change.php -text squirrelmail/alternc_changepass/setup.php -text squirrelmail/class/m_squirrelmail.php -text +squirrelmail/procmail_to_sieve.php -text squirrelmail/squirrelmail-install -text squirrelmail/templates/apache2/squirrelmail.conf -text squirrelmail/templates/squirrelmail/alternc-changepass.conf -text diff --git a/squirrelmail/procmail_to_sieve.php b/squirrelmail/procmail_to_sieve.php new file mode 100755 index 00000000..3fb1d913 --- /dev/null +++ b/squirrelmail/procmail_to_sieve.php @@ -0,0 +1,234 @@ +=3.0 + ---------------------------------------------------------------------- +*/ + +/* ----------------------------------------------------------------- */ +/** + MAIN FUNCTION + Read all the mail folders and search for .procmailrc's +*/ +function procmail2sieve() { + global $ROOT; + $d=opendir($ROOT); + if ($d) { + while ($c=readdir($d)) { + if (substr($c,0,1)==".") continue; // skip hidden files + if (is_dir($ROOT."/".$c)) { + // Go to level 2. + $e=opendir($ROOT."/".$c); + if ($e) { + while ($f=readdir($e)) { + if (substr($f,0,1)==".") continue; // skip hidden files + if (is_file($ROOT."/".$c."/".$f."/.procmailrc")) { + // We found one .procmailrc, let's parse it on behalf of his user... + parseOneProcmail($f); /* ################## SUB FUNCTION ###################### */ + } + } + closedir($e); + } + + } + } + closedir($d); + } +} /* procmail2sieve */ + + + +/* ----------------------------------------------------------------- */ +/** Parse ONE procmailrc, and write its sieve rules + */ +function parseOneProcmail($user) { + global $SIEVEROOT; + if ($rules=readrules($user)) { /* ################## SUB FUNCTION ###################### */ + for($i=0; $iuser; + $u=substr($user,0,1); + if (!file_exists("/var/alternc/mail/$u/$user/.procmailrc")) { + return false; + } + $f=fopen("/var/alternc/mail/$u/$user/.procmailrc","rb"); + $state=0; $rulenum=0; $ligne=0; + $res=array(); + while (!feof($f)) { + $found=false; // found allow us to know if we found something for each loop + $s=fgets($f,1024); + $s=trim($s); + if ($state==1 && !ereg("^# RuleEnd$",$s)) { + $res[$rulenum]["rule"][$res[$rulenum]["count"]++]=$s; + $found=true; + } + if ($state==1 && ereg("^# RuleEnd$",$s)) { + $state=0; + $rulenum++; + $found=true; + } + if ($state==0 && ereg("^# RuleType ([0-9][0-9]) -- (.*)?$",$s,$r)) { + $state=1; + $res[$rulenum]["type"]=$r[1]; + $res[$rulenum]["name"]=$r[2]; + $res[$rulenum]["count"]=0; + $found=true; + } + if (!$found && $state!=0) { + return false; + } + $ligne++; + } + fclose($f); + return $res; +} + + +/* ----------------------------------------------------------------- */ +/** Take ONE rule array, extract properly + returns one array with the conditions (which are arrays with Condition Type and Value) + and the action parameter +*/ +function describe($rule) { + + // Lecture des conditions : + $cond=array(); + switch ($rule["type"]) { + case 5: + $i=1; + while ($rule["rule"][$i]!="* !^FROM_DAEMON" && $rule["rule"][$i]!="") { + $cond[]=$rule["rule"][$i]; + $i++; + } + break; + default: + $i=1; + while (substr($rule["rule"][$i],0,1)=="*") { + $cond[]=$rule["rule"][$i]; + $i++; + } + break; + } + + // $cond is an array of conditions + // let's parse the condition : (see arrays at the top of this file) + $conds=array(); + + for($i=0;$i "Le sujet du message contient ...", + 1 => "L'expéditeur du message est contient ...", + 2 => "L'un des destinataires du message contient ...", + 3 => "L'en-tete 'List-Post' du message est ...", + 4 => "L'en-tete 'List-Id' du message est ...", + 5 => "SpamAssassin considère qu'il s'agit d'un Spam", + 6 => "L'en-tete 'Delivered-To' du message contient ...", + ); +$aactions=array( + 1 => "Move the message to this folder", + 2 => "Filter the message through SpamAssassin", + 3 => "Discard the message (for good !)", + 4 => "Forward the mail to", + 5 => "Auto-reply", + ); + + +/* ----------------------------------------------------------------- */ +// CONFIGURATION : +$ROOT="/var/alternc/mail"; +$SIEVEROOT="/var/lib/dovecot/sieve"; +// GO ! +procmail2sieve(); +