* * Licensed under the GNU GPL. For full terms see the file COPYING that came * with the Squirrelmail distribution. * */ /** * Script Variables Schema * NB: Might be Incomplete. * * The following table tries to describe the variables schema that is used by * avelsieve. * * VARIABLES * --------- * AVELSIEVE_CREATED * AVELSIEVE_MODIFIED * AVELSIEVE_COMMENT * * key values comments * --- ------ -------- * type 1, 2, 3, 4 ruletype * * Type: * * 1) // Address Match * Not implemented yet. * * 2) // Header Match * header[$n] * matchtype[$n] "is" | "contains" | "matches" | "lt" | "regex" | ... * headermatch[$n] string * condition undefined | "or" | "and" * * 3) // Size match * sizerel "bigger" | "smaller" * sizeamount int * sizeunit "kb" | "mb" * * 4) // Always * n/a * * * Action * * action 1 | 2 | 3 | 4 | 5 | 6 * * 1) // Keep * * 2) // Discard * * 3) // Reject w/ excuse * * excuse string valid only for: action==3 * * 4) // Redirect * * redirectemail string (email) valid only for: action==4 * * 5) // Fileinto * * folder valid only for: action==5 * * 6) // Vacation * * vac_days int * vac_addresses string * vac_message string valid only for: action==6 * * * -) // All * * keepdeleted boolean valid for all * stop boolean valid for all * notify array valid for all * */ /** * Gets a $rule array and builds a part of a SIEVE script (aka a rule). * * @param $rule A rule array. * @param $type What to return. Can be one of: * verbose = return a (verbose) textual description of the rule. * terse = return a very terse description * rule = return a string with the appropriate SIEVE code. */ function makesinglerule($rule, $type="rule") { global $maxitems; /* Step zero :-) : serialize & encode my array */ $coded = urlencode(base64_encode(serialize($rule))); $out = "#START_SIEVE_RULE".$coded."END_SIEVE_RULE\n"; /* Step one: make the if clause */ /* The actual 'if' will be added by makesieverule() */ $terse = '
';
if($rule['type']=="4") {
$text = _("For ALL incoming messages; ");
$terse .= "ALL";
} else {
$text = ""._("If")." ";
}
switch ($rule['type']) {
case "1": /* address --- slated for the future. */
for ( $i=0; $i<3; $i++) {
$out .= 'address :'.${'address'.$i};
if(${'addressrel'.$i} != "0") {
$out .= ":";
}
}
break;
case "2": /* header */
if(isset($rule['condition'])) {
switch ($rule['condition']) {
case "or":
$out .= "anyof (";
$text .= _("any of the following mail headers match: ");
// $terse .= "ANY (";
break;
case "and":
$out .= "allof (";
$text .= _("all of the following mail headers match: ");
// $terse .= "ALL (";
break;
default: /* condition was not defined, so there's only one header item. */
$lonely = true;
break;
}
}
/* if ( $i "; } elseif ($rule['condition'] == "and" ) { $terse .= " AND "; } } elseif($i == 0 && !isset($rule['headermatch'][1]) ) { // && ($lonely == true) $out .= "\n"; $text .= ", "; } else { $out .= ")\n"; $text .= ", "; } } /* end for */ break; case "3": /* size */ $out .= 'size :'; $text .= _("the size of the message is"); $text .= ""; $terse .= "SIZE"; if($rule['sizerel'] == "bigger") { $out .= "over "; $terse .= " > "; $text .= _(" bigger"); } else { $out .= "under "; $terse .= " < "; $text .= _(" smaller"); } $text .= " "._("than")." ". htmlspecialchars($rule['sizeamount']) . " ". htmlspecialchars($rule['sizeunit']) . ", "; $terse .= $rule['sizeamount']; $out .= $rule['sizeamount']; if($rule['sizeunit']=="kb") { $out .= "K\n"; $terse .= "K\n"; } elseif($rule['sizeunit']=="mb") { $out .= "M\n"; $terse .= "M\n"; } break; case "4": /* always */ $out .= "true\n"; break; } /* step two: make the then clause */ $out .= "{\n"; $terse .= ' | ';
if($rule['type']!="4") {
$text .= "";
$text .= _("then");
$text .= " ";
}
switch ($rule['action']) {
case "1": /* keep (default) */
$out .= "keep;";
$text .= _("keep it.");
$terse .= "KEEP";
break;
case "2": /* discard */
$out .= "discard;";
$text .= _("discard it.");
$terse .= "DISCARD";
break;
case "3": /* reject w/ excuse */
$out .= "reject text:\n".$rule['excuse']."\r\n.\r\n;";
$text .= _("reject it, sending this excuse back to the sender:")." \"".htmlspecialchars($rule['excuse'])."\".";
$terse .= "REJECT";
break;
case "4": /* redirect to address */
$out .= "redirect \"".$rule['redirectemail']."\";";
$text .= _("redirect it to the email address")." ".htmlspecialchars($rule['redirectemail']).".";
$terse .= "REDIRECT ".htmlspecialchars($rule['redirectemail']);
break;
case "5": /* fileinto folder */
$out .= 'fileinto "'.$rule['folder'].'";';
$text .= _("file it into the folder ");
/* FIXME - funny stuff has entered gettext function ... */
$text .= " " . htmlspecialchars(imap_utf7_decode_local($rule['folder'])) . "";
$text .= ".";
$terse .= "FILEINTO ".htmlspecialchars(imap_utf7_decode_local($rule['folder']));
break;
case "6": /* vacation message */
/* Check if $addresses is valid */
/* If vacation address does not exist, put inside the default, which is
* user's addresses. */
if( !isset($rule['vac_addresses']) ||
(isset($rule['vac_addresses']) && trim($rule['vac_addresses'])=="" ) ) {
global $data_dir, $username;
$addresses = getPref($data_dir, $username, 'email_address');
} else {
/* Ugly... */
$addresses = str_replace(",",'","',str_replace(" ","",$rule['vac_addresses']));
}
$out .= 'vacation :days '.$rule['vac_days'].' :addresses ["'.$addresses.
'"] '." text:\n".$rule['vac_message']."\r\n.\r\n;";
/* FIXME: vac_message should be UTF-8 */
/* Perhaps fix that as a a whole, while uploading the script. */
/* Used to be: '"] "'.$rule['vac_message'].'";'; */
$text .= _("reply with this vacation message: ") . htmlspecialchars($rule['vac_message']);
$terse .= "VACATION";
break;
default:
return false;
break;
}
if (isset($rule['keepdeleted'])) {
$text .= _(" Also keep a copy in INBOX, marked as deleted.");
$out .= "\naddflag \"\\\\\\\\\\\\\\\\Deleted\";\nkeep;";
$terse .= " KEEP DELETED"; } if (isset($rule['stop'])) { $text .= _(" Then STOP processing rules."); $out .= "\nstop;"; $terse .= " STOP"; } /* Notify extension: 'method' => string 'id' => string 'options' => array( [0]=> foo, [1] => bar ) 'priority' => low|normal|high 'message' => string notify :method "mailto" :options "koula@intra.com" :message "Sou hrthe ena mail apo .... lala" ; */ if (array_key_exists("notify", $rule) && is_array($rule['notify']) && ($rule['notify']['method'] != '')) { global $notifystrings, $prioritystrings; $text .= _(" Also notify using the method") . " " . htmlspecialchars($notifystrings[$rule['notify']['method']]) . ", ". _("with") . " " . htmlspecialchars($prioritystrings[$rule['notify']['priority']]) . " " . _("priority and the message") . " "" . htmlspecialchars($rule['notify']['message']) . ""."; $out .= "\nnotify :method \"".$rule['notify']['method']."\" "; $out .= ":options \"".$rule['notify']['options']."\" "; if(isset($rule['notify']['id'])) { $out .= ":id \"".$rule['notify']['id']."\" "; } if(isset($rule['notify']['priority']) && array_key_exists($rule['notify']['priority'], $prioritystrings)) { $out .= ":".$rule['notify']['priority'] . " "; } $out .= ":message \"".$rule['notify']['message']."\""; $out .= ";\n"; $terse .= " NOTIFY"; } $out .= "\n}"; $terse .= " |