Goleusov Alexander wrote:
> Sergey Chumakov wrote:
>> На Thu, 05 Jun 2008 12:07:16 +0500
>> "Goleusov Alexander" <CGatePro@mx.ru> записано:
>>
>>
>>> Встала задача: потереть все письма в ящике абонента.
>>> Попробовал сделать это соотвественно в каталоге этого пользователя
>>> удалением файла INBOX.mbox
>>> Затем создал такой же новый файл нулевого размера с темиже правами
>>> доступа и принадлежности (CGPro стоит под фрибсд)
>>> Но при отправке этому пользователю письма оно доставилось ему но в
>>> логах вижу кучу ругани.
>>>
>>> Так всеже как правильно чистить все письма в ящике юзера?
>>>
>>>
>>
>> IMAP/POP3
>>
>>
> Именно не забрать письма (тем самым почистив ящик) а удалить их.
>
Через CLI. Вот скрипт что удаляет почту в папке Spam старше 7 дней
#!/usr/bin/perl -w # # The old mail deletion script for CommuniGate Pro. # # This script deletes all mail older than the number of days specified below # in $keepForDays variable. The time is compared against messages' INTERNALDATE # attribute which may be not the same as the date when the message was received, # so don't get confused if after the deletion you see messages older than expected. # # The mail is deleted from all mailboxes in all accounts in all domains, # including mailing list archives. Mail marked for deletion by users is also # deleted. You may want to modify this script to process not all but only certain # domains or accounts. Use this script with extreme care becasue mail once deleted # is not recoverable. # # Please mail your comments and suggestions to <support@stalker.com> #
my $keepForDays = 7;
use CLI;
my $deadlineDate=getDeadlineDate();
print "\nWARNING!!!\n";
print "This script will delete messages received before $deadlineDate from all\n"; print "mailboxes in all acounts in all domains. Make sure you know what you're\n"; print "doing. It's not too late to hit Ctrl-C.\n\n";
print "CommuniGate Pro domain: ";
my $Domain = 'Your_domain.tld';
#my $Domain = <STDIN>;
#chomp $Domain;
$CGServerAddress = $Domain;
#my $Login = "Postmaster\@$Domain";
my $Login = "postmaster\@$Domain";
print "Postmaster's password: ";
my $Password = '*****';
#my $Password = <STDIN>;
#chomp $Password;
$imap->autoflush(1);
my $responseLine = <$imap>;
print "$responseLine\n";
print $imap "x LOGIN $Login $Password\n"; do {
$responseLine = <$imap>;
}until($responseLine =~/^x /);
die "*** Can't login to CGPro IMAP: $responseLine.\n" unless($responseLine =~ /^x OK/);
my $cli = new CGP::CLI( { PeerAddr => $CGServerAddress,
PeerPort => 106, login => $Login, password => $Password } ) || die "*** Can't login to CGPro CLI: ".$CGP::ERR_STRING."\n";
processAccount('yashik@domen.zone');
#processAllDomains();
exit;
sub processAllDomains() {
my $DomainList = $cli->ListDomains()
|| die "*** Can't get the domain list: ".$cli->getErrMessage.", quitting";
foreach(@$DomainList) {
processDomain($_);
}
}
sub processDomain() {
my $domain=$_[0];
print "Domain: $domain\n";
my $accountList = $cli->ListAccounts($domain);
unless($accountList) {
print "*** Can't get accounts for $domain: ".$cli->getErrMessage."\n";
return;
} foreach(keys %$accountList) {
processAccount("$_\@$domain"); }
}
sub processAccount() {
my $account=$_[0];
#print "Account: $account\n";
print "Account: $account\n";
my $mailboxesList=$cli->ListMailboxes(accountName=>$account); unless($mailboxesList) {
print "*** Can't list mailboxes for $account:".$cli->getErrMessage."\n";
return;
}
foreach(keys %$mailboxesList) {
my $data=@$mailboxesList{$_};
if(ref $data eq 'HASH') {
my $nMessages=@$data{'Messages'}; if(defined $nMessages && $nMessages eq 0) { #print "skipping empty $account/$_\n"; print "skipping empty $account/$_\n"; next; }
#processMailbox("$account/$_");
# стираем только в папке Spam
processMailbox("$account/Spam");
}
}
sub processMailbox() { my $mailbox=$_[0]; my $delList = "";
print "Mailbox: $mailbox\n";
#print $imap "x SELECT \"~$mailbox\"\n";
print $imap "x SELECT \"~$mailbox\"\n";
do {
$responseLine = <$imap>;
}until($responseLine =~/^x /);
unless($responseLine =~ /^x OK/) {
print "*** Can't select $mailbox: $responseLine.\n";
return;
}
print $imap "x SEARCH BEFORE $deadlineDate UNDELETED\n";
do {
$responseLine = <$imap>;
if($responseLine =~ /^\* SEARCH (.+)/) {
$delList.=' ' if($delList ne ""); $delList.=$1;
if($delList ne "") {
$delList =~ s/ /\,/g;
print "Mailbox: $mailbox\n";
print "deletion list=$delList\n";
#return;
print $imap "s STORE $delList +FLAGS (\\Deleted)\n";
do {
$responseLine = <$imap>;
}until($responseLine =~/^s /);
unless($responseLine =~ /^s OK/) {
print "*** Can't store flags for $mailbox messages: $responseLine.\n";
}
print $imap "c CLOSE\n";
do {
$responseLine = <$imap>;
}until($responseLine =~/^c /);
unless($responseLine =~ /^c OK/) {
print "*** Can't close $mailbox: $responseLine.\n";
}
}
}
sub getDeadlineDate() {
my @mNames=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my $deadlineTime=time()-$keepForDays*24*60*60;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($deadlineTime);
return $mday.'-'.$mNames[$mon].'-'.(1900+$year);
}
Получено Thu Jun 05 07:47:59 2008
Этот архив был сгенерирован hypermail 2.1.8 : Fri 24 Apr 2015 - 16:16:06 MSK