diff options
author | Thomas Bruederli <thomas@roundcube.net> | 2013-10-19 15:49:49 +0200 |
---|---|---|
committer | Thomas Bruederli <thomas@roundcube.net> | 2013-10-19 15:49:49 +0200 |
commit | 49b8e5d0bb712ccf1a1a52bd794d3d7bb905a493 (patch) | |
tree | aa71ad7e1c9817a0aea5174262e2629b0ba2620b /program | |
parent | 1498ac81c9462808fcfdc6ca69f31209a0181cdd (diff) |
Add plugin hook 'contact_validate' to let plugins validate contact records
Diffstat (limited to 'program')
-rw-r--r-- | program/lib/Roundcube/rcube_addressbook.php | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/program/lib/Roundcube/rcube_addressbook.php b/program/lib/Roundcube/rcube_addressbook.php index 6e2b439d8..cd347af25 100644 --- a/program/lib/Roundcube/rcube_addressbook.php +++ b/program/lib/Roundcube/rcube_addressbook.php @@ -209,6 +209,7 @@ abstract class rcube_addressbook public function validate(&$save_data, $autofix = false) { $rcube = rcube::get_instance(); + $valid = true; // check validity of email addresses foreach ($this->get_col_values('email', $save_data, true) as $email) { @@ -216,12 +217,30 @@ abstract class rcube_addressbook if (!rcube_utils::check_email(rcube_utils::idn_to_ascii($email))) { $error = $rcube->gettext(array('name' => 'emailformaterror', 'vars' => array('email' => $email))); $this->set_error(self::ERROR_VALIDATE, $error); - return false; + $valid = false; + break; } } } - return true; + // require at least one email address or a name + if ($valid && !strlen($save_data['firstname'].$save_data['surname'].$save_data['name']) && !array_filter($this->get_col_values('email', $save_data, true))) { + $this->set_error(self::ERROR_VALIDATE, 'noemailwarning'); + $valid = false; + } + + // allow plugins to do contact validation and auto-fixing + $plugin = $rcube->plugins->exec_hook('contact_validate', array( + 'record' => $save_data, + 'autofix' => $autofix, + 'valid' => $valid, + )); + + if (is_array($plugin['record'])) { + $save_data = $plugin['record']; + } + + return $plugin['valid']; } /** |