Example #1
0
 /**
  */
 protected static function _fallbackToAscii($str)
 {
     if (!isset(self::$_map)) {
         self::$_map = array('À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'Þ' => 'TH', 'þ' => 'th', 'Ç' => 'C', 'ç' => 'c', 'Ð' => 'D', 'ð' => 'd', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ƒ' => 'f', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'Ñ' => 'N', 'ñ' => 'n', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'Š' => 'S', 'ẞ' => 'SS', 'ß' => 'ss', 'š' => 's', 'ś' => 's', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'Ý' => 'Y', 'ý' => 'y', 'ÿ' => 'y', 'Ž' => 'Z', 'ž' => 'z');
     }
     return strtr($str, self::$_map);
 }
Example #2
0
 /**
  * @throws IMP_Exception
  */
 public function __set($name, $value)
 {
     switch ($name) {
         case 'imapflag':
             /* IMAP keywords must conform to RFC 3501 [9] (flag-keyword). */
             $atom = new Horde_Imap_Client_Data_Format_Atom(strtr(Horde_String_Transliterate::toAscii($value), ' ', '_'));
             /* 3: Remove all non-atom characters. */
             $imapflag = $atom->stripNonAtomCharacters();
             /* 4: If string is empty (i.e. it contained all non-ASCII
              * characters that could not be converted), save the hashed value
              * of original string as flag. */
             if (!strlen($imapflag)) {
                 $imapflag = hash(PHP_MINOR_VERSION >= 4 ? 'fnv132' : 'sha1', $value);
             }
             $this->_imapflag = $imapflag;
             break;
         case 'label':
             $this->_label = $value;
             break;
         default:
             parent::__set($name, $value);
             break;
     }
 }
Example #3
0
 public function categoriesToFlags($mailbox, $categories, $uid)
 {
     $msgFlags = $this->_getMsgFlags();
     $mbox = new Horde_Imap_Client_Mailbox($mailbox);
     $options = array('ids' => new Horde_Imap_Client_Ids(array($uid)), 'add' => array());
     foreach ($categories as $category) {
         // Do our best to make sure the imap flag is a RFC 3501 compliant.
         $atom = new Horde_Imap_Client_Data_Format_Atom(strtr(Horde_String_Transliterate::toAscii($category), ' ', '_'));
         $imapflag = Horde_String::lower($atom->stripNonAtomCharacters());
         if (!empty($msgFlags[$imapflag])) {
             $options['add'][] = $imapflag;
             unset($msgFlags[$imapflag]);
         }
     }
     $options['remove'] = array_keys($msgFlags);
     try {
         $this->_getImapOb()->store($mbox, $options);
     } catch (Horde_Imap_Client_Exception $e) {
         throw new Horde_ActiveSync_Exception($e);
     }
 }
