From d2fb365fa9e53c3a20d8ccd584d7b44231619be5 Mon Sep 17 00:00:00 2001
From: Isaac Connor /g;
- } else {
- Warning("Path to first image does not exist at $path for image $first_alarm_frame");
- $text =~ s/%EI1%/No image found for EI1/g;
+ if ($attachments_ref) {
+ if ($text =~ /%EI1%/g) {
+ my $path = generateImage($Event, $first_alarm_frame);
+ if (-e $path) {
+ my $filename = fileparse($path);
+ my $attachment = { type=>'image/jpeg', path=>$path, content_id=>uri_encode($filename) };
+ push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
+ $text =~ s/%EI1%/
/g;
+ } else {
+ Warning("Path to first image does not exist at $path for image $first_alarm_frame");
+ $text =~ s/%EI1%/No image found for EI1/g;
+ }
+ }
+
+ if ($text =~ /%EIM%/g) {
+ my $path = generateImage($Event, $max_alarm_frame);
+ if (-e $path) {
+ my $filename = fileparse($path);
+ my $attachment = { type=>'image/jpeg', path=>$path, content_id=>uri_encode($filename) };
+ push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
+ $text =~ s/%EIM%/
/g;
+ } else {
+ Warning("No image for EIM at $path");
+ $text =~ s/%EIM%/No image found for EIM/g;
+ }
+ }
+
+ if ($text =~ /%EI1A%/g) {
+ my $path = generateImage($Event, $first_alarm_frame, 'analyse');
+ if (-e $path) {
+ my $filename = fileparse($path);
+ my $attachment = { type=>'image/jpeg', path=>$path, content_id=>uri_encode($filename) };
+ push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
+ $text =~ s/%EI1A%/
/g;
+ } else {
+ Warning("No image for EI1A at $path");
+ $text =~ s/%EI1A%/No image found for EI1A/g;
+ }
+ }
+
+ if ( $text =~ /%EIMA%/g ) {
+ # Don't attach the same image twice
+ my $path = generateImage($Event, $max_alarm_frame, 'analyse');
+ if (-e $path) {
+ my $filename = fileparse($path);
+ my $attachment = { type=>'image/jpeg', path=>$path, content_id=>uri_encode($filename) };
+ push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
+ $text =~ s/%EIMA%/
/g;
+ } else {
+ Warning("No image for EIMA at $path");
+ $text =~ s/%EIMA%/No image found for EIMA/g;
+ }
+ }
+
+ if ($text =~ /%EIMOD%/g ) {
+ my $path = $Event->Path().'/objdetect.jpg';
+ if (-e $path) {
+ my $filename = fileparse($path);
+ my $attachment = { type=>'image/jpeg', path=>$path, content_id=>uri_encode($filename) };
+ push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
+ $text =~ s/%EIMOD%/
/g;
+ } else {
+ Warning('No image for MOD at '.$path);
+ $text =~ s/%EIMOD%/No image found for EIMOD/g;
+ }
+ }
+
+ if ( $text =~ s/%EIMODG%//g ) {
+ my $path = $Event->Path().'/objdetect.gif';
+ if ( -e $path ) {
+ my $filename = fileparse($path);
+ my $attachment = { type=>'image/gif', path=>$path, content_id=>uri_encode($filename) };
+ push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
+ $text =~ s/%EIMODG%/
/g;
+ } else {
+ Debug(1, 'No image for MODG at '.$path);
+ $text =~ s/%EIMODG%/No image found for EIMODG/g;
+ }
+ }
+
+ } # end if attachments_ref
+ } # end if $first_alarm_frame
+
+ if ( $attachments_ref ) {
+ if ( $text =~ s/%EV%//g ) {
+ if ( $$Event{DefaultVideo} ) {
+ push @$attachments_ref, { type=>'video/mp4', path=>join('/', $Event->Path(), $Event->DefaultVideo()) };
+ } elsif ( $Config{ZM_OPT_FFMPEG} ) {
+ my ( $format, $path ) = generateVideo($filter, $Event);
+ if ( !$format ) {
+ return undef;
+ }
+ push @$attachments_ref, { type=>"video/$format", path=>$path };
}
}
-
- if ($text =~ /%EIM%/g) {
- my $path = generateImage($Event, $max_alarm_frame);
- if (-e $path) {
- my $filename = fileparse($path);
- my $attachment = { type=>'image/jpeg', path=>$path, content_id=>uri_encode($filename) };
- push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
- $text =~ s/%EIM%/
/g;
- } else {
- Warning("No image for EIM at $path");
- $text =~ s/%EIM%/No image found for EIM/g;
- }
- }
-
- if ($text =~ /%EI1A%/g) {
- my $path = generateImage($Event, $first_alarm_frame, 'analyse');
- if (-e $path) {
- my $filename = fileparse($path);
- my $attachment = { type=>'image/jpeg', path=>$path, content_id=>uri_encode($filename) };
- push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
- $text =~ s/%EI1A%/
/g;
- } else {
- Warning("No image for EI1A at $path");
- $text =~ s/%EI1A%/No image found for EI1A/g;
- }
- }
-
- if ( $text =~ /%EIMA%/g ) {
- # Don't attach the same image twice
- my $path = generateImage($Event, $max_alarm_frame, 'analyse');
- if (-e $path) {
- my $filename = fileparse($path);
- my $attachment = { type=>'image/jpeg', path=>$path, content_id=>uri_encode($filename) };
- push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
- $text =~ s/%EIMA%/
/g;
- } else {
- Warning("No image for EIMA at $path");
- $text =~ s/%EIMA%/No image found for EIMA/g;
- }
- }
-
- if ($text =~ /%EIMOD%/g ) {
- my $path = $Event->Path().'/objdetect.jpg';
- if (-e $path) {
- my $filename = fileparse($path);
- my $attachment = { type=>'image/jpeg', path=>$path, content_id=>uri_encode($filename) };
- push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
- $text =~ s/%EIMOD%/
/g;
- } else {
- Warning('No image for MOD at '.$path);
- $text =~ s/%EIMOD%/No image found for EIMOD/g;
- }
- }
-
- if ( $text =~ s/%EIMODG%//g ) {
- my $path = $Event->Path().'/objdetect.gif';
- if ( -e $path ) {
- my $filename = fileparse($path);
- my $attachment = { type=>'image/gif', path=>$path, content_id=>uri_encode($filename) };
- push @$attachments_ref, $attachment if !is_in_attachments($path, $attachments_ref);
- $text =~ s/%EIMODG%/
/g;
- } else {
- Debug(1, 'No image for MODG at '.$path);
- $text =~ s/%EIMODG%/No image found for EIMODG/g;
- }
- }
-
- } # end if attachments_ref
- } # end if $first_alarm_frame
-
- if ( $attachments_ref ) {
- if ( $text =~ s/%EV%//g ) {
- if ( $$Event{DefaultVideo} ) {
- push @$attachments_ref, { type=>'video/mp4', path=>join('/', $Event->Path(), $Event->DefaultVideo()) };
- } elsif ( $Config{ZM_OPT_FFMPEG} ) {
- my ( $format, $path ) = generateVideo($filter, $Event);
+ if ( $text =~ s/%EVM%//g ) {
+ my ( $format, $path ) = generateVideo($filter, $Event, 1);
if ( !$format ) {
return undef;
}
push @$attachments_ref, { type=>"video/$format", path=>$path };
}
}
- if ( $text =~ s/%EVM%//g ) {
- my ( $format, $path ) = generateVideo($filter, $Event, 1);
- if ( !$format ) {
- return undef;
- }
- push @$attachments_ref, { type=>"video/$format", path=>$path };
- }
- }
+ } # end if Event
$text =~ s/%FN%/$filter->{Name}/g;
( my $filter_name = $filter->{Name} ) =~ s/ /+/g;
- $text =~ s/%FP%/$url?view=filter&mid=$Event->{MonitorId}&filter_name=$filter_name/g;
+ $text =~ s/%FP%/$url?view=filter&filter_name=$filter_name/g;
return $text;
} # end subsitituteTags
+sub sendSummaryEmail {
+ my $filter = shift;
+ my @events = map { new ZoneMinder::Event($$_{Id}, $_) } @_;
+
+ if (!$Config{ZM_FROM_EMAIL}) {
+ Error('No from email address defined, not sending email');
+ return 0;
+ }
+ if (!$$filter{EmailTo}) {
+ Error('No email address defined, not sending email');
+ return 0;
+ }
+ my $subject = substituteTags($$filter{EmailSubject}, $filter);
+ print "Got $subject";
+ return 0 if !$subject;
+
+ my ($body_head, $summary_part, $body_tail) = split(/%SUMMARY%/m, $$filter{EmailBody});
+ print "Head: $body_head\n";
+ print "Summary: $summary_part\n";
+ print "Tail: $body_tail\n";
+
+ if (!$summary_part) {
+ Error('Failed finding summary part of email body');
+ return 0;
+ }
+ my @attachments;
+ my $body = $body_head;
+ foreach my $event (@events) {
+ $body .= substituteTags($summary_part, $filter, $event, \@attachments);
+ }
+ return 0 if !$body;
+ $body .= $body_tail;
+ Debug("Sending notification email '$subject'");
+ if (sendTheEmail($filter, $subject, $body, @attachments)) {
+ foreach my $event (@events) {
+ $event->save({Emailed=>1});
+ }
+ return 1;
+ }
+ return 0;
+}
+
sub sendEmail {
my $filter = shift;
- my $Event = shift;
+ my $event = shift;
if (!$Config{ZM_FROM_EMAIL}) {
Error('No from email address defined, not sending email');
@@ -855,15 +906,22 @@ sub sendEmail {
return 0;
}
- Debug('Creating notification email');
-
- my $subject = substituteTags($$filter{EmailSubject}, $filter, $Event);
+ my $subject = substituteTags($$filter{EmailSubject}, $filter, $event);
return 0 if !$subject;
my @attachments;
- my $body = substituteTags($$filter{EmailBody}, $filter, $Event, \@attachments);
+ my $body = substituteTags($$filter{EmailBody}, $filter, $event, \@attachments);
return 0 if !$body;
Debug("Sending notification email '$subject'");
+ if (sendTheEmail($filter, $subject, $body, @attachments)) {
+ $event->save({Emailed=>1});
+ return 1;
+ }
+ return 0;
+}
+
+sub sendTheEmail {
+ my ($filter, $subject, $body, @attachments) = @_;
eval {
if ($Config{ZM_NEW_MAIL_MODULES}) {
@@ -1012,11 +1070,6 @@ sub sendEmail {
} else {
Info("Notification email sent to $$filter{EmailTo}");
}
- my $sql = 'UPDATE `Events` SET `Emailed` = 1 WHERE `Id` = ?';
- my $sth = $dbh->prepare_cached($sql)
- or Fatal("Unable to prepare '$sql': ".$dbh->errstr());
- my $res = $sth->execute($Event->{Id})
- or Fatal("Unable to execute '$sql': ".$dbh->errstr());
return 1;
} # end sub sendEmail
diff --git a/version b/version
index 2e4d3755a..2381793ba 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-1.37.39
+1.37.40
diff --git a/web/includes/Filter.php b/web/includes/Filter.php
index ac21e69fe..c96efeb3a 100644
--- a/web/includes/Filter.php
+++ b/web/includes/Filter.php
@@ -23,6 +23,7 @@ class Filter extends ZM_Object {
'EmailTo' => '',
'EmailSubject' => '',
'EmailBody' => '',
+ 'EmailFormat' => 'Individual',
'AutoDelete' => 0,
'AutoArchive' => 0,
'AutoUnarchive' => 0,
diff --git a/web/skins/classic/views/filter.php b/web/skins/classic/views/filter.php
index 2381525a7..93e3c5d05 100644
--- a/web/skins/classic/views/filter.php
+++ b/web/skins/classic/views/filter.php
@@ -335,6 +335,14 @@ if ( ZM_OPT_EMAIL ) {
+ +translate('Individual'), 'Summary'=>translate('Summary')], + $filter->EmailFormat()); ?> +
+