+ # Re-establish callback
+ eval { $IMAP->idle(\&MonitorMail) };
+
+ # If we return from idle then the server went away for some reason. With Gmail
+ # the server seems to time out around 30-40 minutes. Here we simply reconnect
+ # to the imap server and continue to MonitorMail.
+ $log->dbug("MonitorMail: Connection to $opts{imap} ended. Reconnecting");
+
+ # Destroy current IMAP connection
+ $log->dbug("MonitorMail: Destorying IMAP connection to $opts{imap}");
+
+ undef $IMAP;
+
+ # Re-establish connection
+ Connect2IMAP;
+
+ $log->dbug("MonitorMail: Reconnected to IMAP server $opts{imap}");
+
+ # MonitorMail again - the dreaded goto! Seems the cleanest way to restart
+ # in this instance. I could call MonitorMail() recursively but that would
+ # leave junk on the stack.
+ $log->dbug('MonitorMail: Going back to the top of the loop');