SettingEmail.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace dokuwiki\plugin\config\core\Setting;
  3. /**
  4. * Class setting_email
  5. */
  6. class SettingEmail extends SettingString {
  7. protected $multiple = false;
  8. protected $placeholders = false;
  9. /** @inheritdoc */
  10. public function update($input) {
  11. if(is_null($input)) return false;
  12. if($this->isProtected()) return false;
  13. $value = is_null($this->local) ? $this->default : $this->local;
  14. if($value == $input) return false;
  15. if($input === '') {
  16. $this->local = $input;
  17. return true;
  18. }
  19. $mail = $input;
  20. if($this->placeholders) {
  21. // replace variables with pseudo values
  22. $mail = str_replace('@USER@', 'joe', $mail);
  23. $mail = str_replace('@NAME@', 'Joe Schmoe', $mail);
  24. $mail = str_replace('@MAIL@', 'joe@example.com', $mail);
  25. }
  26. // multiple mail addresses?
  27. if($this->multiple) {
  28. $mails = array_filter(array_map('trim', explode(',', $mail)));
  29. } else {
  30. $mails = array($mail);
  31. }
  32. // check them all
  33. foreach($mails as $mail) {
  34. // only check the address part
  35. if(preg_match('#(.*?)<(.*?)>#', $mail, $matches)) {
  36. $addr = $matches[2];
  37. } else {
  38. $addr = $mail;
  39. }
  40. if(!mail_isvalid($addr)) {
  41. $this->error = true;
  42. $this->input = $input;
  43. return false;
  44. }
  45. }
  46. $this->local = $input;
  47. return true;
  48. }
  49. }