[ale] IMAP slowness

Christopher Fowler cfowler at outpostsentinel.com
Fri Apr 22 10:34:16 EDT 2005


Part of me is leaning on making the quota part of our automated mail
system instead of an OS feature.  I'm hacking out something in perl and
you can see what I've got below.  Maybe the all might powerful perl guru
Fletch will have some pointers.

--- Cut Here ---

use strict;

die "quota.pl <user> <quotalimit>\n" unless $ARGV[0];
my $logname = $ARGV[0];
my $quotalimit = $ARGV[1];

$quotalimit = (300 * 1024 * 1024) unless $quotalimit;


sub get_total_bytes {
  my $bytes = 0;
  opendir(D, "/home/$logname/INBOX");
  my @files = readdir D;
  closedir D;

  foreach my $file (@files) {
    next if $file =~ /^\./;
    $bytes += (stat("/home/$logname/INBOX/$file"))[7];
  }

  # Add the users INBOX
  $bytes += (stat("/var/spool/mail/$logname"))[7];

  return $bytes;
}


my $bytes = get_total_bytes();

# If we are too high we need to save this somewhere else
if($bytes >= $quota_limit) {
  open(STORE, ">/home/$logname/QUOTA_STORAGE/mail.$$.".time());
  while(<STDIN>) {
    print STORE $_;
  }

  close STORE;
  # Eamil is in storage we need to exist it.  We might
  # want to use Net::SMTP to email the user to let them know
  # what we have delayed their email.  We could imply reject the
  # email and instead of stoing in QUOTA_STORAGE we can reply
  # back to the sender wiht a error message that the users Quota
  # has been esceeded.
  exit 0;

}

--- Cut Here ---

I think I like the idea of redirecting the email /dev/null and sending a
reply to the sender from the user that the quota has been exceeded.   It
keeps the system simple and is what many SMTP servers do.  Just in this
case this program would be generating the error and not the SMTP server.

Anyone got and great ideas on how to tackle this problem?
  

On Fri, 2005-04-22 at 10:03, Christopher Fowler wrote:
> There may be hack I can do int .procmailrc that will implment a quota
> foe me without having to upgrade the kernel and etc.  This quota could
> be for mail only.
> 
> 
> I could write a perl program that calculates the size of the Mailbox
> files for a user whenever a mail comes in.  .procmailrc will simply
> execute this program when a mail comes in.
> 
> Kinda like this:
> 
> :0fw
> | checkquota.pl
> 
> If the quota has not been met the mail is simply passed through.  If it
> has been met then this program will simply dump it to an overflow bin
> then send the user an email stating that they received an Email from
> user at domain.com at data with subject and that it could not be placed in
> the users INBOX due to quota restriction.  It was saved and will be
> moved back to the users inbox when quota requirements have been met.
> 
> I can either manually move them or make the program even smarter that
> whenever it does execute it can move the stored emails into their proper
> place.
> 
>  
> On Fri, 2005-04-22 at 09:53, Jason Fritcher wrote:
> > Christopher Fowler wrote:
> > > When we access the IMAP server I see the hdd light on solid for a few
> > > minutes.  They keep saying that the problem is that IMAP can't handle it
> > > and that Exchange will.  With 500M of data in your mailbox I doubt
> > > Exchange can handle it any better than Linux running IMAP.
> > 
> > The problem is UW-IMAP and the mbox format. When mailboxes get that big, they
> > can take a long time to parse fully. I used to run that awhile ago, but switched
> > over to using Courier-IMAP because it uses Maildir format where each message is
> > its own file. Its much quicker for the imap daemon to scan just the headers of a
> > few thousand files than have to parse the headers and bodies of the same
> > messages all stacked up in one file.
> > 
> > > I get in arguments with this guy all the time about mailbox size and
> > > that at a real company he would be given a quota.  Using fetchmail to
> > > retrieve mail from a pop3 server and then procmail to place them in
> > > boxes is there a way I could impose a quota?  Maybe add a filter to
> > > procmailrc that will count the bytes in an email and redirect to
> > > /dev/null if it is greater than 5M.  That could limit the amount of
> > > damage done by quotas.
> > 
> > The quick and dirty solution would be an account level quota using the quota
> > system. But, that might be alot courser than you'd like. :)
> > 
> > --
> > Jason Fritcher
> > jkf at wolfnet.org
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list