Script had stoped working after Perl update

Asta Adomaityte <[email protected]> Tue, 11 Jan 2005 12:15:43 +0200
Newsgroups gmane.comp.lang.perl.modules.mail-box
Message-ID <[email protected]>
Hi,

Script had worked nearly one year without any problems ( I wrote it for 
MailBox Manager version
2.051 ).  Script collects 'To' addresses from nested messages (this 
returned not delivered to subscribers messages). Formats the list of 
addresses, unsubscribes them and sends list of unsubscribed email 
addresses to some administrative accounts.

After perl upgrade it only moves mail messages from 'new' to 'old' 
directory and doesn't proceeds them. During work for each proceeded 
message reports the same 3 problems.

Does somebody can say what changes I should do to make script workable 
again with a MailBoxManager 2.059???

Thanks in advance.
Asta

Here are errors which repeats for the each mail messge

Use of uninitialized value in string ne at 
/usr/lib/perl5/site_perl/5.8.2/Mail/Box/Maildir/Message.pm line 100.
Use of uninitialized value in concatenation (.) or string at 
/usr/lib/perl5/site_perl/5.8.2/Mail/Box/Maildir/Message.pm line 105.
Cannot rename 
/home/mail_users/failed_emails/new/002-00:00:00.1104550027.12918_0.newmail.eiendomsnett.no 
to /new/:2,: No such file or directory at 
/usr/lib/perl5/site_perl/5.8.2/Mail/Box/Maildir/Message.pm line 109.

Script source:

#!/usr/bin/perl
#
# Parse from nested messages subscribers address,
# count failures of each in mysql table,
# when mail report about permanent failures,
# format list for automated unsubscribe from db2

use warnings;
use strict;
use lib '..', '.';
use DBI();
use Mail::Box::Manager;
#use Mail::Reporter;

my $dbh = DBI->connect("DBI:mysql:database=z_counter;host=localhost",
                         "z_counter", "z_passwd",
                         {'RaiseError' => 1});
sub collect_to($);

#
# Set arguments.
#

my $foutput = '/root/failed_list/listas.tmp';
my $filename = '/home/mail_users/failed_emails/';
my $start_phrase = 'These eMail addresses have permanent failures: ' . "\n";
my $end_phrase = "\n" . "\n" . 'MailError Revisor';
my $m_from = '[email protected]';
my $m_to = '[email protected]';
my $m_cc = '[email protected]';
my $m_subj = 'Failed email addresses ';
#my ($logl, $tracel) = Mail::Reporter->defaultTrace('WARNINGS', 'DEBUG');
#
# Open the folder
#
my $mgr = Mail::Box::Manager->new(folderdir => $filename);

my $folder = $mgr->open
   ( folder => $filename,
   extract    => 'LAZY'   # never take the body unless needed
   );                       #  which saves memory and time.
die "Cannot open $filename: $!\n"
    unless defined $folder;
#
# List all messages in this folder.
#

my @messages = $folder->messages(0);
my $counter  = 1;
my $prev;
my @to;

sub collect_to($)
  {  

    my $part = shift;
      if(my $to = $part->head->get('to'))
      {   push @to, $to->addresses;

      }
      if($part->isMultipart) { collect_to($_) for $part->body->parts }
      elsif($part->isNested) { collect_to($part->body->nested) }
  }


foreach my $message (@messages)
{  
    printf "%3d. ", $counter++;
    printf $message->printStructure;
    collect_to($message);
}

#printf("Test %s\n", "2");

$prev = '[email protected]';

my $leps;



foreach my $tout (@to)
{
  if ($tout->format ne $prev) {
    $leps = $tout->format;
#   print $tout->format, "\n";
#         print $leps, "\n", "SELECT * FROM counts WHERE mail='$leps'", 
"\n";
         my $sth = $dbh->prepare("SELECT * FROM counts WHERE mail='$leps'");
         if (!$sth) {
                        die "Error:" . $dbh->errstr . "\n";
         }
         if (!$sth->execute) {
                        die "Error:" . $sth->errstr . "\n";
         }
         my $ref = $sth->fetchrow_arrayref;
         $sth->finish();
         my $rfound = (scalar $ref);
        if ($rfound ==0){
#print "INSERT INTO counts (mail,failes,delpoz)  VALUES ('$leps',1,0)";
           $dbh->do("INSERT INTO counts (mail,failes,delpoz)  VALUES 
('$leps',1,0)");
        }
        else {
#print "UPDATE counts SET failes=failes+1 WHERE mail='$leps'";
           $dbh->do("UPDATE counts SET failes=failes+1 WHERE mail='$leps'");
        }
  }
}

# form e-mail with a list fails>5 and send it to

     my $sthh = $dbh->prepare("SELECT mail FROM counts WHERE failes>4");
     if (!$sthh) {
             die "Error:" . $dbh->errstr . "\n";
     }
     if (!$sthh->execute) {
             die "Error:" . $sthh->errstr . "\n";
      }
     my $addr_coll='';
     while (my $rref= $sthh->fetchrow_arrayref){
#print $$rref[0], "\n";
       $addr_coll = $addr_coll . $$rref[0] . "\n";
     }
         $sthh->finish();

#sent

if (length($addr_coll)>0)
{
my $sent_mess = Mail::Message->build
  ( From    => $m_from
  , To      => $m_to
  , Cc      => $m_cc
  , Subject => $m_subj
  , data => $start_phrase . $addr_coll . $end_phrase
 );
$sent_mess->send;

# format list for automated remove in db2

open my $flh, "+> $foutput";
print $flh $addr_coll;

# delete all addresses where failes >5

$dbh->do("DELETE FROM counts WHERE failes>4");
}
# move procceded messages to old directory

qx{for i in /home/mail_users/failed_emails/cur/*.*; do mv \$i 
/home/mail_users/failed_emails/old 2>/dev/null; done };

#
# Finish
#
#print 'did everything huh..';

$dbh->disconnect();
$folder->close;