Re: [exim] Rejecting over quota at RCPT time - revisited

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Todd Lyons
Ημερομηνία:  
Προς: Robert Blayzor
Υ/ο: exim-users@exim.org
Αντικείμενο: Re: [exim] Rejecting over quota at RCPT time - revisited
Tomorrow, I will be experimenting with jamming the following into a
perl function (I use the embedded perl a lot) and call it as a
condition for a verify_only router, and then defer with an appropriate
quota related message is customer is already over quota to stop
further incoming emails from clogging the queue.


use strict;
use warnings;
# Prints out 0 if over quota (means "not ok")
# Prints out 1 if not over quota
my $local_part = shift();
my $domain     = shift();
print_and_exit(1) if (!defined $local_part || !defined $domain);
# We use hashed subdirectories for mailstores
my $home = "/netapp3/mail/maildirs";
(my $tmp = $domain) =~ s/^(...).*/$1/;
foreach my $char (split(//,$tmp)) {
  $home .= '/';
  $home .= $char =~ /\w/ ? $char : '_';
}


my $file="$home/$domain/$local_part/Maildir/maildirsize";
open(my $fh, "<", $file) or print_and_exit(1);
my @lines = <$fh>;
close($fh);
print_and_exit(1) if (scalar @lines == 0);

my ($quota,$qcount);  # count is calculated, but ignored
my @quota = split(/,/,$lines[0]);
if (scalar @quota > 0) {
  $quota  = substr($quota[0],0,-1)
    if (substr($quota[0],-1) eq 'S');
  $qcount = substr($quota[0],0,-1)
    if (substr($quota[0],-1) eq 'C');
}
print_and_exit(1) if (!defined $quota);


my $line=my $size=my $msgs=0;
do {
$line++;
(my $msgsize, my $msgcount) = split(" ", $lines[$line]);
$size+=$msgsize; $msgs+=$msgcount;
} while ($line < $#lines);

if ($size > $quota) {
print_and_exit(0); # Over quota!
} else {
print_and_exit(1); # Still has room
}

sub print_and_exit {
my $rv = shift() || 0;
print $rv, "\n"; # Need the newline?
exit;
}


Expanded upon original work at
http://www.kutukupret.com/2011/05/18/check-disk-quota-usage-by-parsing-maildirsize/

...Todd


On Wed, Nov 28, 2012 at 6:22 PM, Robert Blayzor <rblayzor.bulk@???> wrote:
> On Nov 28, 2012, at 8:32 PM, Jeremy Harris <jgh@???> wrote:
>> The "quota" option on an appendfile transport is an expanded string;
>> you can basically do what you want with it given a bit of creativity.
>
>
> Well, yes, it is. But that string is expanded regardless if the user is over quota or not. The idea is to trap the over quota condition and act on it.
>
> Perhaps another string thats only expanded only if the over quota condition happens.
>
> --
> Robert Blayzor
> INOC, LLC
> rblayzor@???
> http://www.inoc.net/~rblayzor/
>
>
>
>
> --
> ## List details at https://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/




--
The total budget at all receivers for solving senders' problems is $0.
If you want them to accept your mail and manage it the way you want,
send it the way the spec says to. --John Levine