10a5b05ebSAndreas Gohr<?php 20a5b05ebSAndreas Gohr 30a5b05ebSAndreas Gohrnamespace dokuwiki\plugin\config\core\Setting; 40a5b05ebSAndreas Gohr 50a5b05ebSAndreas Gohr/** 60a5b05ebSAndreas Gohr * Class setting_email 70a5b05ebSAndreas Gohr */ 88c7c53b0SAndreas Gohrclass SettingEmail extends SettingString 98c7c53b0SAndreas Gohr{ 100a5b05ebSAndreas Gohr protected $multiple = false; 110a5b05ebSAndreas Gohr protected $placeholders = false; 120a5b05ebSAndreas Gohr 130a5b05ebSAndreas Gohr /** @inheritdoc */ 14*d868eb89SAndreas Gohr public function update($input) 15*d868eb89SAndreas Gohr { 160a5b05ebSAndreas Gohr if (is_null($input)) return false; 170a5b05ebSAndreas Gohr if ($this->isProtected()) return false; 180a5b05ebSAndreas Gohr 190a5b05ebSAndreas Gohr $value = is_null($this->local) ? $this->default : $this->local; 200a5b05ebSAndreas Gohr if ($value == $input) return false; 210a5b05ebSAndreas Gohr if ($input === '') { 220a5b05ebSAndreas Gohr $this->local = $input; 230a5b05ebSAndreas Gohr return true; 240a5b05ebSAndreas Gohr } 250a5b05ebSAndreas Gohr $mail = $input; 260a5b05ebSAndreas Gohr 270a5b05ebSAndreas Gohr if ($this->placeholders) { 280a5b05ebSAndreas Gohr // replace variables with pseudo values 290a5b05ebSAndreas Gohr $mail = str_replace('@USER@', 'joe', $mail); 300a5b05ebSAndreas Gohr $mail = str_replace('@NAME@', 'Joe Schmoe', $mail); 310a5b05ebSAndreas Gohr $mail = str_replace('@MAIL@', 'joe@example.com', $mail); 320a5b05ebSAndreas Gohr } 330a5b05ebSAndreas Gohr 340a5b05ebSAndreas Gohr // multiple mail addresses? 350a5b05ebSAndreas Gohr if ($this->multiple) { 360a5b05ebSAndreas Gohr $mails = array_filter(array_map('trim', explode(',', $mail))); 370a5b05ebSAndreas Gohr } else { 38467c1427SAndreas Gohr $mails = [$mail]; 390a5b05ebSAndreas Gohr } 400a5b05ebSAndreas Gohr 410a5b05ebSAndreas Gohr // check them all 420a5b05ebSAndreas Gohr foreach ($mails as $mail) { 430a5b05ebSAndreas Gohr // only check the address part 440a5b05ebSAndreas Gohr if (preg_match('#(.*?)<(.*?)>#', $mail, $matches)) { 450a5b05ebSAndreas Gohr $addr = $matches[2]; 460a5b05ebSAndreas Gohr } else { 470a5b05ebSAndreas Gohr $addr = $mail; 480a5b05ebSAndreas Gohr } 490a5b05ebSAndreas Gohr 500a5b05ebSAndreas Gohr if (!mail_isvalid($addr)) { 510a5b05ebSAndreas Gohr $this->error = true; 520a5b05ebSAndreas Gohr $this->input = $input; 530a5b05ebSAndreas Gohr return false; 540a5b05ebSAndreas Gohr } 550a5b05ebSAndreas Gohr } 560a5b05ebSAndreas Gohr 570a5b05ebSAndreas Gohr $this->local = $input; 580a5b05ebSAndreas Gohr return true; 590a5b05ebSAndreas Gohr } 600a5b05ebSAndreas Gohr} 61