package Ernad::Notify; use strict; use warnings; use Carp qw(cluck longmess shortmess croak confess); use File::Path; use Data::Dumper; use Ernad::Common; use Ernad::Email; use Krichel::File; binmode(STDOUT,":utf8:"); our $e; sub notify { $e=shift; if(not defined($e) or not ref($e) eq 'Ernad::Erimp') { confess "I need an erimp here"; } my $rif=shift; if(not defined($rif) or not -f $rif) { confess "I need an rif here"; } #my $repcode=$e->find_repcode_from_file($rif) my $repcode=$e->{'f'}->repcode($rif) or confess "Where is the repcode in $rif?"; my $issuedate=$e->{'f'}->issuedate($rif) or confess "Where is the issuedate in $rif?"; my $doc=&Krichel::File::load($rif); my $notify_dir=$e->{'report'}->{$repcode}->{'dir'}->{'notify'} or confess "I need a notify_dir here."; my $save_string=$notify_dir.'/'.$issuedate; if(not -d $notify_dir) { File::Path::mkpath($notify_dir); } my $glob="$save_string.*"; my @files=glob($glob); my $count_files=$#files+1; ## don't send this again if($count_files == 3) { $e->echo(__LINE__,"I have three mail files, I will not mail again."); return ''; } elsif($count_files != 0) { #confess "I see $count_files!=3 files for $repcode on $issuedate in $notify_dir."; $e->echo(__LINE__,"I see $count_files!=3 files for $repcode on $issuedate in $notify_dir."); return ''; } my $email_file=&Ernad::Email::prepare_email($doc,'notify',$save_string); &Ernad::Email::send_email($email_file); } 1;