smeserver-mailsorting/root/etc/e-smith/templates-user/.procmailrc/40global

167 lines
4.8 KiB
Plaintext

{
use esmith::config;
use esmith::db;
my %processmail;
tie %processmail, 'esmith::config', '/home/e-smith/db/processmail';
#get Global rules
my @pmGlobRules = ();
foreach (sort keys %processmail)
{
push (@pmGlobRules, $_)
if (db_get_type(\%processmail, $_) eq 'pmGlobalRule');
}
#if they have rules add them to the templete
my $pmGlobRules = @pmGlobRules || '0';
if ($pmGlobRules > 0)
{
$OUT .= "\n";
$OUT .= "# ---start of Global rules---------\n";
my $pmGlobRule;
foreach $pmGlobRule (sort {$a <=> $b} @pmGlobRules)
{
my $basis = db_get_prop(\%processmail, $pmGlobRule, "basis") || '';
my $criterion = db_get_prop(\%processmail, $pmGlobRule, "criterion") || '';
my $basis2 = db_get_prop(\%processmail, $pmGlobRule, "basis2") || '';
my $secondtest = db_get_prop(\%processmail, $pmGlobRule, "basis2") || '';
my $criterion2 = db_get_prop(\%processmail, $pmGlobRule, "criterion2") || '';
my $deliver = db_get_prop(\%processmail, $pmGlobRule, "deliver") || '';
my $deliver2 = db_get_prop(\%processmail, $pmGlobRule, "deliver2") || '';
my $copy = db_get_prop(\%processmail, $pmGlobRule, "copy") || '';
my $action = db_get_prop(\%processmail, $pmGlobRule, "action") || '';
my $action2 = db_get_prop(\%processmail, $pmGlobRule, "action2") || '';
unless (($zarafa1 eq 'enabled') || ($zarafa2 eq 'enabled'))
{
$deliver =~ s/ /\\ /g;
$deliver2 =~ s/ /\\ /g;
}
foreach ($basis, $basis2)
{
## headers include the basis in the criterion
if ($_ eq 'headers')
{
$_ = '';
}
## size doesn't use '^. *' but needs a space
if ($_ ne '<')
{
if ($_ ne '>')
{
#[sme 2264] remove .* after TO_ macro
if ($_ eq 'TO_')
{
#[sme 6061 remove space after TO_
$_ = "^"."$_"."";
}
else
{
$_ = "^"."$_".".*";
}
}
else
{
$_ = $_.' ';
}
}
else
{
$_ = $_.' ';
}
}
##construct the deliver line
if (($action eq 'sort') || ($action eq 'create'))
{
# to a folder
if (($zarafa1 eq 'enabled') || ($zarafa2 eq 'enabled'))
{
if ($deliver eq 'junkmail')
{ $deliver = "| zarafa-dagent -j $USERNAME"; }
else
{ $deliver = "| zarafa-dagent $USERNAME -C -F 'Inbox\\$deliver'"; }
}
else
{ $deliver = "\$MAILDIR/".'.'."$deliver"."/"; }
}
elsif ($action eq 'forward')
{
# to an email
$deliver = "! "."$deliver";
}
elsif ($action eq 'delete')
{
# delete it
$deliver = '/dev/null';
}
else
{
# freeform
$deliver = "$deliver";
}
##construct the 2nd deliver line
if ($action2 eq 'sort')
{
# to a folder
if (($zarafa1 eq 'enabled') || ($zarafa2 eq 'enabled'))
{
if ($deliver eq 'junkmail')
{ $deliver = "| zarafa-dagent -j $USERNAME"; }
else
{ $deliver = "| zarafa-dagent $USERNAME -C -F 'Inbox\\$deliver'"; }
}
else
{ $deliver = "\$MAILDIR/".'.'."$deliver2"."/"; }
}
elsif ($action2 eq 'forward')
{
# to an email
$deliver2 = "! "."$deliver2";
}
## construct the rule
if ($secondtest ne '')
{
$secondtest = "* "."$basis2"."$criterion2"."\n";
}
if ($copy eq 'no')
{
$OUT .= "\n";
$OUT .= ":0\n";
$OUT .= "* "."$basis"."$criterion"."\n";
$OUT .= $secondtest;
$OUT .= "$deliver\n";
}
elsif ($copy eq 'yes' && $action2 eq 'inbox')
{
$OUT .= "\n";
$OUT .= ":0 c\n";
$OUT .= "* "."$basis"."$criterion"."\n";
$OUT .= $secondtest;
$OUT .= "$deliver\n";
}
else
{
$OUT .= "\n";
$OUT .= ":0\n";
$OUT .= "* "."$basis"."$criterion"."\n";
$OUT .= $secondtest;
$OUT .= "\{\n";
$OUT .= " :0 c\n";
$OUT .= " $deliver\n";
$OUT .= " \n";
$OUT .= " :0\n";
$OUT .= " $deliver2\n";
$OUT .= "\}\n";
}
}#foreach rule
}#if rules exist
}