diff --git a/html/js/noalyss_script.js b/html/js/noalyss_script.js index 15d3ff4f9..01375da59 100644 --- a/html/js/noalyss_script.js +++ b/html/js/noalyss_script.js @@ -4946,7 +4946,15 @@ Noalyss.prototype.save_config_smtp = function () reconnect(); return; } - let json = req.evalJSON(); + let json = req.responseJSON; + try { + let json=req.responseJSON; + if (json['status']=='NOK') { + smoke.alert(json['error']); + } + }catch (e) { + console.error(e) + } } @@ -4963,9 +4971,11 @@ Noalyss.prototype.parameter_display_smtp = function () if ($F("smtp_type") == 'smtp') { $("smtp_config_div").style.display = "grid"; $('btn_save1').hide(); + $('info_snd').hide(); } else { $("smtp_config_div").hide(); $('btn_save1').show(); + $('info_snd').show(); } }; diff --git a/include/ajax/ajax_email_setting.php b/include/ajax/ajax_email_setting.php index 0b41e20cb..58b63bfcd 100644 --- a/include/ajax/ajax_email_setting.php +++ b/include/ajax/ajax_email_setting.php @@ -75,10 +75,11 @@ if ( $op2 == "save_config_smtp") ); $mail_parameter->from_post(); $mail_parameter->save(); - echo 'OK'; + echo json_response(["status"=>"OK"]) ; } catch (Exception $exc) { \record_log($exc); - echo 'NOK'; + echo json_response(["status"=>"NOK","error"=>$exc->getMessage()]) ; + } return; } diff --git a/include/lib/mail_parameter.class.php b/include/lib/mail_parameter.class.php index fc8339cbd..0b40e197f 100644 --- a/include/lib/mail_parameter.class.php +++ b/include/lib/mail_parameter.class.php @@ -137,6 +137,31 @@ class Mail_Parameter */ function save() { + if ( $this->smtp_replyto!="" && filter_var($this->smtp_replyto, FILTER_VALIDATE_EMAIL) == false) + { + throw new \Exception (_("adresse réponse invalide"),140); ; + } + if ( $this->smtp_from!="" && filter_var($this->smtp_from, FILTER_VALIDATE_EMAIL) == false) + { + throw new \Exception (_("adresse expéditeur invalide"),146); + } + if ( $this->smtp_type=="sendmail" && defined("ALLOWED_EMAIL_DOMAIN")) + { + $a_allowed=explode(",", ALLOWED_EMAIL_DOMAIN); + if ($this->smtp_replyto !="" ) { + list($m,$domain)=explode("@",$this->smtp_replyto); + if (!in_array($domain, $a_allowed)) { + throw new \Exception (_("adresse réponse invalide"),153); + } + } + if ($this->smtp_from !="" ) { + list($m,$domain)=explode("@",$this->smtp_from); + if (!in_array($domain, $a_allowed)) { + throw new \Exception (_("adresse expéditeur invalide"),160); + } + } + } + foreach (self::PARAMETER as $key) { $id = $this->cn->get_value("select pe_id from parm_mail_server @@ -235,13 +260,17 @@ class Mail_Parameter $this->smtp_auth=1; } - public static function Factory(\Database $cnx,$reply_to="", $blind_copy="") + public static function Factory(\Database $cnx,$reply_to="", $blind_copy="",$mail_setting=MAIL_SETTING_NOALYSS) { + $mail_parameter=new Mail_Parameter($cnx,MAIL_SETTING_NOALYSS); if ( $mail_parameter->smtp_type=="sendmail") { - return new \Sendmail($mail_parameter->smtp_replyto,$mail_parameter->smtp_replyto); + $mail=new \Sendmail(); + $mail->setReplyTo($reply_to)->setBlindCopy($blind_copy); + return $mail; } elseif ($mail_parameter->smtp_type=="smtp") { $phpmail= new SMTPMail($mail_parameter); + $phpmail->setReplyTo($reply_to)->setBlindCopy($blind_copy); return $phpmail; } diff --git a/include/lib/sendmail_core.class.php b/include/lib/sendmail_core.class.php index 5e874349b..f20876a7f 100644 --- a/include/lib/sendmail_core.class.php +++ b/include/lib/sendmail_core.class.php @@ -74,7 +74,40 @@ class Sendmail_Core $this->afile=[]; } - public function getSupplemental_param() + public function getMailto() + { + return $this->mailto; + } + + public function getBlindCopy() + { + return $this->blind_copy; + } + + public function getReplyTo() + { + return $this->reply_to; + } + + public function setMailto($mailto) + { + $this->mailto = $mailto; + return $this; + } + + public function setBlindCopy($blind_copy) + { + $this->blind_copy = $blind_copy; + return $this; + } + + public function setReplyTo($reply_to) + { + $this->reply_to = $reply_to; + return $this; + } + + public function getSupplemental_param() { return $this->supplemental_param; } diff --git a/include/template/mail_parameter-input.php b/include/template/mail_parameter-input.php index 86e0301b6..e9d152dec 100644 --- a/include/template/mail_parameter-input.php +++ b/include/template/mail_parameter-input.php @@ -80,7 +80,17 @@ $show=($this->smtp_type=="sendmail")?"none":"grid"; value="sendmail">Sendmail - + smtp_type == 'sendmail') ? "none" : "block" ;?> +
+ + +