<head>
        <title></title>
</head>
<body>
<div class="userStyles" style=" font-family: Arial; font-size: 12pt; color: #000000;">Joel, Thank you very much for the quick reply. I'll look into putting it in an array and see if that helps.<br>
<br>
Thanks again!
<footer class="signatureContainer" style="display:inline;"> </footer>

<footer class="replyforwardcontainer"><br>
<br>
<span>On Wed, 21 Jun 2023 09:27:44 -0500, Joel Berger <joel.a.berger@gmail.com> wrote:</span><br>
 
<div dir="ltr">
<div>I can't fully debug the result you're seeing without some sample data etc (nor do I really have the time to do so) but what I will say is that you probably want to store the results of parsing the headers in a variable and not parse them several times. This could be just efficiency, but it also might matter if the internals of the parser actually consume the data from some buffer, something that is pretty typical of a parser. See if storing those results into a temporary variable solves some of your issues.</div>

<div> </div>

<div>Joel</div>
</div>
 

<div class="gmail_quote">
<div class="gmail_attr" dir="ltr">On Wed, Jun 21, 2023 at 9:22 AM Richard Reina <<a href="mailto:richard@rushlogistics.com">richard@rushlogistics.com</a>> wrote:</div>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">With the code below I use Perl to search through old email with a given title before or after a certain date and delete them. I invoke it like this: perl -e 'use RIMAPtools; my ($IMLU_obj) = RIMAPtools->new(since => "17-Nov-2020", username => "richard",  domain => "<a href="http://rushlogistics.com" rel="noreferrer" target="_blank">rushlogistics.com</a>", sub_stg => "NETWORK STATUS REPORT"); $IMLU_obj->look_up();'<br>
<br>
Periodically the program crashes with error message: Can't use an undefined value as a HASH reference at /etc/perl/RIMAPtools.pm line 120.<br>
<br>
  LINE 113:     if (! defined $imap->parse_headers($msg,"Subject")->{"Subject"}->[0]) {<br>
  LINE 114:<br>
  LINE 115:           print "msg SUBJECT was not defined. Skipping to next email.\n";<br>
  LINE 116:           next;<br>
  LINE 117:<br>
  LINE 118:       } else {<br>
  LINE 119:      <br>
  LINE 120:            $msg_subject = $imap->parse_headers($msg,"Subject")->{"Subject"}->[0];<br>
  LINE 121:<br>
  LINE 122:       }<br>
<br>
<br>
As you can see Perl tells me $imap->parse_headers($msg,"Subject")->{"Subject"}->[0] is defined on line 113 and then undefined on line 120. Any ideas?<br>
<br>
Full subroutine below.<br>
<br>
Thanks,<br>
<br>
Richard<br>
<br>
##################<br>
sub look_up {<br>
##################<br>
<br>
     my ( $self, %args ) = @_;<br>
    <br>
     my ($svr, $pw) = get_cred($self->{_username}, $self->{_domain});<br>
<br>
     print "Contacting: $svr vial Mail::IMAPClient.\n";<br>
<br>
     my $userid =  $self->{_username} . '@' . $self->{_domain};<br>
     <br>
     my $imap=Mail::IMAPClient->new(<br>
<br>
     Server => $svr,<br>
     Port => 143,<br>
     User => $userid,<br>
     Password => $pw,<br>
     Peek => 1,<br>
     <br>
    );<br>
     <br>
    unless($imap) { <br>
    <br>
    die "Couldn't log in to server: $svr $@\n";<br>
<br>
    }<br>
    <br>
    # Open the inbox<br>
    $imap->select('INBOX');<br>
    my @mails; <br>
    <br>
    if ($self->{_since}) {<br>
<br>
    print "Will look at messages before: $self->{_since}\n";<br>
    @mails = $imap->since($self->{_since}) or die "Could not find any messages since $self->{_since}: $@\n";<br>
<br>
    } elsif ($self->{_before}) {<br>
<br>
    print "Will look at messages before: $self->{_before}\n"; <br>
    @mails = $imap->before($self->{_before}) or die "Could not find any messages before $self->{_before}: $@\n";<br>
    <br>
    }<br>
<br>
     if ($self->{_sub_stg}) {<br>
<br>
     print "Will search for mails with subject containing: $self->{_sub_stg}\n";<br>
<br>
    }<br>
     <br>
    foreach my $msg (@mails) {<br>
<br>
    my $msg_subject;<br>
<br>
    if (! defined $msg) {<br>
<br>
        print "msg was not defined. Skipping to next email.\n";<br>
        next;<br>
    }<br>
<br>
    if (! defined $imap->parse_headers($msg,"Subject")->{"Subject"}->[0]) {<br>
<br>
        print "msg SUBJECT was not defined. Skipping to next email.\n";<br>
        next;<br>
<br>
    } else {<br>
        <br>
        $msg_subject = $imap->parse_headers($msg,"Subject")->{"Subject"}->[0];<br>
<br>
    }<br>
    <br>
    if ($self->{_sub_stg}) {<br>
        <br>
        print "Will look for string: " . $self->{_sub_stg} . " IN SUBJECT: " . $msg_subject . "\n";<br>
        <br>
        if ($msg_subject =~ /$self->{_sub_stg}/) {<br>
        <br>
        print "MATCH: " . $msg_subject . " DATE: " . $imap->get_header($msg,"Date") . "\n";<br>
        $imap->delete_message($msg) or die "Could not delete_message: $@\n";;<br>
                    <br>
    }<br>
        <br>
    } # eo foreach<br>
    <br>
#######################    <br>
} #EOS look_up<br>
#######################<br>
_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org" target="_blank">Chicago-talk@pm.org</a><br>
<a href="https://mail.pm.org/mailman/listinfo/chicago-talk" rel="noreferrer" target="_blank">https://mail.pm.org/mailman/listinfo/chicago-talk</a></blockquote>
</div>
_______________________________________________<br>
Chicago-talk mailing list<br>
Chicago-talk@pm.org<br>
https://mail.pm.org/mailman/listinfo/chicago-talk</footer>
</div>


</body>