adding PROCMAILBUILDER to AVELSIEVE migration script \o/ Refers #1262
This commit is contained in:
parent
2486b8fb5a
commit
aabb6f6617
|
@ -592,6 +592,7 @@ squirrelmail/templates/apache2/squirrelmail.conf -text
|
|||
squirrelmail/templates/squirrelmail/alternc-changepass.conf -text
|
||||
squirrelmail/templates/squirrelmail/apache.conf -text
|
||||
squirrelmail/templates/squirrelmail/avelsieve-config.php -text
|
||||
squirrelmail/unavelsieve -text
|
||||
src/Makefile -text
|
||||
src/alternc-check -text
|
||||
src/alternc-dboptimize -text
|
||||
|
|
|
@ -30,13 +30,13 @@
|
|||
*/
|
||||
function procmail2sieve() {
|
||||
global $ROOT;
|
||||
$d=opendir($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);
|
||||
$e=@opendir($ROOT."/".$c);
|
||||
if ($e) {
|
||||
while ($f=readdir($e)) {
|
||||
if (substr($f,0,1)==".") continue; // skip hidden files
|
||||
|
@ -46,11 +46,16 @@ function procmail2sieve() {
|
|||
}
|
||||
}
|
||||
closedir($e);
|
||||
} else {
|
||||
echo "ERROR: Cannot open ".$ROOT."/".$c."\n";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
closedir($d);
|
||||
} else {
|
||||
echo "FATAL: cannot open ".$ROOT."\n";
|
||||
exit();
|
||||
}
|
||||
} /* procmail2sieve */
|
||||
|
||||
|
@ -61,6 +66,7 @@ function procmail2sieve() {
|
|||
*/
|
||||
function parseOneProcmail($user) {
|
||||
global $SIEVEROOT;
|
||||
$email=preg_replace("#_([^_]*)$#","@$1",$user);
|
||||
if ($rules=readrules($user)) { /* ################## SUB FUNCTION ###################### */
|
||||
for($i=0; $i<count($rules); $i++) {
|
||||
list($rules[$i]["conds"],$rules[$i]["actionparam"])=describe($rules[$i]); /* ################## SUB FUNCTION ###################### */
|
||||
|
@ -69,15 +75,145 @@ function parseOneProcmail($user) {
|
|||
// Now we have $rule["type"] = the ACTION to accomplish + (if 1 or 4) $actionparam
|
||||
// and a list of $rule["conds"][0]=condition type & $rule["conds"][1]=condition parameter (if not 5)
|
||||
// Let's write a sieve script :)
|
||||
$f=fopen($SIEVEROOT."/".$user,"wb");
|
||||
$u=substr($u,0,1);
|
||||
@mkdir($SIEVEROOT."/".$u."/".$user."/sieve");
|
||||
@mkdir($SIEVEROOT."/".$u."/".$user."/sieve/tmp");
|
||||
$uid=fileowner($SIEVEROOT."/".$u."/".$user);
|
||||
chown($SIEVEROOT."/".$u."/".$user."/sieve",$uid);
|
||||
chgrp($SIEVEROOT."/".$u."/".$user."/sieve","vmail");
|
||||
chown($SIEVEROOT."/".$u."/".$user."/sieve/tmp",$uid);
|
||||
chgrp($SIEVEROOT."/".$u."/".$user."/sieve/tmp","vmail");
|
||||
|
||||
$f=fopen($SIEVEROOT."/".$u."/".$user."/sieve/tmp/phpscript.sieve","wb");
|
||||
if (!$f) {
|
||||
echo "ERROR: Can't open '$user' in '$SIEVEROOT' for writing\n";
|
||||
} else {
|
||||
echo "OK: writing sieve script for $user (".count($rules)." rules)\n";
|
||||
|
||||
// FIXME: DO IT :)
|
||||
$avelsieveversion=array("major" => 1, "minor"=>9, "release" => 9, "string" => "1.9.9");
|
||||
fputs($f,'# This script has been automatically generated by avelsieve
|
||||
# (Sieve Mail Filters Plugin for Squirrelmail)
|
||||
# Warning: If you edit this manually, then the changes will not
|
||||
# be reflected in the users\' front-end!
|
||||
#AVELSIEVE_VERSION'.urlencode(base64_encode(serialize($avelsieveversion))).'
|
||||
#AVELSIEVE_CREATED'.time().'
|
||||
#AVELSIEVE_MODIFIED'.time().'
|
||||
require ["fileinto","envelope","reject","vacation","imap4flags","relational","comparator-i;ascii-numeric","regex","body","date"];
|
||||
');
|
||||
foreach($rules as $rule) {
|
||||
if ($rule["type"]==2) continue; // IGNORE "Filter the message through SpamAssassin"
|
||||
|
||||
// Create the avelsieve array:
|
||||
$avelrule=array();
|
||||
// And sieve script:
|
||||
$script="if ";
|
||||
$avelrule["condition"]="and";
|
||||
$avelrule["type"]=1;
|
||||
if (!count($rule["conds"])) {
|
||||
// no conditions
|
||||
$script.="true\n";
|
||||
$avelrule["cond"][]=array("kind" => "message", "type" => "all");
|
||||
} else { // have conditions
|
||||
$script.="allof (";
|
||||
$first=true;
|
||||
foreach($conds as $cond) {
|
||||
if (!$first) $script.=",\n";
|
||||
$first=false;
|
||||
// What kind of condition?
|
||||
switch($cond[0]) {
|
||||
case 0: // subject
|
||||
$script.='header :contains "Subject" "'.str_replace('"','\\"',$cond[1]).'"';
|
||||
$avelrule["cond"][]=array("kind" => "message", "type" => "header", "header" => "Subject", "matchtype" => "contains", "headermatch" => $cond[1] );
|
||||
break;
|
||||
case 1: // sender
|
||||
$script.='header :contains "From" "'.str_replace('"','\\"',$cond[1]).'"';
|
||||
$avelrule["cond"][]=array("kind" => "message", "type" => "header", "header" => "From", "matchtype" => "contains", "headermatch" => $cond[1] );
|
||||
break;
|
||||
case 2: // recipient
|
||||
$script.='address :contains ["to", "cc"] "'.str_replace('"','\\"',$cond[1]).'"';
|
||||
$avelrule["cond"][]=array("kind" => "message", "type" => "address", "address" => "toorcc", "matchtype" => "contains", "addressmatch" => $cond[1] );
|
||||
break;
|
||||
case 3: // List-Post
|
||||
$script.='header :contains "List-Post" "'.str_replace('"','\\"',$cond[1]).'"';
|
||||
$avelrule["cond"][]=array("kind" => "message", "type" => "header", "header" => "List-Post", "matchtype" => "contains", "headermatch" => $cond[1] );
|
||||
break;
|
||||
case 4: // List-Id
|
||||
$script.='header :contains "List-Id" "'.str_replace('"','\\"',$cond[1]).'"';
|
||||
$avelrule["cond"][]=array("kind" => "message", "type" => "header", "header" => "List-Id", "matchtype" => "contains", "headermatch" => $cond[1] );
|
||||
break;
|
||||
case 5: // Spamassassin
|
||||
$script.='header :contains "X-Spam-Status" "Yes"';
|
||||
$avelrule["cond"][]=array("kind" => "message", "type" => "header", "header" => "X-Spam-Status", "matchtype" => "contains", "headermatch" => "Yes" );
|
||||
break;
|
||||
case 6: // Delivered-To
|
||||
$script.='envelope :contains "to" "'.str_replace('"','\\"',$cond[1]).'"';
|
||||
$avelrule["cond"][]=array("kind" => "message", "type" => "envelope", "envelope" => "to", "matchtype" => "contains", "envelopematch" => $cond[1] );
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
$script.=")\n{\n";
|
||||
}
|
||||
// Now the ACTION:
|
||||
switch($rule["type"]) {
|
||||
case 1: // move to
|
||||
$script.='fileinto "'.str_replace('"','\\"',$rule["actionparam"]).'";
|
||||
stop;
|
||||
';
|
||||
$avelrule["action"] = 5;
|
||||
$avelrule["folder"] = $rule["actionparam"];
|
||||
$avelrule["stop"] = "on";
|
||||
break;
|
||||
case 3: // Discard (for good)
|
||||
$script.='discard;
|
||||
stop;
|
||||
';
|
||||
$avelrule["action"] = 2;
|
||||
$avelrule["stop"] = "on";
|
||||
break;
|
||||
case 4: // Forward To (copy)
|
||||
$script.='redirect "'.str_replace('"','\\"',$rule["actionparam"]).'";
|
||||
';
|
||||
$avelrule["action"] = 4;
|
||||
$avelrule["redirectemail"] = $rule["actionparam"];
|
||||
break;
|
||||
case 5: // Auto-Reply
|
||||
$script.='vacation :days 7 :addresses ["'.$email.'"@ :subject "Auto Reply" text:
|
||||
'.str_replace("\\'","'",@file_get_contents($ROOT."/".$u."/".$user."/".$user.".txt")).'
|
||||
.
|
||||
;
|
||||
';
|
||||
$avelrule["action"] = 6;
|
||||
$avelrule["vac_addresses"] = $email;
|
||||
$avelrule["vac_subject"] = "Auto Reply";
|
||||
$avelrule["vac_days"] = 7;
|
||||
$avelrule["vac_message"] = @file_get_contents($ROOT."/".$u."/".$user."/".$user.".txt");
|
||||
break;
|
||||
}
|
||||
$script.="}\n";
|
||||
// Now put it into the script file :
|
||||
fputs($f,"#START_SIEVE_RULE".urlencode(base64_encode(serialize($avelrule)))."END_SIEVE_RULE\n");
|
||||
fputs($f,$script);
|
||||
/*
|
||||
if allof (header :contains "From" "expediteur@coin.pan",
|
||||
header :contains "To" "destinataire@coin.pan")
|
||||
{
|
||||
fileinto "INBOX.test";
|
||||
stop;
|
||||
}
|
||||
*/
|
||||
} /* for each rule */
|
||||
|
||||
fclose($f);
|
||||
|
||||
// Then Move it to the right place
|
||||
@unlink($SIEVEROOT."/".$u."/".$user."/sieve/phpscript.sieve");
|
||||
rename(
|
||||
$SIEVEROOT."/".$u."/".$user."/sieve/tmp/phpscript.sieve",
|
||||
$SIEVEROOT."/".$u."/".$user."/sieve/phpscript.sieve"
|
||||
);
|
||||
chown($SIEVEROOT."/".$u."/".$user."/sieve/phpscript.sieve",$uid);
|
||||
chgrp($SIEVEROOT."/".$u."/".$user."/sieve/phpscript.sieve","vmail");
|
||||
}
|
||||
} else {
|
||||
echo "ERROR: can't read rules for $user\n";
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
if (empty($argv[1])) {
|
||||
echo "Usage: unavelsieve <file or string>\nPrint the content of an avelsieve-encoded string\n";
|
||||
exit();
|
||||
}
|
||||
if (is_file($argv[1])) {
|
||||
$content=file_get_contents($argv[1]);
|
||||
} else {
|
||||
$content=$argv[1];
|
||||
}
|
||||
|
||||
print_r(unserialize(base64_decode(urldecode($content))));
|
||||
|
Loading…
Reference in New Issue