From 578673d4ea406c119c7589ac8a591dadd15f4fa8 Mon Sep 17 00:00:00 2001 From: stan Date: Sun, 13 Apr 2003 22:58:31 +0000 Subject: [PATCH] Corrections to videos and attachments. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@477 e3e1d417-86f3-4887-817a-d78f3d33393f --- scripts/zmfilter.pl.z | 67 +++++++++++++++++++------------------------ scripts/zmvideo.pl.z | 1 + 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/scripts/zmfilter.pl.z b/scripts/zmfilter.pl.z index 03e18cf8b..9f46aaaf5 100755 --- a/scripts/zmfilter.pl.z +++ b/scripts/zmfilter.pl.z @@ -475,8 +475,9 @@ sub sendEmail print( "Creating notification email\n" ); - my $subject = substituteTags( $email_subject, $filter, \$event ); - my $body = substituteTags( $email_body, $filter, \$event ); + my $subject = substituteTags( $email_subject, $filter, $event ); + my @attachments; + my $body = substituteTags( $email_body, $filter, $event, @attachments ); print( "Sending notification email '$subject'\n" ); print( "$body\n" ) if ( VERBOSE ); @@ -490,17 +491,14 @@ sub sendEmail Data=>$body ); - if ( $event->{attachments} ) + foreach my $attachment ( @attachments ) { - foreach my $attachment ( @{$event->{attachments}} ) - { - print( "Attaching '$attachment->{path}\n" ); - $mail->attach( - Path=>$attachment->{path}, - Type=>$attachment->{type}, - Encoding=>"base64" - ); - } + print( "Attaching '$attachment->{path}\n" ); + $mail->attach( + Path=>$attachment->{path}, + Type=>$attachment->{type}, + Encoding=>"base64" + ); } $mail->smtpsend(); @@ -533,8 +531,9 @@ sub sendMessage print( "Creating notification message\n" ); - my $subject = substituteTags( $message_subject, $filter, \$event ); - my $body = substituteTags( $message_body, $filter, \$event ); + my $subject = substituteTags( $message_subject, $filter, $event ); + my @attachments; + my $body = substituteTags( $message_body, $filter, $event, @$attachments ); print( "Sending notification message '$subject'\n" ); print( "$body\n" ) if ( VERBOSE ); @@ -548,17 +547,14 @@ sub sendMessage Data=>$body ); - if ( $event->{attachments} ) + foreach my $attachment ( @attachments ) { - foreach my $attachment ( @{$event->{attachments}} ) - { - print( "Attaching '$attachment->{path}\n" ); - $mail->attach( - Path=>$attachment->{path}, - Type=>$attachment->{type}, - Encoding=>"base64" - ); - } + print( "Attaching '$attachment->{path}\n" ); + $mail->attach( + Path=>$attachment->{path}, + Type=>$attachment->{type}, + Encoding=>"base64" + ); } $mail->smtpsend(); @@ -577,8 +573,8 @@ sub substituteTags { my $text = shift; my $filter = shift; - my $event_ref = shift; - my $event = $$event_ref; + my $event = shift; + my $attachments_ref = shift; # First we'd better check what we need to get # We have a filter and an event, do we need any more @@ -651,28 +647,23 @@ sub substituteTags $text =~ s/%ESM%/$event->{MaxScore}/g; $text =~ s/%EPI1%/$url?view=image&mid=$filter->{MonitorId}&eid=$event->{Id}&fid=$first_alarm_frame->{FrameId}/g; $text =~ s/%EPIM%/$url?view=image&mid=$filter->{MonitorId}&eid=$event->{Id}&fid=$max_alarm_frame->{FrameId}/g; - if ( $text =~ s/%EI1%/First alarm frame attached/g ) + if ( $attachments_ref && $text =~ s/%EI1%/First alarm frame attached/g ) { - my $attachments = $event->{attachments}; - $attachments = $event->{attachments} = [] if ( !$attachments ); - push( @$attachments, { type=>"image/jpeg", path=>sprintf( "%s/%d/capture-%03d.jpg", $filter->{MonitorName}, $event->{Id}, $first_alarm_frame->{FrameId} ) } ); + push( @$attachments_ref, { type=>"image/jpeg", path=>sprintf( "%s/%d/capture-%03d.jpg", $filter->{MonitorName}, $event->{Id}, $first_alarm_frame->{FrameId} ) } ); } - if ( $text =~ s/%EIM%/Max alarm frame attached/g ) + if ( $attachments_ref && $text =~ s/%EIM%/Max alarm frame attached/g ) { - my $attachments = $event->{attachments}; - $attachments = $event->{attachments} = [] if ( !$attachments ); - push( @$attachments, { type=>"image/jpeg", path=>sprintf( "%s/%d/capture-%03d.jpg", $filter->{MonitorName}, $event->{Id}, $max_alarm_frame->{FrameId} ) } ); + push( @$attachments_ref, { type=>"image/jpeg", path=>sprintf( "%s/%d/capture-%03d.jpg", $filter->{MonitorName}, $event->{Id}, $max_alarm_frame->{FrameId} ) } ); } - if ( $text =~ s/%EV%/Event video attached/g ) + if ( $attachments_ref && $text =~ s/%EV%/Event video attached/g ) { - my $attachments = $event->{attachments}; - $attachments = $event->{attachments} = [] if ( !$attachments ); my $command = ZM_PATH_BIN."/zmvideo.pl -e $event->{Id}"; my $output = qx($command); my $status = $? >> 8; if ( $status == 0 ) { - push( @$attachments, { type=>"video/mpeg", path=>sprintf( "%s/%d/%s", $filter->{MonitorName}, $event->{Id}, $output ) } ); + chomp $output; + push( @$attachments_ref, { type=>"video/mpeg", path=>sprintf( "%s/%d/%s", $filter->{MonitorName}, $event->{Id}, $output ) } ); } } $text =~ s/%FN%/$filter->{Name}/g; diff --git a/scripts/zmvideo.pl.z b/scripts/zmvideo.pl.z index f158381d3..d751d7d0f 100644 --- a/scripts/zmvideo.pl.z +++ b/scripts/zmvideo.pl.z @@ -154,6 +154,7 @@ if ( !-s $video_file ) { die( "Error: $status" ); } + print( LOG "Finished $video_file\n" ); } else {