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