Example #4
0
File: Api.php Project: Gomez/horde
 /**
  * Returns a contact search result.
  *
  * @param mixed $names  The search filter values.
  * @param array $opts   Optional parameters:
  *   - customStrict: (array) An array of fields that must match exactly.
  *                   DEFAULT: None
  *   - fields: (array) The fields to search on.
  *             DEFAULT: Search all configured search fields.
  *   - forceSource: (boolean) Whether to use the specified sources, even
  *                  if they have been disabled in the preferences?
  *                  DEFAULT: false
  *   - matchBegin: (boolean) Match word boundaries only?
  *                 DEFAULT: false
  *   - returnFields: Only return these fields.
  *                   DEFAULT: Return all fields.
  *   - rfc822Return: Return a Horde_Mail_Rfc822_List object.
  *                   DEFAULT: Returns an array of search results.
  *   - sources: (array) The sources to search in.
  *              DEFAULT: Search the user's default address book
  *   - count_only: (boolean) If true, only return the count of matching
  *                           results.
  *                 DEFAULT: false (Return the full data set).
  *
  * @return mixed  Either a hash containing the search results or a
  *                Rfc822 List object (if 'rfc822Return' is true).
  * @throws Turba_Exception
  */
 public function search($names = null, array $opts = array())
 {
     global $attributes, $cfgSources, $injector;
     $opts = array_merge(array('fields' => array(), 'forceSource' => false, 'matchBegin' => false, 'returnFields' => array(), 'rfc822Return' => false, 'sources' => array(), 'customStrict' => array(), 'count_only' => false), $opts);
     $results = !empty($opts['count_only']) ? 0 : (empty($opts['rfc822Return']) ? array() : new Horde_Mail_Rfc822_List());
     if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources) || is_null($names)) {
         return $results;
     }
     if (!is_array($names)) {
         $names = array($names);
     }
     if (!$opts['forceSource']) {
         // Make sure the selected source is activated in Turba.
         $addressbooks = array_keys(Turba::getAddressBooks());
         foreach (array_keys($opts['sources']) as $id) {
             if (!in_array($opts['sources'][$id], $addressbooks)) {
                 unset($opts['sources'][$id]);
             }
         }
     }
     // ...and ensure the default source is used as a default.
     if (!count($opts['sources'])) {
         $opts['sources'] = array(Turba::getDefaultAddressbook());
     }
     $driver = $injector->getInstance('Turba_Factory_Driver');
     foreach ($opts['sources'] as $source) {
         // Skip invalid sources -or-
         // skip sources that aren't browseable if the search is empty.
         if (!isset($cfgSources[$source]) || empty($cfgSources[$source]['browse']) && (!count($names) || count($names) == 1 && empty($names[0]))) {
             continue;
         }
         if (empty($opts['fields'][$source])) {
             $opts['fields'][$source] = $GLOBALS['cfgSources'][$source]['search'];
         }
         $sdriver = $driver->create($source);
         foreach ($names as $name) {
             $trimname = trim($name);
             $out = $criteria = array();
             unset($tname);
             if (strlen($trimname)) {
                 if (isset($opts['fields'][$source])) {
                     foreach ($opts['fields'][$source] as $field) {
                         $criteria[$field] = $trimname;
                     }
                 }
             }
             try {
                 $search = $sdriver->search($criteria, Turba::getPreferredSortOrder(), 'OR', $opts['returnFields'], $opts['customStrict'], $opts['matchBegin'], $opts['count_only']);
             } catch (Exception $e) {
                 continue;
             }
             if ($opts['count_only']) {
                 $results += $search;
                 continue;
             } elseif (!$search instanceof Turba_List) {
                 continue;
             }
             $rfc822 = new Horde_Mail_Rfc822();
             while ($ob = $search->next()) {
                 $emails = $seen = array();
                 if ($ob->isGroup()) {
                     /* Is a distribution list. */
                     $members = $ob->listMembers();
                     if (!$members instanceof Turba_List || !count($members)) {
                         continue;
                     }
                     $listatt = $ob->getAttributes();
                     $listName = $ob->getValue('name');
                     while ($ob = $members->next()) {
                         foreach (array_keys($ob->getAttributes()) as $key) {
                             $value = $ob->getValue($key);
                             if (empty($value)) {
                                 continue;
                             }
                             $seen_key = trim(Horde_String::lower($ob->getValue('name'))) . trim(Horde_String::lower(is_array($value) ? $value['load']['file'] : $value));
                             if (isset($attributes[$key]) && $attributes[$key]['type'] == 'email' && empty($seen[$seen_key])) {
                                 $emails[] = $value;
                                 $seen[$seen_key] = true;
                             }
                         }
                     }
                     if (empty($opts['rfc822Return'])) {
                         $out[] = array('email' => implode(', ', $emails), 'id' => $listatt['__key'], 'name' => $listName, 'source' => $source);
                     } else {
                         $results->add(new Horde_Mail_Rfc822_Group($listName, $emails));
                     }
                 } else {
                     /* Not a group. */
                     $att = array('__key' => $ob->getValue('__key'));
                     foreach (array_keys($ob->driver->getCriteria()) as $key) {
                         $att[$key] = $ob->getValue($key);
                     }
                     $email = new Horde_Mail_Rfc822_List();
                     $display_name = $ob->hasValue('name') || !isset($ob->driver->alternativeName) ? Turba::formatName($ob) : $ob->getValue($ob->driver->alternativeName);
                     unset($tdisplay_name);
                     foreach (array_keys($att) as $key) {
                         if ($ob->getValue($key) && isset($attributes[$key]) && $attributes[$key]['type'] == 'email') {
                             $e_val = $ob->getValue($key);
                             if (strlen($trimname)) {
                                 /* Ticket #12480: Don't return email if it
                                  * doesn't contain the search string, since
                                  * an entry can contain multiple e-mail
                                  * fields. Return all e-mails if it
                                  * occurs in the name. */
                                 if (!isset($tname)) {
                                     $tname = Horde_String_Transliterate::toAscii($name);
                                 }
                                 if (!isset($tdisplay_name)) {
                                     $tdisplay_name = Horde_String_Transliterate::toAscii($display_name);
                                 }
                                 $add = Horde_String::ipos(Horde_String_Transliterate::toAscii($e_val), $tname) !== false || Horde_String::ipos($tdisplay_name, $tname) !== false;
                             } else {
                                 $add = true;
                             }
                             if ($add) {
                                 // Multiple addresses support
                                 $email->add($rfc822->parseAddressList($e_val, array('limit' => isset($attributes[$key]['params']) && is_array($attributes[$key]['params']) && !empty($attributes[$key]['params']['allow_multi']) ? 0 : 1)));
                             }
                         }
                     }
                     if (count($email)) {
                         foreach ($email as $val) {
                             $seen_key = trim(Horde_String::lower($display_name)) . '/' . Horde_String::lower($val->bare_address);
                             if (empty($seen[$seen_key])) {
                                 $seen[$seen_key] = true;
                                 if (empty($opts['rfc822Return'])) {
                                     $emails[] = $val->bare_address;
                                 } else {
                                     $val->personal = $display_name;
                                     $results->add($val);
                                 }
                             }
                         }
                     } elseif (empty($opts['rfc822Return'])) {
                         $emails[] = null;
                     }
                     if (empty($opts['rfc822Return'])) {
                         foreach ($emails as $val) {
                             $out[] = array_merge($att, array('__type' => 'Object', 'email' => $val, 'id' => $att['__key'], 'name' => $display_name, 'source' => $source));
                         }
                     }
                 }
             }
             if (!empty($out)) {
                 $results[$name] = $out;
             }
         }
     }
     return $results;
 }
