/** * @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; } }
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); } }
/** * @dataProvider stripNonAtomCharactersProvider */ public function testStripNonAtomCharacters($str, $expected) { $atom = new Horde_Imap_Client_Data_Format_Atom($str); $this->assertEquals($expected, $atom->stripNonAtomCharacters()); }