initial commit of file from CVS for smeserver-mailsorting on Sat Sep 7 19:56:19 AEST 2024

This commit is contained in:
Trevor Batley
2024-09-07 19:56:19 +10:00
parent 37ac171721
commit 747f415ed0
59 changed files with 6609 additions and 2 deletions

View File

@@ -0,0 +1,21 @@
{
# vim: ft=perl:
use esmith::AccountsDB;
use esmith::ConfigDB;
our $adb = esmith::AccountsDB->open_ro or die "Couldn't open AccountsDB";
our $cdb = esmith::ConfigDB->open_ro or die "Couldn't open ConfigDB";
$user = $adb->get($USERNAME) or die "No user $USERNAME in AccountsDB";
%props = $user->props;
our $sievesupport = $cdb->get_prop('sieve','status') || 'disabled';
our $sieveuser = $props{Sieve} || 'enabled';
our $zarafa1 = $props{zarafa} || 'disabled1';
our $zarafa2 = ${'zarafa-server'}{GlobalForward} || 'disabled2';
our $EmailForward = $props{EmailForward} || '';
our $ForwardAddress = $props{ForwardAddress} || '';
$OUT = '';
}

View File

@@ -0,0 +1,24 @@
{
if ($USERNAME ne 'admin')
{
$OUT .= "# ---- Defaults ------------------\n";
$OUT .= "SHELL=/bin/bash\n";
$OUT .= "DEFAULT=\$HOME/Maildir/\n";
$OUT .= "FORMAIL=/usr/bin/formail\n";
$OUT .= "MAILDIR=\$HOME/Maildir/\n";
$OUT .= "PMDIR=\$HOME\n";
$OUT .= "SENDMAIL=/usr/sbin/sendmail\n";
}
elsif ($USERNAME eq 'admin')
{
$OUT .= "# ---- Defaults ------------------\n";
$OUT .= "SHELL=/bin/bash\n";
$OUT .= "DEFAULT=/home/e-smith/Maildir/\n";
$OUT .= "FORMAIL=/usr/bin/formail\n";
$OUT .= "MAILDIR=/home/e-smith/Maildir/\n";
$OUT .= "PMDIR=/home/e-smith\n";
$OUT .= "SENDMAIL=/usr/sbin/sendmail\n";
}
}

View File

@@ -0,0 +1,47 @@
{
use esmith::config;
use esmith::db;
my %processmail;
tie %processmail, 'esmith::config', '/home/e-smith/db/processmail';
$OUT = '';
# control level of logging
my $loglevel = db_get_prop(\%processmail, $USERNAME, "loglevel") || 'some';
if ($loglevel eq 'none')
{
$OUT .= "\n";
$OUT .= "# ---- no logging ------------------\n";
}
elsif ($loglevel eq 'some')
{
$OUT .= "\n";
$OUT .= "# ---- some logging------------------\n";
$OUT .= "VERBOSE=no\n";
if ($USERNAME ne "admin")
{
$OUT .= "LOGFILE=\$HOME/procmail.log\n";
}
if ($USERNAME eq "admin")
{
$OUT .= "LOGFILE=/home/e-smith/procmail.log\n";
}
}
else
{
$OUT .= "\n";
$OUT .= "# ---- verbose, for debugging only --------------\n";
$OUT .= "VERBOSE=yes\n";
$OUT .= "LOGABSTRACT=all\n";
if ($USERNAME ne "admin")
{
$OUT .= "LOGFILE=\$HOME/procmail.log\n";
}
if ($USERNAME eq "admin")
{
$OUT .= "LOGFILE=/home/e-smith/procmail.log\n";
}
}
}

View File

@@ -0,0 +1,6 @@
{
$OUT .= "\n";
$OUT .= "# ---- delete duplicates -------\n";
$OUT .= ":0 Wh: msgid.lock\n";
$OUT .= "| \$FORMAIL -D 8192 msgid.cache\n";
}

View File

@@ -0,0 +1,166 @@
{
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
}

View File

@@ -0,0 +1,167 @@
{
use esmith::config;
use esmith::db;
my %processmail;
tie %processmail, 'esmith::config', '/home/e-smith/db/processmail';
# get users rules
my @pmRules = ();
foreach (sort keys %processmail)
{
push (@pmRules, $_)
if (db_get_type(\%processmail, $_) eq $USERNAME);
}
# if they have rules add them to the templete
my $pmRules = @pmRules || '0';
if ($pmRules > 0)
{
$OUT .= "\n";
$OUT .= "# ---- user rules ------------------\n";
my $pmRule;
foreach $pmRule (sort @pmRules)
{
my $basis = db_get_prop(\%processmail, $pmRule, "basis") || '';
my $criterion = db_get_prop(\%processmail, $pmRule, "criterion") || '';
my $basis2 = db_get_prop(\%processmail, $pmRule, "basis2") || '';
my $secondtest = db_get_prop(\%processmail, $pmRule, "basis2") || '';
my $criterion2 = db_get_prop(\%processmail, $pmRule, "criterion2") || '';
my $deliver = db_get_prop(\%processmail, $pmRule, "deliver") || '';
my $deliver2 = db_get_prop(\%processmail, $pmRule, "deliver2") || '';
my $copy = db_get_prop(\%processmail, $pmRule, "copy") || '';
my $action = db_get_prop(\%processmail, $pmRule, "action") || '';
my $action2 = db_get_prop(\%processmail, $pmRule, "action2") || '';
#allow for spaces _ to \_
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
}

View File

@@ -0,0 +1,23 @@
{
$OUT .= "\n";
$OUT .= "# ---- to the inbox------------------\n";
if (($zarafa1 eq 'enabled') || ($zarafa2 eq 'enabled'))
{
$OUT .= ":0\n";
$OUT .= "| zarafa-dagent $USERNAME \n";
}
elsif (($sieveuser eq 'enabled') && ($sievesupport eq 'enabled'))
{
$OUT .= ":0 w\n";
$OUT .= "\| /usr/libexec/dovecot/deliver\n";
}
else
{
$OUT .= ":0\n";
$OUT .= "\$DEFAULT\n";
}
$OUT .= "\n";
$OUT .= "# ---- end of rules ------------------\n";
}