diff --git a/fhem/CHANGED b/fhem/CHANGED index e567dd666..42ed27337 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. + - bugfix: 76_MSGMail: Add MSGMail_Attr() - feature: 70_PIONEERAVR: new set hdmiOut <1/2>to switch hdmi outputs - new set networkStandby (on|off) Needed to turn on/off... - new readings hdmiOut, screenLineNumber[First,Last,Total] diff --git a/fhem/FHEM/76_MSGMail.pm b/fhem/FHEM/76_MSGMail.pm index 57aed5e29..430c991ca 100644 --- a/fhem/FHEM/76_MSGMail.pm +++ b/fhem/FHEM/76_MSGMail.pm @@ -4,6 +4,7 @@ # # History: # +# 2015-05-19: Add MSGMail_Attr() # 2015-05-15: Add attribute mailtype as suggested by Roger (forum #37206) # 2015-05-11: Improve error logging to assist problem solving # 2015-05-09: Assimilate mail related code from 75_MSG @@ -45,10 +46,12 @@ sub MSGMail_Initialize($) { my ($hash) = @_; - $hash->{SetFn} = "MSGMail_Set"; - $hash->{DefFn} = "MSGMail_Define"; - $hash->{UndefFn} = "MSGMail_Undef"; - $hash->{AttrList} = "loglevel:0,1,2,3,4,5,6 authfile smtphost smtpport subject mailtype:plain,html from to cc CR:0,1"; + $hash->{SetFn} = "MSGMail_Set"; + $hash->{DefFn} = "MSGMail_Define"; + $hash->{UndefFn} = "MSGMail_Undef"; + $hash->{AttrFn} = "MSGMail_Attr"; + $hash->{AttrList} = + "loglevel:0,1,2,3,4,5,6" . " authfile smtphost smtpport" . " subject mailtype:plain,html from to cc CR:0,1"; my $name = "MSGMail"; @@ -71,8 +74,7 @@ sub MSGMail_Initialize($) $MSGMail_SSL = 1; } } - Log 0, - "$name: SSL is " + Log 0, "$name: SSL is " . ( ($MSGMail_SSL) ? ("available, provided by Net::SMTP" . (($MSGMail_SMTP < 3.00) ? "::SSL" : "")) @@ -128,6 +130,40 @@ sub MSGMail_Undef($$) return undef; } +############################################## +# Attr Function +# +# Check sanity of attribute values; no need to actually set attributes, this is done by FHEM +# return undef if OK, otherwise return error message +# +# authfile smtphost smtpport subject mailtype:plain,html from to cc +############################################## +sub MSGMail_Attr(@) +{ + my ($cmd, $name, $attrName, $attrVal) = @_; + my $hash = $defs{$name}; + + return if ($cmd ne "set"); + + if ($attrName eq "loglevel") # loglevel:0,1,2,3,4,5,6 + { + return if ($attrVal =~ m/^[0-6]$/); + return "Valid values for loglevel are 0,1,2,3,4,5,6"; + } + elsif ($attrName eq "mailtype") # mailtype:plain,html + { + return if ($attrVal =~ m/^(plain|html)$/); + return "Valid values for mailtype are plain,html"; + } + elsif ($attrName eq "CR") # CR:0,1 + { + return if ($attrVal =~ m/^[01]$/); + return "Valid values for mailtype are 0,1"; + } + + return undef; +} + ############################################## # Set Function # all the data are stored in the global array @data @@ -203,12 +239,12 @@ sub MSGMail_Set($@) my $subject = AttrVal($name, "subject", ""); my $authfile = AttrVal($name, "authfile", ""); my $smtphost = AttrVal($name, "smtphost", ""); - my $smtpport = AttrVal($name, "smtpport", "465"); # 465 is the default port - my $cc = AttrVal($name, "cc", ""); # Carbon Copy + my $smtpport = AttrVal($name, "smtpport", "465"); # 465 is the default port + my $cc = AttrVal($name, "cc", ""); # Carbon Copy my $mtype = AttrVal($name, "mailtype", "plain"); my $mailtype = "text/plain"; - $mailtype= "text/$mtype" if ($mtype =~ m/^(plain|html)$/); + $mailtype = "text/$mtype" if ($mtype =~ m/^(plain|html)$/); return "No address specified, use attr $name from " if (!$from);