Example #5
0
 /**
  * Returns an un-used access key from the label given.
  *
  * @param string $label      The label to choose an access key from.
  * @param boolean $nocheck   Don't check if the access key already has been
  *                           used?
  * @param boolean $shutdown  Is this called as a shutdown function?
  *
  * @return string  A single lower case character access key, or an empty
  *                 string if no key can be found.
  */
 public static function getAccessKey($label, $nocheck = false, $shutdown = false)
 {
     /* Shutdown call for translators? */
     if ($shutdown) {
         if (!count(self::$_labels)) {
             return;
         }
         $script = basename($_SERVER['PHP_SELF']);
         $labels = array_keys(self::$_labels);
         sort($labels);
         $used = array_keys(self::$_used);
         sort($used);
         $remaining = str_replace($used, array(), 'abcdefghijklmnopqrstuvwxyz');
         self::log('Access key information for ' . $script);
         self::log('Used labels: ' . implode(',', $labels));
         self::log('Used keys: ' . implode('', $used));
         self::log('Free keys: ' . $remaining);
         return;
     }
     /* Use access keys at all? */
     if (!isset(self::$_noAccessKey)) {
         self::$_noAccessKey = !$GLOBALS['browser']->hasFeature('accesskey') || !$GLOBALS['prefs']->getValue('widget_accesskey');
     }
     if (self::$_noAccessKey || !preg_match('/_(\\w)/u', $label, $match)) {
         return '';
     }
     $key = Horde_String_Transliterate::toAscii($match[1]);
     /* Has this key already been used? */
     if (isset(self::$_used[strtolower($key)]) && !($nocheck && isset(self::$_labels[$label]))) {
         return '';
     }
     /* Save key and label. */
     self::$_used[strtolower($key)] = true;
     self::$_labels[$label] = true;
     return $key;
 }