- 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 $envelope = $IMAP->fetch($_, '(envelope)');
- my $from = $envelope->{$_}{envelope}{From};
- my $subject = $envelope->{$_}{envelope}{Subject};
- $subject //= 'Unknown subject';
-
- # Extract the name only when the email is of the format "name <email>"
- if ($from =~ /^"?(.*?)"?\s*\<(\S*)>/) {
- $from = $1 if $1 ne '';
- } # if
-
- if ($subject =~ /=?\S+?(Q|B)\?(.+)\?=/) {
- $subject = decode_base64($2);
+ 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{$_};