1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Interesting email issue - In need of assistance

Discussion in 'Plesk for Linux - 8.x and Older' started by criticman, Apr 28, 2006.

  1. criticman

    criticman Guest

    0
     
    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!
     
  2. wagnerch

    wagnerch Guest

    0
     
    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);
    }
    
     
Loading...