コード例 #1
0
 /**
  * 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();
     $part = $uid && $mime_id ? $rcmail->imap->get_message_part($uid, $mime_id) : null;
     $error_msg = $this->gettext('vcardsavefailed');
     if ($part && ($vcard = new rcube_vcard($part)) && $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 ($done = $existing->count) {
             $rcmail->output->command('display_message', $this->gettext('contactexists'), 'warning');
         } else {
             // add contact
             $success = $contacts->insert(array('name' => $vcard->displayname, 'firstname' => $vcard->firstname, 'surname' => $vcard->surname, 'email' => $vcard->email[0], 'vcard' => $vcard->export()));
             if ($success) {
                 $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();
 }
コード例 #2
0
ファイル: rcube_csv2vcard.php プロジェクト: BIGGANI/zpanelx
 /**
  * Convert CSV data row to vCard
  */
 protected function csv_to_vcard($data)
 {
     $contact = array();
     foreach ($this->map as $idx => $name) {
         $value = $data[$idx];
         if ($value !== null && $value !== '') {
             $contact[$name] = $value;
         }
     }
     if (empty($contact)) {
         return;
     }
     // Handle special values
     if (!empty($contact['birthday-d']) && !empty($contact['birthday-m']) && !empty($contact['birthday-y'])) {
         $contact['birthday'] = $contact['birthday-y'] . '-' . $contact['birthday-m'] . '-' . $contact['birthday-d'];
     }
     // categories/groups separator in vCard is ',' not ';'
     if (!empty($contact['groups'])) {
         $contact['groups'] = str_replace(';', ',', $contact['groups']);
     }
     // Empty dates, e.g. "0/0/00", "0000-00-00 00:00:00"
     foreach (array('birthday', 'anniversary') as $key) {
         if (!empty($contact[$key])) {
             $date = preg_replace('/[0[:^word:]]/', '', $contact[$key]);
             if (empty($date)) {
                 unset($contact[$key]);
             }
         }
     }
     if (!empty($contact['gender']) && ($gender = strtolower($contact['gender']))) {
         if (!in_array($gender, array('male', 'female'))) {
             unset($contact['gender']);
         }
     }
     // Convert address(es) to rcube_vcard data
     foreach ($contact as $idx => $value) {
         $name = explode(':', $idx);
         if (in_array($name[0], array('street', 'locality', 'region', 'zipcode', 'country'))) {
             $contact['address:' . $name[1]][$name[0]] = $value;
             unset($contact[$idx]);
         }
     }
     // Create vcard object
     $vcard = new rcube_vcard();
     foreach ($contact as $name => $value) {
         $name = explode(':', $name);
         $vcard->set($name[0], $value, $name[1]);
     }
     // add to the list
     $this->vcards[] = $vcard;
 }
コード例 #3
0
 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");
 }
コード例 #4
0
 /**
  * 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();
 }
コード例 #5
0
 /**
  * Decode a given string with the encoding rule from ENCODING attributes
  *
  * @param string String to decode
  * @param string Encoding type (quoted-printable and base64 supported)
  * @return string Decoded 8bit value
  */
 private static function decode_value($value, $encoding)
 {
     switch (strtolower($encoding)) {
         case 'quoted-printable':
             self::$values_decoded = true;
             return quoted_printable_decode($value);
         case 'base64':
         case 'b':
             self::$values_decoded = true;
             return base64_decode($value);
         default:
             return $value;
     }
 }
コード例 #6
0
 /**
  * Sync groups upstream
  *
  * @param  integer $gid (group id)
  * @return void
  */
 function groups_upstream_sync($gid)
 {
     $sql = 'SELECT * FROM ' . get_table_name($this->db_groupmembers) . ' WHERE contactgroup_id=?';
     $res = $this->db->query($sql, $gid);
     while ($member = $this->db->fetch_assoc($res)) {
         $members[] = $member;
     }
     if (is_array($members)) {
         foreach ($members as $member) {
             $sql = 'SELECT * FROM ' . get_table_name($this->db_name) . ' WHERE user_id=? AND carddav_contact_id=?';
             $res = $this->db->query($sql, $this->rc->user->ID, $member['contact_id']);
             $contact = $this->db->fetch_assoc($res);
             $vcard = new rcube_vcard();
             $vcard->load($contact['vcard']);
             $save_data = $vcard->get_assoc();
             $save_data['groups'][0] = array();
             $sql = 'SELECT contactgroup_id FROM ' . get_table_name($this->db_groupmembers) . ' WHERE contact_id=?';
             $res = $this->db->query($sql, $member['contact_id']);
             while ($group_id = $this->rc->db->fetch_assoc($res)) {
                 $group_ids[] = $group_id;
             }
             if (!empty($group_ids)) {
                 $categories = array();
                 foreach ($group_ids as $group_id) {
                     $sql = 'SELECT name FROM ' . get_table_name($this->db_groups) . ' WHERE contactgroup_id=? AND del=?';
                     $res = $this->db->query($sql, $group_id['contactgroup_id'], 0);
                     if ($category = $this->rc->db->fetch_assoc($res)) {
                         if ($category['name']) {
                             $categories[$category['name']] = $category['name'];
                         }
                     }
                 }
                 if (!empty($categories)) {
                     $save_data['groups'] = implode(',', $categories);
                 }
             }
             $this->update($member['contact_id'], $save_data);
         }
     }
 }
