im
changeset 0 2a5f2464f8c6
equal deleted inserted replaced
-1:000000000000 0:2a5f2464f8c6
       
     1 #! /usr/bin/perl
       
     2 # © 2005 Heiko Schlittermann
       
     3 # $Id$
       
     4 # $URL$
       
     5 
       
     6 # small template for action on all imap folders
       
     7 # or simlar quatsch
       
     8 
       
     9 use strict;
       
    10 use warnings;
       
    11 use AppConfig;
       
    12 
       
    13 use Mail::IMAPClient;
       
    14 use Cyrus::IMAP::Admin;
       
    15 
       
    16 use constant QUOTA => 200000;	# kiloByte
       
    17 
       
    18 use constant CONFIG => (
       
    19 	{ CASE => 1 },
       
    20 	quota => { DEFAULT => 200000, ARGS => "=i" },
       
    21 	force => { DEFAULT => undef, ARGS => "!" },
       
    22 );
       
    23 
       
    24 my $Cf = new AppConfig CONFIG;
       
    25    $Cf->getopt(\@ARGV);
       
    26 
       
    27 my $imap = new Cyrus::IMAP::Admin("localhost") or die;
       
    28 # $imap->authenticate(-user => "root", -password => "hallo") or die;
       
    29 $imap->authenticate(-user => "root") or die;
       
    30 
       
    31 foreach ($imap->list("user/*")) {
       
    32 	my ($mb, $att, $sep) = @$_;
       
    33 
       
    34 	next unless $mb =~ /^user\/[^\/]+$/;
       
    35 	print "$mb";
       
    36 
       
    37 	my ($qroot, $quota) = $imap->listquotaroot($mb);
       
    38 	if ($qroot && $qroot ne $mb) { 
       
    39 		print " QuotaRoot; $qroot\n";
       
    40 		next;
       
    41 	}
       
    42 
       
    43 	my %q = $imap->listquota($mb);
       
    44 	if (exists $q{STORAGE} and !$Cf->force) {
       
    45 		my ($used, $max) = @{$q{STORAGE}};
       
    46 		print " Quota $used/$max " . int($used/$max*100) . "%";
       
    47 	} else {
       
    48 		$imap->setquota($mb, "STORAGE" => $Cf->quota) or die;
       
    49 	}
       
    50 
       
    51 	print "\n";
       
    52 	
       
    53 }