- my $msg = "Now monitoring email for $opts{username}\@$opts{imap}";
-
- $log->msg($msg);
-
- my $cmd = "/usr/local/bin/gt \"$msg\"";
-
- my ($status, @output) = Execute $cmd;
-
- while () {
- # First close and reselect the INBOX to get its current status
- debugit "Reconnecting to INBOX";
- $IMAP->close;
- $IMAP->select('INBOX')
- or $log->err("Unable to select INBOX - ". $IMAP->errstr(), 1);
-
- # Go through all of the unseen messages and add them to %unseen if they were
- # not there already from a prior run and read
- my %newUnseen = unseenMsgs;
-
- # Now clean out any messages in %unseen that were not in the %newUnseen and
- # marked as previously read
- for (keys %unseen) {
- if (defined $newUnseen{$_}) {
- if ($unseen{$_}) {
- delete $newUnseen{$_};
- } # if
- } else {
- delete $unseen{$_}
- } # if
- } # for
-
- debugit "Processing newUnseen";
- for (keys %newUnseen) {
- next if $unseen{$_};
-
- my @msglines = $IMAP->top($_);
-
- # What happens at INBOX 0? Does top return empty array?
- $log->err("Unable to get top for $_ - " . $IMAP->errstr(), 1) unless @msglines;
-
- my $email = Email::Simple->new(join '', @msglines);
-
- my $from = $email->header('From');
-
- # Extract the name only when the email is of the format "name <email>"
- if ($from =~ /^"?(.*?)"?\s*\<(\S*)>/) {
- $from = $1 if $1 ne '';
+ MONITORMAIL:
+ $log->dbug("Top of MonitorMail loop");
+
+ # First close and reselect the INBOX to get its current status
+ $IMAP->close;
+ $IMAP->select('INBOX')
+ or $log->err("Unable to select INBOX - ". $IMAP->errstr(), 1);
+
+ $log->dbug("Closed and reselected INBOX");
+ # Go through all of the unseen messages and add them to %unseen if they were
+ # not there already from a prior run and read
+ my %newUnseen = unseenMsgs;
+
+ # Now clean out any messages in %unseen that were not in the %newUnseen and
+ # marked as previously read
+ $log->dbug("Cleaning out unseen");
+ for (keys %unseen) {
+ if (defined $newUnseen{$_}) {
+ if ($unseen{$_}) {
+ delete $newUnseen{$_};