| |
| use Cyrus::IMAP::Admin; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| my $quota_attr = "mailQuota"; |
| my $mail_attr = "mailRoutingAddress"; |
| my $user = "cyrus"; |
| my $passwd = "blah"; |
| |
| |
| my @entries = (); |
| my $index = 0; |
| my $counter = 0; |
| my $old_timestamp = 0; |
| my $timestamp = "199412161032Z"; |
| |
| |
| |
| |
| |
| |
| |
| { |
| if (-e "/etc/cyrus_ldap_quota_time") |
| { |
| open(TIME_FILE, "/etc/cyrus_ldap_quota_time") or die "could not |
| open the time file: $!\n"; |
| |
| while(<TIME_FILE>) { $old_timestamp = $_; } |
| |
| close(TIME_FILE); |
| } |
| |
| |
| |
| |
| unless ($old_timestamp == 0) { $timestamp = $old_timestamp; } |
| |
| |
| |
| |
| |
| |
| open(TIME_FILE, ">/etc/cyrus_ldap_quota_time") or die "could not |
| create file: $!\n"; |
| |
| my @time = (localtime)[0..5]; |
| |
| printf TIME_FILE $time[5] + 1900; |
| printf TIME_FILE "%02d", $time[4] + 1; |
| for (my $i = 3; $i >= 0; $i--) { printf TIME_FILE "%02d", $time[$i];} |
| print TIME_FILE 'Z'; |
| |
| close(TIME_FILE); |
| } |
| |
| |
| |
| |
| { |
| |
| |
| |
| |
| |
| (my $query = "ldapsearch -x '(&(modifyTimestamp>=$timestamp)($quota_attr=*))' $quota_attr $mail_attr |
| | grep -v ^# | grep -v ^dn | grep -v ^version | grep -v ^search | grep -v ^result | grep -v ^\$") =~ s!\n!!; |
| |
| |
| my $result = `$query`; |
| |
| |
| |
| my @output = split(/\n/, $result); |
| |
| |
| foreach (@output) |
| { |
| |
| (my $key, my $value) = split(/: /); |
| |
| |
| if ($value =~ m!@!) |
| { |
| ($value, undef) = split (/@/, $value); |
| } |
| |
| |
| $entries[$index]{$key} = $value; |
| |
| |
| |
| if ($counter % 2) |
| { |
| $index++; |
| } |
| |
| $counter++; |
| } |
| } |
| |
| |
| |
| { |
| my $imap = Cyrus::IMAP::Admin->new('localhost') or die "imap: |
| cannot connect to server: $!\n"; |
| |
| $imap->send(undef, undef, "LOGIN %s %s", $user, $passwd) or die |
| "could not send user:pass to the server: $!\n"; |
| |
| for (my $i = 0; $i <= $#entries; $i++) |
| { |
| $imap->setquota("user." . $entries[$i]{$mail_attr}, "STORAGE", |
| $entries[$i]{$quota_attr}) |
| or die "imap: could not set quota for |
| user.$entries[$i]{$mail_attr}: $!\n"; |
| } |
| |
| $imap=undef; |
| } |