コード例 #7
0
 private function convert_save_data($save_data, $record = array())
 {
     $out = array();
     $words = '';
     // copy values into vcard object
     $vcard = new rcube_vcard($record['vcard'] ? $record['vcard'] : $save_data['vcard'], RCMAIL_CHARSET, false, $this->vcard_fieldmap);
     $vcard->reset();
     foreach ($save_data as $key => $values) {
         list($field, $section) = explode(':', $key);
         $fulltext = in_array($field, $this->fulltext_cols);
         foreach ((array) $values as $value) {
             if (isset($value)) {
                 $vcard->set($field, $value, $section);
             }
             if ($fulltext && is_array($value)) {
                 $words .= ' ' . rcube_utils::normalize_string(join(" ", $value));
             } else {
                 if ($fulltext && strlen($value) >= 3) {
                     $words .= ' ' . rcube_utils::normalize_string($value);
                 }
             }
         }
     }
     $out['vcard'] = $vcard->export(false);
     foreach ($this->table_cols as $col) {
         $key = $col;
         if (!isset($save_data[$key])) {
             $key .= ':home';
         }
         if (isset($save_data[$key])) {
             if (is_array($save_data[$key])) {
                 $out[$col] = join(self::SEPARATOR, $save_data[$key]);
             } else {
                 $out[$col] = $save_data[$key];
             }
         }
     }
     // save all e-mails in database column
     $out['email'] = join(self::SEPARATOR, $vcard->email);
     // join words for fulltext search
     $out['words'] = join(" ", array_unique(explode(" ", $words)));
     return $out;
 }
コード例 #8
0
 /**
  * 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();
 }
コード例 #9
0
 /**
  * Get vcard data for specified contact
  */
 private function get_contact_vcard($source, $cid, &$filename = null)
 {
     $rcmail = rcmail::get_instance();
     $source = $rcmail->get_address_book($source);
     $contact = $source->get_record($cid, true);
     if ($contact) {
         $fieldmap = $source ? $source->vcard_map : null;
         if (empty($contact['vcard'])) {
             $vcard = new rcube_vcard('', RCUBE_CHARSET, false, $fieldmap);
             $vcard->reset();
             foreach ($contact as $key => $values) {
                 list($field, $section) = explode(':', $key);
                 // avoid unwanted casting of DateTime objects to an array
                 // (same as in rcube_contacts::convert_save_data())
                 if (is_object($values) && is_a($values, 'DateTime')) {
                     $values = array($values);
                 }
                 foreach ((array) $values as $value) {
                     if (is_array($value) || is_a($value, 'DateTime') || @strlen($value)) {
                         $vcard->set($field, $value, strtoupper($section));
                     }
                 }
             }
             $contact['vcard'] = $vcard->export();
         }
         $name = rcube_addressbook::compose_list_name($contact);
         $filename = (self::parse_filename($name) ?: 'contact') . '.vcf';
         // fix folding and end-of-line chars
         $vcard = preg_replace('/\\r|\\n\\s+/', '', $contact['vcard']);
         $vcard = preg_replace('/\\n/', rcube_vcard::$eol, $vcard);
         return rcube_vcard::rfc2425_fold($vcard) . rcube_vcard::$eol;
     }
 }
