From 625bb522e80765d3d2df173871e2188d90c4c50f Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Tue, 2 Aug 2022 13:21:22 +0000 Subject: [PATCH] 49_SSCAM: allow placeholders #CAM, #DATE, #TIME, #FILE, #CTIME git-svn-id: https://svn.fhem.de/fhem/trunk@26279 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/49_SSCam.pm | 262 +++++++++++++++++++++++++++--------------- 2 files changed, 170 insertions(+), 93 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index d40467480..2580cfa2c 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 49_SSCAM: allow placeholders #CAM, #DATE, #TIME, #FILE, #CTIME - bugfix: 50_Signalbot: update contacts on startup, signal-cli 0.10.9 - feature: 96_Snapcast: group volume now can be set - feature: 49_SSCam: text field long for some attributes, the body text diff --git a/fhem/FHEM/49_SSCam.pm b/fhem/FHEM/49_SSCam.pm index a97f496e3..8f75fdd5f 100644 --- a/fhem/FHEM/49_SSCam.pm +++ b/fhem/FHEM/49_SSCam.pm @@ -185,6 +185,7 @@ BEGIN { # Versions History intern my %vNotesIntern = ( + "9.10.7" => "02.08.2022 allow placeholders #CAM, #DATE, #TIME, #FILE, #CTIME (also for Email) ", "9.10.6" => "18.07.2022 textField-long property set for recChatTxt, recEmailTxt, recTelegramTxt, snapChatTxt, snapEmailTxt, snapTelegramTxt, ". "set 'part1type' to default => text/html instead of text/plain", "9.10.5" => "01.07.2022 fix noQuotesForSID using in streaming devices type mjpeg ", @@ -9783,9 +9784,9 @@ sub _prepSendChat { if($subjt) { $subjt = trim($subjt); - $subjt =~ s/\$CAM/$calias/gx; - $subjt =~ s/\$DATE/$date/gx; - $subjt =~ s/\$TIME/$time/gx; + $subjt =~ s/[\$#]CAM/$calias/gx; + $subjt =~ s/[\$#]DATE/$date/gx; + $subjt =~ s/[\$#]TIME/$time/gx; } my %chatmsg = (); @@ -10072,8 +10073,8 @@ sub __extractForChat { $fname = $tdir."/".$fname; } - $subject =~ s/\$FILE/$fname/gx; - $subject =~ s/\$CTIME/$ct/gx; + $subject =~ s/[\$#]FILE/$fname/gx; + $subject =~ s/[\$#]CTIME/$ct/gx; return ($subject,$fname); } @@ -10104,9 +10105,9 @@ sub _prepSendTelegram { if($subjt) { $subjt = trim($subjt); - $subjt =~ s/\$CAM/$calias/gx; - $subjt =~ s/\$DATE/$date/gx; - $subjt =~ s/\$TIME/$time/gx; + $subjt =~ s/[\$#]CAM/$calias/gx; + $subjt =~ s/[\$#]DATE/$date/gx; + $subjt =~ s/\[\$#]TIME/$time/gx; } my %telemsg = (); @@ -10330,8 +10331,8 @@ sub __extractForTelegram { } } - $subject =~ s/\$FILE/$fname/gx; - $subject =~ s/\$CTIME/$ct/gx; + $subject =~ s/[\$#]FILE/$fname/gx; + $subject =~ s/[\$#]CTIME/$ct/gx; return ($data,$subject,$MediaStream,$fname); } @@ -10663,14 +10664,14 @@ sub _prepSendMail { my $bodyt = (split "=>", $body)[1]; $subjt = trim($subjt); - $subjt =~ s/\$CAM/$calias/gx; - $subjt =~ s/\$DATE/$date/gx; - $subjt =~ s/\$TIME/$time/gx; + $subjt =~ s/[\$#]CAM/$calias/gx; + $subjt =~ s/[\$#]DATE/$date/gx; + $subjt =~ s/[\$#]TIME/$time/gx; $bodyt = trim($bodyt); - $bodyt =~ s/\$CAM/$calias/gx; - $bodyt =~ s/\$DATE/$date/gx; - $bodyt =~ s/\$TIME/$time/gx; + $bodyt =~ s/[\$#]CAM/$calias/gx; + $bodyt =~ s/[\$#]DATE/$date/gx; + $bodyt =~ s/[\$#]TIME/$time/gx; my %smtpmsg = (); $smtpmsg{subject} = "$subjt"; @@ -10843,6 +10844,7 @@ sub __sendEmailblocking { ## } $subject = decode_utf8($subject); + my $mailmsg = MIME::Lite->new( From => $from, To => $to, @@ -10850,15 +10852,10 @@ sub __sendEmailblocking { ## Type => 'multipart/mixed', #'multipart/mixed', # was 'text/plain' ); - ### Add the text message part: - ### (Note that "attach" has same arguments as "new"): $part1txt = decode_utf8($part1txt); - $mailmsg->attach( - Type => $part1type, - Data => $part1txt, - ); - + ### Add image, Das Image liegt bereits als File vor + #################################################### if($image) { $mailmsg->attach( Type => $part2type, @@ -10885,8 +10882,20 @@ sub __sendEmailblocking { ## Filename => $fname, Disposition => 'attachment', ); + + my $params = { + hash => $hash, + name => $name, + txt => $part1txt, + fname => $fname, + ct => $ct + }; + + $part1txt = __extractForEmail ($params); + Log3($name, 4, "$name - Image data sequence [$key] decoded from internal Cache for Email attachment") if($decoded); } + BlockingInformParent("FHEM::SSCam::subaddFromBlocking", [$name, "-", $tac], 0); } else { @@ -10913,8 +10922,20 @@ sub __sendEmailblocking { ## Filename => $fname, Disposition => 'attachment', ); + + my $params = { + hash => $hash, + name => $name, + txt => $part1txt, + fname => $fname, + ct => $ct + }; + + $part1txt = __extractForEmail ($params); + Log3($name, 4, "$name - Image data sequence [$key] decoded from CHI-Cache for Email attachment"); } + BlockingInformParent("FHEM::SSCam::subaddFromBlocking", [$name, "-", $tac], 0); } } @@ -10934,8 +10955,20 @@ sub __sendEmailblocking { ## Filename => $fname, Disposition => 'attachment', ); + + my $params = { + hash => $hash, + name => $name, + txt => $part1txt, + fname => $fname, + ct => $ct + }; + + $part1txt = __extractForEmail ($params); + Log3($name, 4, "$name - Video data sequence [$key] decoded from internal Cache for Email attachment"); } + BlockingInformParent("FHEM::SSCam::subaddFromBlocking", [$name, "-", $tac], 0); } else { @@ -10962,12 +10995,31 @@ sub __sendEmailblocking { ## Filename => $fname, Disposition => 'attachment', ); + + my $params = { + hash => $hash, + name => $name, + txt => $part1txt, + fname => $fname, + ct => $ct + }; + + $part1txt = __extractForEmail ($params); + Log3($name, 4, "$name - Video data sequence [$key] decoded from CHI-Cache for Email attachment"); } + BlockingInformParent("FHEM::SSCam::subaddFromBlocking", [$name, "-", $tac], 0); } } + ### Add the text message part (Note that "attach" has same arguments as "new") + ############################################################################### + $mailmsg->attach( + Type => $part1type, + Data => $part1txt, + ); + $mailmsg->attr('content-type.charset' => 'UTF-8'); ##### SMTP-Connection ##### @@ -11087,6 +11139,22 @@ sub __sendEmailblocking { ## return "$name|''|$ret"; } +#################################################################################################### +# Daten extrahieren für Email Versand +#################################################################################################### +sub __extractForEmail { + my $paref = shift; + my $txt = $paref->{txt} // qq{}; + my $fname = $paref->{fname} // qq{}; + my $ct = $paref->{ct} // qq{}; + + $txt =~ s/[\$#]FILE/$fname/gx; + $txt =~ s/[\$#]CTIME/$ct/gx; + +return $txt; +} + + #################################################################################################### # Auswertungsroutine nichtblockierendes Send EMail #################################################################################################### @@ -13389,12 +13457,12 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
@@ -13410,15 +13478,17 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
  • recEmailTxt subject => <subject text>, body => <message text>
    Activates the Email shipping of recordings after whose creation.
    - The attribute has to be definied in the form as described.
    - You can use the following placeholders in "subject" and "body".

    + The attribute must be defined in the specified form.
    + The following placeholders can be used in the subject or body.


    @@ -13443,12 +13513,12 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
    @@ -13554,12 +13624,12 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
    @@ -13575,15 +13645,17 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
  • snapEmailTxt subject => <subject text>, body => <message text>
    Activates the Email shipping of snapshots after whose creation.
    - The attribute has to be defined in the form as described.
    - You can use the following placeholders in "subject" and "body".

    + The attribute must be defined in the specified form.
    + The following placeholders can be used in the subject or body.


    @@ -13609,12 +13681,12 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
    @@ -15417,12 +15489,12 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
    @@ -15439,14 +15511,16 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
  • recEmailTxt subject => <Betreff-Text>, body => <Mitteilung-Text>
    Aktiviert den Emailversand von Aufnahmen nach deren Erstellung.
    Das Attribut muß in der angegebenen Form definiert werden.
    - Es können die folgenden Platzhalter im subject und body verwendet werden.

    + Es können die folgenden Platzhalter im subject bzw. body verwendet werden.


    @@ -15471,12 +15545,12 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
    @@ -15583,12 +15657,12 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR
    @@ -15606,14 +15680,16 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR Aktiviert den Emailversand von Schnappschüssen nach deren Erstellung. Wurden mehrere Schnappschüsse ausgelöst, werden sie gemeinsam in einer Mail versendet.
    Das Attribut muß in der angegebenen Form definiert werden.
    - Es können die folgenden Platzhalter im subject und body verwendet werden.

    + Es können die folgenden Platzhalter im subject bzw. body verwendet werden.


    @@ -15639,12 +15715,12 @@ attr <name> genericStrmHtmlTag <img $HTMLATTR