--- /dev/null
+#!/bin/bash
+case $1 in
+ post)
+ # If we send the USR2 signal before the network comes back up then
+ # announceEmail.pl will die trying to re-establish its connection to the
+ # IMAP server. So instead we use this cheap method of sleeping for a minute
+ # as the network should be back by then. A better method would be to poll
+ # looking for the network to come back up but that's tricker to implement.
+ sleep 60
+ killall -USR2 announceEmail.pl
+ ;;
+esac
-h|elp Detailed help
-v|erbose Verbose mode (Default: -verbose)
-de|bug Turn on debugging (Default: Off)
-
+
-user|name User name to log in with (Default: $USER)
-p|assword Password to use (Default: prompted)
-i|map IMAP server to talk to (Default: defaria.com)
-uses|sl Whether or not to use SSL to connect (Default: False)
-useb|locking Whether to block on socket (Default: False)
+ Signals:
+ $SIG{USR1}: Toggles debug option
+ $SIG{USR2}: Reestablishes connection to IMAP server
+
=head1 DESCRIPTION
This script will connect to an IMAP server, login and then monitor the user's
'I was looking in your inbox and found a message',
'Not sure you want to hear this message',
'Good news',
+ "What's this? A new message",
);
my %opts = (
return;
} # interrupted
+sub Connect2IMAP;
+
+sub restart {
+ $log->dbug("Re-establishing connection to $opts{imap} as $opts{username}");
+ Connect2IMAP;
+
+ goto MONITORMAIL;
+} # restart
+
$SIG{USR1} = \&interrupted;
+$SIG{USR2} = \&restart;
sub unseenMsgs() {
$IMAP->select('inbox') or
sub Connect2IMAP() {
$log->dbug("Connecting to $opts{imap} as $opts{username}");
+ # Destroy any old connections
+ undef $IMAP;
+
$IMAP = Mail::IMAPTalk->new(
Server => $opts{imap},
Username => $opts{username},
# 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 - lasted "
- . howlong $startTime);
-
- # Destroy current IMAP connection
- $log->dbug("MonitorMail: Destroying IMAP connection to $opts{imap}");
+ restart;
- 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');
-
- goto MONITORMAIL;
-
- return; # To make perlcritic happy
+ return;
} # MonitorMail
END {
# Call old signal handler (if any)
&$oldHandler if $oldHandler;
-
+
return;
} # DESTROY
Sends a command to the cleartool coprocess. If not running a cleartool coprocess
is started and managed. The coprocess is implemented as a coprocess using IPC
for communication that will exist until the object is destroyed. Stdin and
-stdout/stderr are therefore pipes and can be fed. The execute method feds the
+stdout/stderr are therefore pipes and can be fed. The execute method feeds the
input pipe and returns status and output from the output pipe.
Using execute can speed up execution of repeative cleartool invocations
# Simple check to see if we can execute cleartool
@output = `$cleartool -ver 2>&1`;
@output = ();
-
+
return (-1, 'Clearcase not installed')
unless $? == 0;
-
+
$clearpid = open3 ($clearin, $clearout, $clearout, $cleartool, "-status");
return (-1, ('Clearcase not installed')) unless $clearpid;
$self->{lastcmd} = 'cleartool ' . $cmd;
$self->{status} = $status;
$self->{output} = join "\n", @output;
-
+
return ($status, @output);
} # execute