コード例 #10
0
 /**
  * Convert CSV data row to vCard
  */
 protected function csv_to_vcard($data)
 {
     $contact = array();
     foreach ($this->map as $idx => $name) {
         $value = $data[$idx];
         if ($value !== null && $value !== '') {
             if (!empty($contact[$name])) {
                 $contact[$name] = (array) $contact[$name];
                 $contact[$name][] = $value;
             } else {
                 $contact[$name] = $value;
             }
         }
     }
     // Gmail format support
     foreach ($this->gmail_map as $idx => $item) {
         $type = preg_replace('/[^a-z]/', '', strtolower($data[$item['_idx']]));
         $key = $item['_key'];
         unset($item['_idx']);
         unset($item['_key']);
         foreach ($item as $item_key => $item_idx) {
             $value = $data[$item_idx];
             if ($value !== null && $value !== '') {
                 foreach (array($type, '*') as $_type) {
                     if ($data_idx = $this->gmail_label_map[$key][$item_key][$_type]) {
                         $value = explode(' ::: ', $value);
                         if (!empty($contact[$data_idx])) {
                             $contact[$data_idx] = array_merge((array) $contact[$data_idx], $value);
                         } else {
                             $contact[$data_idx] = $value;
                         }
                         break;
                     }
                 }
             }
         }
     }
     if (empty($contact)) {
         return;
     }
     // Handle special values
     if (!empty($contact['birthday-d']) && !empty($contact['birthday-m']) && !empty($contact['birthday-y'])) {
         $contact['birthday'] = $contact['birthday-y'] . '-' . $contact['birthday-m'] . '-' . $contact['birthday-d'];
     }
     if (!empty($contact['groups'])) {
         // categories/groups separator in vCard is ',' not ';'
         $contact['groups'] = str_replace(',', '', $contact['groups']);
         $contact['groups'] = str_replace(';', ',', $contact['groups']);
         if (!empty($this->gmail_map)) {
             // remove "* " added by GMail
             $contact['groups'] = str_replace('* ', '', $contact['groups']);
             // replace strange delimiter
             $contact['groups'] = str_replace(' ::: ', ',', $contact['groups']);
         }
     }
     // Empty dates, e.g. "0/0/00", "0000-00-00 00:00:00"
     foreach (array('birthday', 'anniversary') as $key) {
         if (!empty($contact[$key])) {
             $date = preg_replace('/[0[:^word:]]/', '', $contact[$key]);
             if (empty($date)) {
                 unset($contact[$key]);
             }
         }
     }
     if (!empty($contact['gender']) && ($gender = strtolower($contact['gender']))) {
         if (!in_array($gender, array('male', 'female'))) {
             unset($contact['gender']);
         }
     }
     // Convert address(es) to rcube_vcard data
     foreach ($contact as $idx => $value) {
         $name = explode(':', $idx);
         if (in_array($name[0], array('street', 'locality', 'region', 'zipcode', 'country'))) {
             $contact['address:' . $name[1]][$name[0]] = $value;
             unset($contact[$idx]);
         }
     }
     // Create vcard object
     $vcard = new rcube_vcard();
     foreach ($contact as $name => $value) {
         $name = explode(':', $name);
         if (is_array($value) && $name[0] != 'address') {
             foreach ((array) $value as $val) {
                 $vcard->set($name[0], $val, $name[1]);
             }
         } else {
             $vcard->set($name[0], $value, $name[1]);
         }
     }
     // add to the list
     $this->vcards[] = $vcard;
 }
コード例 #11
0
 /**
  * Convert CSV data row to vCard
  */
 protected function csv_to_vcard($data)
 {
     $contact = array();
     foreach ($this->map as $idx => $name) {
         $value = $data[$idx];
         if ($value !== null && $value !== '') {
             $contact[$name] = $value;
         }
     }
     if (empty($contact)) {
         return;
     }
     // Handle special values
     if (!empty($contact['birthday-d']) && !empty($contact['birthday-m']) && !empty($contact['birthday-y'])) {
         $contact['birthday'] = $contact['birthday-y'] . '-' . $contact['birthday-m'] . '-' . $contact['birthday-d'];
     }
     foreach (array('birthday', 'anniversary') as $key) {
         if (!empty($contact[$key]) && $contact[$key] == '0/0/00') {
             // @TODO: localization?
             unset($contact[$key]);
         }
     }
     if (!empty($contact['gender']) && ($gender = strtolower($contact['gender']))) {
         if (!in_array($gender, array('male', 'female'))) {
             unset($contact['gender']);
         }
     }
     // Convert address(es) to rcube_vcard data
     foreach ($contact as $idx => $value) {
         $name = explode(':', $idx);
         if (in_array($name[0], array('street', 'locality', 'region', 'zipcode', 'country'))) {
             $contact['address:' . $name[1]][$name[0]] = $value;
             unset($contact[$idx]);
         }
     }
     // Create vcard object
     $vcard = new rcube_vcard();
     foreach ($contact as $name => $value) {
         $name = explode(':', $name);
         $vcard->set($name[0], $value, $name[1]);
     }
     // add to the list
     $this->vcards[] = $vcard;
 }