• Plesk Uservoice will be deprecated by October. Moving forward, all product feature requests and improvement suggestions will be managed through our new platform Plesk Productboard.
    To continue sharing your ideas and feedback, please visit features.plesk.com

Interesting email issue - In need of assistance

C

criticman

Guest
Alright, spammer got in, took care of that issue.

Failure notices galore in one inbox.

Attempting to login to webmail fails, and all IMAP and POP3 attempts timeout (we're talking nearly 200,000 messages in this box).

So, is there a command line way to delete messages containing "failure notice" in them? I know where the mailbox is in terms of the qmail mailname Maildir. I am just blanking on the command to locate messages with "failure notice" in them and automatically delete messages it matches.

I believe there are some important messages among the junk and need to be able to find them - so a complete deletion of the Maildir file contents using find -type f....etc will not be sufficient.

Thanks!
 
Below is a script that should do the job. You would execute it was follows:

./rm-maildir-messages.pl /var/qmail/mailnames/xyz.com/sales/Maildir "^Subject: failure notice$"

Code:
#!/usr/bin/perl

use strict;
use FileHandle;

my ($Maildir) = $ARGV[0] || die "Maildir not provided.\n";
my ($regexp) = qr/$ARGV[1]/;

MAIN:
{
   my ($subdir);

   unless (scalar @ARGV == 2)
   {
      die "$0 <maildir> <regexp>\n";
   }

   for $subdir ('cur', 'new')
   {
      clean_maildir ($Maildir . '/' . $subdir);
   }
};

sub clean_maildir
{
   my ($dirname) = @_;
   my ($dh) = new FileHandle();
   my ($file);

   opendir ($dh, $dirname) or die $!;

   while ($file = readdir ($dh))
   {
      next unless (-f $dirname . '/' . $file);

      my ($fh) = new FileHandle();
      next unless ($fh->open ($dirname . '/' . $file));

      while (<$fh>)
      {
         s/[\r\n]+$//;
         if ($_ =~ $regexp)
         {
#            printf "%s/%s\n", $dirname, $file;
            unlink ($dirname . '/' . $file);
         }
      }

      $fh->close();
   }

   closedir ($dh);
}
 
Back
Top