-
- // use email address part for name
- if (empty($contact['name']) || $contact['name'] == $contact['email'])
- $contact['name'] = ucfirst(preg_replace('/[\.\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@'))));
+
+ // Validity checks
+ if (empty($contact['email'])) {
+ $OUTPUT->show_message('errorsavingcontact', 'error');
+ $OUTPUT->send();
+ }
+
+ $email = rcube_idn_to_ascii($contact['email']);
+ if (!check_email($email, false)) {
+ $OUTPUT->show_message('emailformaterror', 'error', array('email' => $contact['email']));
+ $OUTPUT->send();
+ }
+
+ $contact['email'] = rcube_idn_to_utf8($contact['email']);
+ $contact['name'] = rcube_addressbook::compose_display_name($contact);
+
+ // validate contact record
+ if (!$CONTACTS->validate($contact, true)) {
+ $error = $CONTACTS->get_error();
+ // TODO: show dialog to complete record
+ // if ($error['type'] == rcube_addressbook::ERROR_VALIDATE) { }
+
+ $OUTPUT->show_message($error['message'] ? $error['message'] : 'errorsavingcontact', 'error');
+ $OUTPUT->send();
+ }