10a5b05ebSAndreas Gohr<?php 20a5b05ebSAndreas Gohr 30a5b05ebSAndreas Gohrnamespace dokuwiki\plugin\config\core\Setting; 40a5b05ebSAndreas Gohr 573dc0a89SAndreas Gohruse dokuwiki\MailUtils; 673dc0a89SAndreas Gohr 70a5b05ebSAndreas Gohr/** 80a5b05ebSAndreas Gohr * Class setting_email 90a5b05ebSAndreas Gohr */ 108c7c53b0SAndreas Gohrclass SettingEmail extends SettingString 118c7c53b0SAndreas Gohr{ 120a5b05ebSAndreas Gohr protected $multiple = false; 130a5b05ebSAndreas Gohr protected $placeholders = false; 140a5b05ebSAndreas Gohr 150a5b05ebSAndreas Gohr /** @inheritdoc */ 16d868eb89SAndreas Gohr public function update($input) 17d868eb89SAndreas Gohr { 180a5b05ebSAndreas Gohr if (is_null($input)) return false; 190a5b05ebSAndreas Gohr if ($this->isProtected()) return false; 200a5b05ebSAndreas Gohr 21*2848662bSsplitbrain $value = $this->local ?? $this->default; 220a5b05ebSAndreas Gohr if ($value == $input) return false; 230a5b05ebSAndreas Gohr if ($input === '') { 240a5b05ebSAndreas Gohr $this->local = $input; 250a5b05ebSAndreas Gohr return true; 260a5b05ebSAndreas Gohr } 270a5b05ebSAndreas Gohr $mail = $input; 280a5b05ebSAndreas Gohr 290a5b05ebSAndreas Gohr if ($this->placeholders) { 300a5b05ebSAndreas Gohr // replace variables with pseudo values 310a5b05ebSAndreas Gohr $mail = str_replace('@USER@', 'joe', $mail); 320a5b05ebSAndreas Gohr $mail = str_replace('@NAME@', 'Joe Schmoe', $mail); 330a5b05ebSAndreas Gohr $mail = str_replace('@MAIL@', 'joe@example.com', $mail); 340a5b05ebSAndreas Gohr } 350a5b05ebSAndreas Gohr 360a5b05ebSAndreas Gohr // multiple mail addresses? 370a5b05ebSAndreas Gohr if ($this->multiple) { 38093fe67eSAndreas Gohr $mails = array_filter(array_map(trim(...), explode(',', $mail))); 390a5b05ebSAndreas Gohr } else { 40467c1427SAndreas Gohr $mails = [$mail]; 410a5b05ebSAndreas Gohr } 420a5b05ebSAndreas Gohr 430a5b05ebSAndreas Gohr // check them all 440a5b05ebSAndreas Gohr foreach ($mails as $mail) { 450a5b05ebSAndreas Gohr // only check the address part 460a5b05ebSAndreas Gohr if (preg_match('#(.*?)<(.*?)>#', $mail, $matches)) { 470a5b05ebSAndreas Gohr $addr = $matches[2]; 480a5b05ebSAndreas Gohr } else { 490a5b05ebSAndreas Gohr $addr = $mail; 500a5b05ebSAndreas Gohr } 510a5b05ebSAndreas Gohr 5273dc0a89SAndreas Gohr if (!MailUtils::isValid($addr)) { 530a5b05ebSAndreas Gohr $this->error = true; 540a5b05ebSAndreas Gohr $this->input = $input; 550a5b05ebSAndreas Gohr return false; 560a5b05ebSAndreas Gohr } 570a5b05ebSAndreas Gohr } 580a5b05ebSAndreas Gohr 590a5b05ebSAndreas Gohr $this->local = $input; 600a5b05ebSAndreas Gohr return true; 610a5b05ebSAndreas Gohr } 620a5b05ebSAndreas Gohr} 63