/** * Handler for request action */ function save_vcard() { $this->add_texts('localization', true); $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST); $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST); $rcmail = rcmail::get_instance(); $storage = $rcmail->get_storage(); $storage->set_folder($mbox); if ($uid && $mime_id) { list($mime_id, $index) = explode(':', $mime_id); $part = $storage->get_message_part($uid, $mime_id, null, null, null, true); } $error_msg = $this->gettext('vcardsavefailed'); if ($part && ($vcards = rcube_vcard::import($part)) && ($vcard = $vcards[$index]) && $vcard->displayname && $vcard->email) { $CONTACTS = $this->get_address_book(); $email = $vcard->email[0]; $contact = $vcard->get_assoc(); $valid = true; // skip entries without an e-mail address or invalid if (empty($email) || !$CONTACTS->validate($contact, true)) { $valid = false; } else { // We're using UTF8 internally $email = rcube_utils::idn_to_utf8($email); // compare e-mail address $existing = $CONTACTS->search('email', $email, 1, false); // compare display name if (!$existing->count && $vcard->displayname) { $existing = $CONTACTS->search('name', $vcard->displayname, 1, false); } if ($existing->count) { $rcmail->output->command('display_message', $this->gettext('contactexists'), 'warning'); $valid = false; } } if ($valid) { $plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null)); $contact = $plugin['record']; if (!$plugin['abort'] && $CONTACTS->insert($contact)) { $rcmail->output->command('display_message', $this->gettext('addedsuccessfully'), 'confirmation'); } else { $rcmail->output->command('display_message', $error_msg, 'error'); } } } else { $rcmail->output->command('display_message', $error_msg, 'error'); } $rcmail->output->send(); }
function test_encodings() { $input = file_get_contents($this->_srcpath('utf-16_sample.vcf')); $vcards = rcube_vcard::import($input); $this->assertEquals("Ǽgean ĽdaMonté", $vcards[0]->displayname, "Decoded from UTF-16"); }
/** * Handler for request action */ function save_vcard() { $this->add_texts('localization', true); $uid = get_input_value('_uid', RCUBE_INPUT_POST); $mbox = get_input_value('_mbox', RCUBE_INPUT_POST); $mime_id = get_input_value('_part', RCUBE_INPUT_POST); $rcmail = rcmail::get_instance(); if ($uid && $mime_id) { list($mime_id, $index) = explode(':', $mime_id); $part = $rcmail->imap->get_message_part($uid, $mime_id); } $error_msg = $this->gettext('vcardsavefailed'); if ($part && ($vcards = rcube_vcard::import($part)) && ($vcard = $vcards[$index]) && $vcard->displayname && $vcard->email) { $contacts = $rcmail->get_address_book(null, true); // check for existing contacts $existing = $contacts->search('email', $vcard->email[0], true, false); if ($existing->count) { $rcmail->output->command('display_message', $this->gettext('contactexists'), 'warning'); } else { // add contact $contact = array('name' => $vcard->displayname, 'firstname' => $vcard->firstname, 'surname' => $vcard->surname, 'email' => $vcard->email[0], 'vcard' => $vcard->export()); $plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null)); $contact = $plugin['record']; if (!$plugin['abort'] && ($done = $contacts->insert($contact))) { $rcmail->output->command('display_message', $this->gettext('addedsuccessfully'), 'confirmation'); } else { $rcmail->output->command('display_message', $error_msg, 'error'); } } } else { $rcmail->output->command('display_message', $error_msg, 'error'); } $rcmail->output->send(); }