Skip to content

Commit

Permalink
[mms] Add support for the IMAP UTF-8 extension (RFC 6855).
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jul 21, 2014
1 parent 19031d2 commit 39e328e
Show file tree
Hide file tree
Showing 16 changed files with 1,087 additions and 441 deletions.
Expand Up @@ -65,9 +65,13 @@ public function query($capability, $parameter = null)
switch (strtoupper($capability)) {
case 'CONDSTORE':
case 'ENABLE':
/* RFC 7162 [3.2.3] - QRESYNC implies CONDSTORE and ENABLE,
* even if not listed as a capability. */
/* RFC 7162 [3.2.3] - QRESYNC implies CONDSTORE and ENABLE. */
return (is_null($parameter) && $this->query('QRESYNC'));

case 'UTF8':
/* RFC 6855 [3] - UTF8=ONLY implies UTF8=ACCEPT. */
return ((strtoupper($parameter) === 'ACCEPT') &&
$this->query('UTF8', 'ONLY'));
}

return false;
Expand Down
Expand Up @@ -20,7 +20,8 @@
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
class Horde_Imap_Client_Data_Format_ListMailbox extends Horde_Imap_Client_Data_Format_Mailbox
class Horde_Imap_Client_Data_Format_ListMailbox
extends Horde_Imap_Client_Data_Format_Mailbox
{
/**
*/
Expand Down
@@ -0,0 +1,39 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/

/**
* Object representation of an IMAP mailbox string used in a LIST command
* when UTF8=ACCEPT is supported/enabled on the server (RFC 6855 [3]).
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
class Horde_Imap_Client_Data_Format_ListMailbox_Utf8
extends Horde_Imap_Client_Data_Format_Mailbox_Utf8
{
/**
*/
protected function _filterParams()
{
$ob = parent::_filterParams();

/* Don't quote % or * characters. */
$ob->no_quote_list = true;

return $ob;
}

}
Expand Up @@ -20,8 +20,16 @@
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
class Horde_Imap_Client_Data_Format_Mailbox extends Horde_Imap_Client_Data_Format_Astring
class Horde_Imap_Client_Data_Format_Mailbox
extends Horde_Imap_Client_Data_Format_Astring
{
/**
* Mailbox encoding.
*
* @var string
*/
protected $_encoding = 'utf7imap';

/**
* Mailbox object.
*
Expand All @@ -36,7 +44,7 @@ public function __construct($data)
{
$this->_mailbox = Horde_Imap_Client_Mailbox::get($data);

parent::__construct($this->_mailbox->utf7imap);
parent::__construct($this->_mailbox->{$this->_encoding});
}

/**
Expand Down Expand Up @@ -76,15 +84,15 @@ public function binary()
*/
public function length()
{
return strlen($this->_mailbox->utf7imap);
return strlen($this->_mailbox->{$this->_encoding});
}

/**
*/
public function getStream()
{
$stream = new Horde_Stream_Temp();
$stream->add($this->_mailbox->utf7imap);
$stream->add($this->_mailbox->{$this->_encoding});
return $stream;
}

Expand Down
@@ -0,0 +1,56 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/

/**
* Object representation of an IMAP mailbox string allowed when UTF8=ACCEPT
* is supported/enabled on the server (RFC 6855 [3]).
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
class Horde_Imap_Client_Data_Format_Mailbox_Utf8
extends Horde_Imap_Client_Data_Format_Mailbox
{
/**
*/
protected $_encoding = 'utf8';

/**
*/
public function __construct($data)
{
parent::__construct($data);

/* RFC 3501 allows any US-ASCII character, except null (\0), in
* mailbox data.
* RFC 6855 [3] institutes additional limitations on valid mailbox
* characters, to comply with RFC 5198 [2] (Net-Unicode Definition):
* "MUST NOT contain control characters (U+0000-U+001F and
* U+0080-U+009F), a delete character (U+007F), a line separator
* (U+2028), or a paragraph separator (U+2029)." */
if ($this->quoted() &&
preg_match('/[\x00-\x1f\x7f\x80-\x9f\x{2028}\x{2029}]/u', strval($this))) {
throw new Horde_Imap_Client_Data_Format_Exception(
'Invalid character found in mailbox data.'
);
}

if ($this->literal()) {
$this->forceQuoted();
}
}

}
@@ -0,0 +1,66 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/

/**
* Query the search charsets available on a server that supports the UTF-8
* IMAP extension (RFC 6855).
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
* @since 2.24.0
*/
class Horde_Imap_Client_Data_SearchCharset_Utf8
extends Horde_Imap_Client_Data_SearchCharset
{
/**
* Charset data.
*
* @var array
*/
protected $_charsets = array(
'US-ASCII' => true,
'UTF-8' => true
);

/**
*/
public function query($charset, $cached = false)
{
return isset($this->_charsets[strtoupper($charset)]);
}

/**
*/
public function setValid($charset, $valid = true)
{
}

/* Serializable methods. */

/**
*/
public function serialize()
{
return '';
}

/**
*/
public function unserialize($data)
{
}

}

0 comments on commit 39e328e

Please sign in to comment.