Пример #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
 /**
  * Make sure MOBILE phone is returned as CELL (as specified in standard)
  */
 function test_parse_three()
 {
     $vcard = new rcube_vcard(file_get_contents($this->_srcpath('johndoe.vcf')), null);
     $vcf = $vcard->export();
     $this->assertRegExp('/TEL;CELL:\\+987654321/', $vcf, "Return CELL instead of MOBILE (import)");
     $vcard = new rcube_vcard();
     $vcard->set('phone', '+987654321', 'MOBILE');
     $vcf = $vcard->export();
     $this->assertRegExp('/TEL;TYPE=CELL:\\+987654321/', $vcf, "Return CELL instead of MOBILE (set)");
 }
 /**
  * Adds a Name field to vcard if missing
  *
  * @param  string $vcard vCard
  * @return string
  */
 private function vcard_check($raw)
 {
     if ($raw !== null) {
         $vcard = new rcube_vcard();
         $vcard->load($raw);
         $data = $vcard->get_assoc();
         if (!isset($data['name'])) {
             if (isset($data['surname'])) {
                 $data['name'] = $data['surname'];
             } else {
                 if (isset($data['displayname'])) {
                     $data['name'] = $data['displayname'];
                 } else {
                     if (isset($data['nickname'])) {
                         $data['name'] = $data['nickname'];
                     } else {
                         if (isset($data['firstname'])) {
                             $data['name'] = $data['firstname'];
                         } else {
                             if (isset($data['middlename'])) {
                                 $data['name'] = $data['middlename'];
                             } else {
                                 if (is_array($data['email:home'])) {
                                     $data['name'] = $data['email:home'][0];
                                 } else {
                                     if (is_array($data['email:work'])) {
                                         $data['name'] = $data['email:work'][0];
                                     } else {
                                         if (is_array($data['email:other'])) {
                                             $data['name'] = $data['email:other'][0];
                                         } else {
                                             $data['name'] = 'unknown';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $vcard->set('surname', '', false);
             $vcard->set('firstname', current(explode('@', $data['name'])), false);
             $raw = $vcard->export();
         }
     }
     return $raw;
 }
 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;
 }
Пример #5
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;
     }
 }