X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=bin%2FannounceEmail.pl;h=cb6667be3d343c51a59b1f88f39b4dd1b5845f15;hb=10b78beac53843192f7da8a6dbaa2d5e0572b307;hp=df5aa91fb9b5f3d684afafb359dafd91c4054f19;hpb=22b63be21c65109a7944dbb2cd0849d3db091d95;p=clearscm.git diff --git a/bin/announceEmail.pl b/bin/announceEmail.pl index df5aa91..cb6667b 100755 --- a/bin/announceEmail.pl +++ b/bin/announceEmail.pl @@ -75,9 +75,10 @@ use warnings; use FindBin; use Getopt::Long; -use Pod::Usage; use Mail::IMAPTalk; use MIME::Base64; +use Pod::Usage; +use Proc::ProcessTable; use lib "$FindBin::Bin/../lib"; @@ -89,6 +90,16 @@ use Utils; local $0 = "$FindBin::Script " . join ' ', @ARGV; +my $processes = Proc::ProcessTable->new; + +for my $process (@{$processes->table}) { + if ($process->cmndline eq $0 and $process->pid != $$) { + verbose "$FindBin::Script already running"; + + exit 0; + } # if +} # for + my $defaultIMAPServer = 'defaria.com'; my $IMAP; my %unseen; @@ -252,9 +263,7 @@ sub MonitorMail() { my $greeting = $greetings[int rand $#greetings]; my $msg = "$greeting from $from... $subject"; - $msg =~ s/\"/\\"/g; - - my $hour = (localtime)[2]; + my $hour = (localtime)[2]; # Only announce if after 6 Am. Note this will announce up until # midnight but that's ok. I want midnight to 6 Am as silent time. @@ -262,9 +271,9 @@ sub MonitorMail() { if ($hour >= 7) { $log->msg($logmsg); $log->dbug("Calling speak"); - speak $msg; + speak $msg, $log; } else { - $log->msg("$logmsg [silent]"); + $log->msg("$logmsg [silent nighttime]"); } # if $unseen{$_} = 1; @@ -274,7 +283,7 @@ sub MonitorMail() { my $startTime = time; # Re-establish callback - $log->msg("Calling IMAP->idle"); + $log->dbug("Calling IMAP->idle"); eval { $IMAP->idle(\&MonitorMail, $opts{timeout}) }; @@ -366,7 +375,7 @@ if ($opts{username} =~ /(.*)\@/) { my $msg = "Now monitoring email for $opts{user}\@$opts{name}"; -speak $msg if $opts{announce}; +speak $msg, $log if $opts{announce}; $log->msg($msg);