22 | * @category Horde
23 | * @copyright 2011-2016 Horde LLC
24 | * @ignore
25 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26 | * @package Imap_Client
27 | * @subpackage UnitTests
28 | */
29 | class Utf7ConvertTest extends TestCase
30 | {
31 | public static function setUpBeforeClass(): void
32 | {
33 | require_once __DIR__ . '/Stub/Utf7imap.php';
34 | }
35 |
36 | /**
37 | * @dataProvider conversionProvider
38 | * @requires extension mbstring
39 | */
40 | public function testConversionWithMbstring($orig, $expected = null)
41 | {
42 | Utf7imap::setMbstring(true);
43 |
44 | $this->_testConversion($orig, $expected);
45 | }
46 |
47 | /**
48 | * @dataProvider conversionProvider
49 | */
50 | public function testConversionWithoutMbstring($orig, $expected = null)
51 | {
52 | Utf7imap::setMbstring(false);
53 |
54 | $this->_testConversion($orig, $expected);
55 | }
56 |
57 | protected function _testConversion($orig, $expected)
58 | {
59 | $utf7_imap = Utf7imap::Utf8ToUtf7Imap(
60 | $orig,
61 | !is_null($expected)
62 | );
63 |
64 | $this->assertEquals(
65 | $expected ?: $orig,
66 | $utf7_imap
67 | );
68 |
69 | if ($expected) {
70 | $utf8 = Utf7imap::Utf7ImapToUtf8($utf7_imap);
71 | $this->assertEquals(
72 | $orig,
73 | $utf8
74 | );
75 | }
76 | }
77 |
78 | public function conversionProvider()
79 | {
80 | return array(
81 | array('Envoyé', 'Envoy&AOk-'),
82 | array('Töst-', 'T&APY-st-'),
83 | array('&', '&-'),
84 | array('&-'),
85 | array('Envoy&AOk-'),
86 | array('T&APY-st-'),
87 | // Bug #10133
88 | array('Entw&APw-rfe'),
89 | // Bug #10093
90 | array('Foo&Bar-2011', 'Foo&-Bar-2011')
91 | );
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/lib/Horde/Imap/Client/Exception/ServerResponse.php:
--------------------------------------------------------------------------------
1 |
18 | * @category Horde
19 | * @copyright 2012-2017 Horde LLC
20 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
21 | * @package Imap_Client
22 | *
23 | * @property-read string $command The command that caused the BAD/NO error
24 | * status.
25 | * @property-read array $resp_data The response data array.
26 | * @property-read integer $status Server error status.
27 | */
28 | class Horde_Imap_Client_Exception_ServerResponse extends Horde_Imap_Client_Exception
29 | {
30 | /**
31 | * Pipeline object.
32 | *
33 | * @var Horde_Imap_Client_Interaction_Pipeline
34 | */
35 | protected $_pipeline;
36 |
37 | /**
38 | * Server response object.
39 | *
40 | * @var Horde_Imap_Client_Interaction_Server
41 | */
42 | protected $_server;
43 |
44 | /**
45 | * Constructor.
46 | *
47 | * @param string|null $msg Error message.
48 | * @param integer $code Error code.
49 | * @param Horde_Imap_Client_Interaction_Server $server Server ob.
50 | * @param Horde_Imap_Client_Interaction_Pipeline $pipeline Pipeline ob.
51 | */
52 | public function __construct(
53 | $msg,
54 | $code,
55 | Horde_Imap_Client_Interaction_Server $server,
56 | Horde_Imap_Client_Interaction_Pipeline $pipeline
57 | )
58 | {
59 | $this->details = strval($server->token);
60 |
61 | $this->_pipeline = $pipeline;
62 | $this->_server = $server;
63 |
64 | parent::__construct($msg, $code);
65 | }
66 |
67 | /**
68 | */
69 | public function __get($name)
70 | {
71 | switch ($name) {
72 | case 'command':
73 | return ($this->_server instanceof Horde_Imap_Client_Interaction_Server_Tagged)
74 | ? $this->_pipeline->getCmd($this->_server->tag)->getCommand()
75 | : null;
76 |
77 | case 'resp_data':
78 | return $this->_pipeline->data;
79 |
80 | case 'status':
81 | return $this->_server->status;
82 |
83 | default:
84 | return parent::__get($name);
85 | }
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/SearchCharsetUtf8Test.php:
--------------------------------------------------------------------------------
1 |
22 | * @category Horde
23 | * @copyright 2014-2016 Horde LLC
24 | * @ignore
25 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26 | * @package Imap_Client
27 | * @subpackage UnitTests
28 | */
29 | class SearchCharsetUtf8Test extends TestCase
30 | {
31 | public function testQuery()
32 | {
33 | $s = new Horde_Imap_Client_Data_SearchCharset_Utf8();
34 | $s->setValid('ISO-8859-1', false);
35 |
36 | $this->assertTrue($s->query('UTF-8', true));
37 | $this->assertTrue($s->query('US-ASCII', true));
38 | $this->assertFalse($s->query('iso-8859-1', true));
39 | }
40 |
41 | public function testRemoval()
42 | {
43 | $s = new Horde_Imap_Client_Data_SearchCharset_Utf8();
44 | $s->setValid('UTF-8');
45 |
46 | $this->assertTrue($s->query('UTF-8', true));
47 |
48 | $s->setValid('utf-8', false);
49 |
50 | $this->assertTrue($s->query('UTF-8', true));
51 | }
52 |
53 | public function testCharsetsProperty()
54 | {
55 | $s = new Horde_Imap_Client_Data_SearchCharset_Utf8();
56 | $s->setValid('UTF-8');
57 | $s->setValid('UTF-8');
58 |
59 | $this->assertEquals(
60 | array('US-ASCII', 'UTF-8'),
61 | $s->charsets
62 | );
63 | }
64 |
65 | public function testObserver()
66 | {
67 | $s = new Horde_Imap_Client_Data_SearchCharset_Utf8();
68 |
69 | $mock = $this->getMockBuilder('SplObserver')
70 | ->getMock();
71 | $mock->expects($this->never())
72 | ->method('update')
73 | ->with($this->equalTo($s));
74 | $s->attach($mock);
75 |
76 | $s->setValid('utf-8');
77 | /* This should be ignored. */
78 | $s->setValid('UTF-8');
79 | }
80 |
81 | public function testSerialize()
82 | {
83 | $s = new Horde_Imap_Client_Data_SearchCharset_Utf8();
84 |
85 | $s_copy = unserialize(serialize($s));
86 |
87 | $s_copy->query('UTF-8', true);
88 |
89 | $this->markTestIncomplete();
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/lib/Horde/Imap/Client/Data/Format/Mailbox.php:
--------------------------------------------------------------------------------
1 |
18 | * @category Horde
19 | * @copyright 2012-2017 Horde LLC
20 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
21 | * @package Imap_Client
22 | */
23 | class Horde_Imap_Client_Data_Format_Mailbox
24 | extends Horde_Imap_Client_Data_Format_Astring
25 | {
26 | /**
27 | * Mailbox encoding.
28 | *
29 | * @var string
30 | */
31 | protected $_encoding = 'utf7imap';
32 |
33 | /**
34 | * Mailbox object.
35 | *
36 | * @var Horde_Imap_Client_Mailbox
37 | */
38 | protected $_mailbox;
39 |
40 | /**
41 | * @param mixed $data Either a mailbox object or a UTF-8 mailbox name.
42 | */
43 | public function __construct($data)
44 | {
45 | $this->_mailbox = Horde_Imap_Client_Mailbox::get($data);
46 |
47 | parent::__construct($this->_mailbox->{$this->_encoding});
48 | }
49 |
50 | /**
51 | */
52 | public function __toString()
53 | {
54 | return strval($this->_mailbox);
55 | }
56 |
57 | /**
58 | */
59 | public function getData()
60 | {
61 | return $this->_mailbox;
62 | }
63 |
64 | /**
65 | * @throws Horde_Imap_Client_Exception
66 | */
67 | public function binary()
68 | {
69 | if (parent::binary()) {
70 | // Mailbox data can NEVER be sent as binary.
71 | /* @todo: Disable until Horde_Imap_Client 3.0 */
72 | // throw new Horde_Imap_Client_Exception(
73 | // 'Client error: can not send mailbox to IMAP server as binary data.'
74 | // );
75 |
76 | // Temporary fix: send a blank mailbox string.
77 | $this->_mailbox = Horde_Imap_Client_Mailbox::get('');
78 | }
79 |
80 | return false;
81 | }
82 |
83 | /**
84 | */
85 | public function length()
86 | {
87 | return strlen($this->_mailbox->{$this->_encoding});
88 | }
89 |
90 | /**
91 | */
92 | public function getStream()
93 | {
94 | $stream = new Horde_Stream_Temp();
95 | $stream->add($this->_mailbox->{$this->_encoding});
96 | return $stream;
97 | }
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Interaction/CommandTest.php:
--------------------------------------------------------------------------------
1 |
25 | * @category Horde
26 | * @copyright 2014-2016 Horde LLC
27 | * @ignore
28 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
29 | * @package Imap_Client
30 | * @subpackage UnitTests
31 | */
32 | class CommandTest extends TestCase
33 | {
34 | /**
35 | * @dataProvider continuationCheckProvider
36 | */
37 | public function testContinuationCheck($command, $result)
38 | {
39 | $this->assertEquals(
40 | $result,
41 | $command->continuation
42 | );
43 | }
44 |
45 | public function continuationCheckProvider()
46 | {
47 | $out = array();
48 |
49 | $cmd = new Horde_Imap_Client_Interaction_Command('FOO', '1');
50 | $cmd->add(array(
51 | 'FOO',
52 | 'BAR'
53 | ));
54 |
55 | $out[] = array($cmd, false);
56 |
57 | $cmd = clone $cmd;
58 | $cmd->add(
59 | new Horde_Imap_Client_Interaction_Command_Continuation(function() {})
60 | );
61 |
62 | $out[] = array($cmd, true);
63 |
64 | $cmd = new Horde_Imap_Client_Interaction_Command('FOO', '1');
65 | $cmd->add(array(
66 | 'FOO',
67 | array(
68 | 'BAR'
69 | ),
70 | new Horde_Imap_Client_Data_Format_List(array(
71 | 'BAR'
72 | ))
73 | ));
74 |
75 | $out[] = array($cmd, false);
76 |
77 | $cmd = new Horde_Imap_Client_Interaction_Command('FOO', '1');
78 | $cmd->add(array(
79 | 'FOO',
80 | array(
81 | 'BAR',
82 | array(
83 | 'BAZ',
84 | array(
85 | new Horde_Imap_Client_Data_Format_String_Nonascii('Envoyé')
86 | )
87 | )
88 | )
89 | ));
90 |
91 | $out[] = array($cmd, true);
92 |
93 | return $out;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/lib/Horde/Imap/Client/Base/Alerts.php:
--------------------------------------------------------------------------------
1 |
18 | * @category Horde
19 | * @copyright 2014-2017 Horde LLC
20 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
21 | * @package Imap_Client
22 | * @since 2.24.0
23 | */
24 | class Horde_Imap_Client_Base_Alerts
25 | implements SplSubject
26 | {
27 | /**
28 | * Alert data.
29 | *
30 | * @var object
31 | */
32 | protected $_alert;
33 |
34 | /**
35 | * Observers.
36 | *
37 | * @var array
38 | */
39 | protected $_observers = array();
40 |
41 | /**
42 | * Add an alert.
43 | *
44 | * @param string $alert The alert string.
45 | * @param string $type The alert type.
46 | */
47 | public function add($alert, $type = null)
48 | {
49 | $this->_alert = new stdClass;
50 | $this->_alert->alert = $alert;
51 | if (!is_null($type)) {
52 | $this->_alert->type = $type;
53 | }
54 |
55 | $this->notify();
56 | }
57 |
58 | /**
59 | * Returns the last alert received.
60 | *
61 | * @return object Alert information. Object with these properties:
62 | *
63 | * - alert: (string) Alert string.
64 | * - type: (string) [OPTIONAL] Alert type.
65 | *
66 | */
67 | public function getLast()
68 | {
69 | return $this->_alert;
70 | }
71 |
72 | /* SplSubject methods. */
73 |
74 | /**
75 | */
76 | #[ReturnTypeWillChange]
77 | public function attach(SplObserver $observer)
78 | {
79 | $this->detach($observer);
80 | $this->_observers[] = $observer;
81 | }
82 |
83 | /**
84 | */
85 | #[ReturnTypeWillChange]
86 | public function detach(SplObserver $observer)
87 | {
88 | if (($key = array_search($observer, $this->_observers, true)) !== false) {
89 | unset($this->_observers[$key]);
90 | }
91 | }
92 |
93 | /**
94 | * Notification is triggered internally whenever the object's internal
95 | * data storage is altered.
96 | */
97 | #[ReturnTypeWillChange]
98 | public function notify()
99 | {
100 | foreach ($this->_observers as $val) {
101 | $val->update($this);
102 | }
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/Format/NstringTest.php:
--------------------------------------------------------------------------------
1 |
21 | * @category Horde
22 | * @copyright 2011-2016 Horde LLC
23 | * @ignore
24 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
25 | * @package Imap_Client
26 | * @subpackage UnitTests
27 | */
28 | class NstringTest extends TestBase
29 | {
30 | protected $cname = 'Horde_Imap_Client_Data_Format_Nstring';
31 |
32 | protected function getTestObs()
33 | {
34 | return array(
35 | new $this->cname('Foo'),
36 | new $this->cname('Foo('),
37 | /* This is an invalid atom, but valid nstring. */
38 | new $this->cname('Foo]'),
39 | new $this->cname()
40 | );
41 | }
42 |
43 | public function stringRepresentationProvider()
44 | {
45 | return $this->createProviderArray(array(
46 | 'Foo',
47 | 'Foo(',
48 | 'Foo]',
49 | ''
50 | ));
51 | }
52 |
53 | public function escapeProvider()
54 | {
55 | return $this->createProviderArray(array(
56 | '"Foo"',
57 | '"Foo("',
58 | '"Foo]"',
59 | 'NIL'
60 | ));
61 | }
62 |
63 | public function verifyProvider()
64 | {
65 | return $this->createProviderArray(array(
66 | true,
67 | true,
68 | true,
69 | true
70 | ));
71 | }
72 |
73 | public function binaryProvider()
74 | {
75 | return $this->createProviderArray(array(
76 | false,
77 | false,
78 | false,
79 | false
80 | ));
81 | }
82 |
83 | public function literalProvider()
84 | {
85 | return $this->binaryProvider();
86 | }
87 |
88 | public function quotedProvider()
89 | {
90 | return $this->createProviderArray(array(
91 | true,
92 | true,
93 | true,
94 | false
95 | ));
96 | }
97 |
98 | public function escapeStreamProvider()
99 | {
100 | return $this->escapeProvider();
101 | }
102 |
103 | public function nonasciiInputProvider()
104 | {
105 | return array(
106 | array(false)
107 | );
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/.github/workflows/phpdoc.yml:
--------------------------------------------------------------------------------
1 | # This is a basic workflow to help you get started with Actions
2 |
3 | name: PHPDOC
4 |
5 | # Controls when the action will run.
6 | on:
7 | # Triggers the workflow on push or pull request events but only for the master branch
8 | push:
9 | branches:
10 | - master
11 | - maintaina-composerfixed
12 | - FRAMEWORK_6_0
13 | # Allows you to run this workflow manually from the Actions tab
14 | workflow_dispatch:
15 |
16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
17 | jobs:
18 | run:
19 | runs-on: ubuntu-20.04
20 | steps:
21 | - name: Setup github ssh key
22 | run: mkdir -p ~/.ssh/ && ssh-keyscan -t rsa github.com > ~/.ssh/known_hosts
23 | - name: Setup uut dir
24 | run: |
25 | export REPO=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//")
26 | export UUT_DIR=$(pwd)
27 | export WORK_DIR=~
28 | export BIN_DIR="${WORK_DIR}/bin"
29 | mkdir -p $BIN_DIR
30 | git config --global user.name "PHPDOC CI Job"
31 | git config --global user.email "ci-job@maintaina.com"
32 | - name: Checkout
33 | uses: actions/checkout@v2
34 | - name: Checkout Doc Dir
35 | uses: actions/checkout@v2
36 | with:
37 | repository: maintaina/phpdoc
38 | token: ${{secrets.PHPDOC_TOKEN}}
39 | path: "phpdoc-git"
40 | - name: Setup PHP
41 | uses: shivammathur/setup-php@v2
42 | with:
43 | php-version: 7.4
44 | extensions: bcmath, ctype, curl, dom, gd, gettext, iconv, imagick, json, ldap, mbstring, mysql, opcache, openssl, pcntl, pdo, posix, redis, soap, sockets, sqlite, tokenizer, xmlwriter
45 | ini-values: post_max_size=512M, max_execution_time=360
46 | coverage: xdebug
47 | tools: composer:v2
48 | - name: Setup Github Token as composer credential
49 | run: composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
50 | - name: phpdocumentor run
51 | run: |
52 | export UUT_DIR=$(pwd)
53 | export REPO=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//")
54 | export WORK_DIR=/home/runner/
55 | export BIN_DIR="${WORK_DIR}/bin"
56 | wget https://phpdoc.org/phpDocumentor.phar
57 | mkdir "${WORK_DIR}/phpdoc-out"
58 | mv phpDocumentor.phar $BIN_DIR/phpdocumentor
59 | chmod +x "${BIN_DIR}/phpdocumentor"
60 | echo "Creating UUT related dir in docu repo"
61 | mkdir -p $UUT_DIR/phpdoc-git/${GITHUB_REF##*/}/${REPO}/
62 | ## Look into any of lib, src, app (if they exist) but not test, migration, bin, locale or script dirs
63 | $BIN_DIR/phpdocumentor -d $UUT_DIR/lib/ -d $UUT_DIR/src/ -d $UUT_DIR/app/ -t "${UUT_DIR}/phpdoc-git/${GITHUB_REF##*/}/${REPO}/"
64 | cd ${UUT_DIR}/phpdoc-git
65 | git add "${GITHUB_REF##*/}/${REPO}"
66 | php indexer.php ${GITHUB_REF##*/} $REPO
67 | git add index.html index.json
68 | git commit -m "Updated phpdoc for $GITHUB_REPOSITORY (${GITHUB_REF##*/} branch) from ci"
69 | git push
70 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/Format/AstringTest.php:
--------------------------------------------------------------------------------
1 |
21 | * @category Horde
22 | * @copyright 2011-2016 Horde LLC
23 | * @ignore
24 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
25 | * @package Imap_Client
26 | * @subpackage UnitTests
27 | */
28 | class AstringTest extends TestBase
29 | {
30 | protected $cname = 'Horde_Imap_Client_Data_Format_Astring';
31 |
32 | protected function getTestObs()
33 | {
34 | return array(
35 | new $this->cname('Foo'),
36 | new $this->cname('Foo('),
37 | /* This is an invalid atom, but valid (non-quoted) astring. */
38 | new $this->cname('Foo]'),
39 | new $this->cname('')
40 | );
41 | }
42 |
43 | public function stringRepresentationProvider()
44 | {
45 | return $this->createProviderArray(array(
46 | 'Foo',
47 | 'Foo(',
48 | 'Foo]',
49 | ''
50 | ));
51 | }
52 |
53 | public function escapeProvider()
54 | {
55 | return $this->createProviderArray(array(
56 | 'Foo',
57 | '"Foo("',
58 | 'Foo]',
59 | '""'
60 | ));
61 | }
62 |
63 | public function verifyProvider()
64 | {
65 | return $this->createProviderArray(array(
66 | true,
67 | true,
68 | true,
69 | true
70 | ));
71 | }
72 |
73 | public function binaryProvider()
74 | {
75 | return $this->createProviderArray(array(
76 | false,
77 | false,
78 | false,
79 | false
80 | ));
81 | }
82 |
83 | public function literalProvider()
84 | {
85 | return $this->binaryProvider();
86 | }
87 |
88 | public function quotedProvider()
89 | {
90 | return $this->createProviderArray(array(
91 | false,
92 | true,
93 | false,
94 | true
95 | ));
96 | }
97 |
98 | public function escapeStreamProvider()
99 | {
100 | return $this->createProviderArray(array(
101 | '"Foo"',
102 | '"Foo("',
103 | '"Foo]"',
104 | '""'
105 | ));
106 | }
107 |
108 | public function nonasciiInputProvider()
109 | {
110 | return array(
111 | array(false)
112 | );
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/lib/Horde/Imap/Client/Socket/Connection/Pop3.php:
--------------------------------------------------------------------------------
1 |
22 | * @category Horde
23 | * @copyright 2013-2017 Horde LLC
24 | * @internal
25 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26 | * @package Imap_Client
27 | */
28 | class Horde_Imap_Client_Socket_Connection_Pop3
29 | extends Horde_Imap_Client_Socket_Connection_Base
30 | {
31 | /**
32 | */
33 | protected $_protocol = 'pop3';
34 |
35 | /**
36 | * Writes data to the POP3 output stream.
37 | *
38 | * @param string $data String data.
39 | * @param boolean $debug Output line to debug?
40 | *
41 | * @throws Horde_Imap_Client_Exception
42 | */
43 | public function write($data, $debug = true)
44 | {
45 | if (fwrite($this->_stream, $data . "\r\n") === false) {
46 | throw new Horde_Imap_Client_Exception(
47 | Horde_Imap_Client_Translation::r("Server write error."),
48 | Horde_Imap_Client_Exception::SERVER_WRITEERROR
49 | );
50 | }
51 |
52 | if ($debug) {
53 | $this->_params['debug']->client($data);
54 | }
55 | }
56 |
57 | /**
58 | * Read data from incoming POP3 stream.
59 | *
60 | * @param integer $size UNUSED: The number of bytes to read from the
61 | * socket.
62 | *
63 | * @return string Line of data.
64 | *
65 | * @throws Horde_Imap_Client_Exception
66 | */
67 | public function read($size = null)
68 | {
69 | if (feof($this->_stream)) {
70 | $this->close();
71 | $this->_params['debug']->info(
72 | 'ERROR: Server closed the connection.'
73 | );
74 | throw new Horde_Imap_Client_Exception(
75 | Horde_Imap_Client_Translation::r("Server closed the connection unexpectedly."),
76 | Horde_Imap_Client_Exception::DISCONNECT
77 | );
78 | }
79 |
80 | if (($read = fgets($this->_stream)) === false) {
81 | $this->_params['debug']->info('ERROR: read/timeout error.');
82 | throw new Horde_Imap_Client_Exception(
83 | Horde_Imap_Client_Translation::r("Error when communicating with the mail server."),
84 | Horde_Imap_Client_Exception::SERVER_READERROR
85 | );
86 | }
87 |
88 | $this->_params['debug']->server(rtrim($read, "\r\n"));
89 |
90 | return $read;
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/SearchCharsetTest.php:
--------------------------------------------------------------------------------
1 |
22 | * @category Horde
23 | * @copyright 2014-2016 Horde LLC
24 | * @ignore
25 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26 | * @package Imap_Client
27 | * @subpackage UnitTests
28 | */
29 | class SearchCharsetTest extends TestCase
30 | {
31 | public function testQuery()
32 | {
33 | $s = new Horde_Imap_Client_Data_SearchCharset();
34 | $s->setValid('ISO-8859-1', false);
35 |
36 | $this->assertNull($s->query('UTF-8', true));
37 | $this->assertTrue($s->query('US-ASCII', true));
38 | $this->assertFalse($s->query('iso-8859-1', true));
39 | }
40 |
41 | /**
42 | * @expectedException RuntimeException
43 | */
44 | public function testQueryWithoutBaseOb()
45 | {
46 | $this->expectException('RuntimeException');
47 |
48 | $s = new Horde_Imap_Client_Data_SearchCharset();
49 |
50 | $s->query('UTF-8');
51 | }
52 |
53 | public function testRemoval()
54 | {
55 | $s = new Horde_Imap_Client_Data_SearchCharset();
56 | $s->setValid('UTF-8');
57 |
58 | $this->assertTrue($s->query('UTF-8', true));
59 |
60 | $s->setValid('utf-8', false);
61 |
62 | $this->assertFalse($s->query('UTF-8', true));
63 | }
64 |
65 | public function testCharsetsProperty()
66 | {
67 | $s = new Horde_Imap_Client_Data_SearchCharset();
68 | $s->setValid('UTF-8');
69 | $s->setValid('UTF-8');
70 |
71 | $this->assertEquals(
72 | array('US-ASCII', 'UTF-8'),
73 | $s->charsets
74 | );
75 | }
76 |
77 | public function testObserver()
78 | {
79 | $s = new Horde_Imap_Client_Data_SearchCharset();
80 |
81 | $mock = $this->getMockBuilder('SplObserver')
82 | ->getMock();
83 | $mock->expects($this->once())
84 | ->method('update')
85 | ->with($this->equalTo($s));
86 | $s->attach($mock);
87 |
88 | $s->setValid('utf-8');
89 | /* This should be ignored. */
90 | $s->setValid('UTF-8');
91 | }
92 |
93 | public function testSerialize()
94 | {
95 | $s = new Horde_Imap_Client_Data_SearchCharset();
96 | $s->setValid('utf-8');
97 |
98 | $s_copy = unserialize(serialize($s));
99 |
100 | $s_copy->query('UTF-8', true);
101 |
102 | $this->markTestIncomplete();
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/migration/Horde/Imap/Client/1_horde_imap_client_base_tables.php:
--------------------------------------------------------------------------------
1 |
18 | * @category Horde
19 | * @copyright 2013-2017 Horde LLC
20 | * @ignore
21 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
22 | * @package Imap_Client
23 | */
24 | class HordeImapClientBaseTables extends Horde_Db_Migration_Base
25 | {
26 | public function up()
27 | {
28 | if (in_array('horde_imap_client_data', $this->tables())) {
29 | return;
30 | }
31 |
32 | $t = $this->createTable('horde_imap_client_data', array(
33 | 'autoincrementKey' => 'messageid'
34 | ));
35 | $t->column('hostspec', 'string', array(
36 | 'limit' => 255,
37 | 'null' => false
38 | ));
39 | $t->column('mailbox', 'string', array(
40 | 'limit' => 255,
41 | 'null' => false
42 | ));
43 | $t->column('modified', 'bigint');
44 | $t->column('port', 'integer', array(
45 | 'null' => false
46 | ));
47 | $t->column('username', 'string', array(
48 | 'limit' => 255,
49 | 'null' => false
50 | ));
51 | $t->end();
52 |
53 | $this->addIndex(
54 | 'horde_imap_client_data',
55 | array('hostspec', 'mailbox', 'port', 'username')
56 | );
57 |
58 | $t = $this->createTable('horde_imap_client_message', array(
59 | 'autoincrementKey' => false
60 | ));
61 | $t->column('data', 'binary');
62 | $t->column('msguid', 'string', array(
63 | 'null' => false
64 | ));
65 | $t->column('messageid', 'bigint', array(
66 | 'null' => false
67 | ));
68 | $t->end();
69 |
70 | $this->addIndex(
71 | 'horde_imap_client_message',
72 | array('msguid', 'messageid')
73 | );
74 |
75 | $t = $this->createTable('horde_imap_client_metadata', array(
76 | 'autoincrementKey' => false
77 | ));
78 | $t->column('data', 'binary');
79 | $t->column('field', 'string', array(
80 | 'null' => false
81 | ));
82 | $t->column('messageid', 'bigint', array(
83 | 'null' => false
84 | ));
85 | $t->end();
86 |
87 | $this->addIndex(
88 | 'horde_imap_client_metadata',
89 | array('messageid')
90 | );
91 | }
92 |
93 | public function down()
94 | {
95 | $this->dropTable('horde_imap_client_data');
96 | $this->dropTable('horde_imap_client_message');
97 | $this->dropTable('horde_imap_client_metadata');
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Stub/Socket.php:
--------------------------------------------------------------------------------
1 |
25 | * @category Horde
26 | * @copyright 2011-2016 Horde LLC
27 | * @ignore
28 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
29 | * @package Imap_Client
30 | * @subpackage UnitTests
31 | */
32 | class Socket extends Horde_Imap_Client_Socket
33 | {
34 | public $fetch_results;
35 |
36 | public function getThreadSort($data)
37 | {
38 | return new Horde_Imap_Client_Data_Thread($this->doServerResponse($this->_pipeline(), $data)->data['threadparse'], 'uid');
39 | }
40 |
41 | public function parseNamespace($data)
42 | {
43 | return $this->doServerResponse($this->_pipeline(), $data)->data['namespace'];
44 | }
45 |
46 | public function parseACL($data)
47 | {
48 | return $this->doServerResponse($this->_pipeline(), $data)->data['getacl'];
49 | }
50 |
51 | public function parseMyACLRights($data)
52 | {
53 | return $this->doServerResponse($this->_pipeline(), $data)->data['myrights'];
54 | }
55 |
56 | public function parseListRights($data)
57 | {
58 | return $this->doServerResponse($this->_pipeline(), $data)->data['listaclrights'];
59 | }
60 |
61 | /**
62 | * @param array $data Options:
63 | * - results: (Horde_Imap_Client_Fetch_Results)
64 | */
65 | public function parseFetch($data, array $opts = array())
66 | {
67 | $pipeline = $this->_pipeline();
68 | if (isset($opts['results'])) {
69 | $pipeline->fetch = $opts['results'];
70 | }
71 | $pipeline->data['modseqs_nouid'] = array();
72 |
73 | return $this->doServerResponse($pipeline, $data);
74 | }
75 |
76 | public function doServerResponse($pipeline, $data)
77 | {
78 | $server = Horde_Imap_Client_Interaction_Server::create(
79 | new Horde_Imap_Client_Tokenize($data)
80 | );
81 | $this->_serverResponse($pipeline, $server);
82 | return $pipeline;
83 | }
84 |
85 | public function doResponseCode($data)
86 | {
87 | $server = Horde_Imap_Client_Interaction_Server::create(
88 | new Horde_Imap_Client_Tokenize($data)
89 | );
90 | $this->_responseCode($this->_pipeline(), $server);
91 | }
92 |
93 | public function pipeline($cmd = null)
94 | {
95 | return $this->_pipeline($cmd);
96 | }
97 |
98 | public function fetch($mailbox, $query, array $options = array())
99 | {
100 | return $this->fetch_results;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/Format/StringTest.php:
--------------------------------------------------------------------------------
1 |
21 | * @category Horde
22 | * @copyright 2011-2016 Horde LLC
23 | * @ignore
24 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
25 | * @package Imap_Client
26 | * @subpackage UnitTests
27 | */
28 | class StringTest extends TestBase
29 | {
30 | protected $cname = 'Horde_Imap_Client_Data_Format_String';
31 |
32 | protected function getTestObs()
33 | {
34 | return array(
35 | new $this->cname('Foo'),
36 | new $this->cname('Foo('),
37 | /* This is an invalid atom, but valid string. */
38 | new $this->cname('Foo]'),
39 | /* This string requires a literal. */
40 | new $this->cname("Foo\n]"),
41 | /* This string requires a binary literal. */
42 | new $this->cname("12\x00\n3")
43 | );
44 | }
45 |
46 | public function stringRepresentationProvider()
47 | {
48 | return $this->createProviderArray(array(
49 | 'Foo',
50 | 'Foo(',
51 | 'Foo]',
52 | "Foo\n]",
53 | "12\x00\n3"
54 | ));
55 | }
56 |
57 | public function escapeProvider()
58 | {
59 | return $this->createProviderArray(array(
60 | '"Foo"',
61 | '"Foo("',
62 | '"Foo]"',
63 | false,
64 | false
65 | ));
66 | }
67 |
68 | public function verifyProvider()
69 | {
70 | return $this->createProviderArray(array(
71 | true,
72 | true,
73 | true,
74 | true,
75 | true
76 | ));
77 | }
78 |
79 | public function binaryProvider()
80 | {
81 | return $this->createProviderArray(array(
82 | false,
83 | false,
84 | false,
85 | false,
86 | true
87 | ));
88 | }
89 |
90 | public function literalProvider()
91 | {
92 | return $this->createProviderArray(array(
93 | false,
94 | false,
95 | false,
96 | true,
97 | true
98 | ));
99 | }
100 |
101 | public function quotedProvider()
102 | {
103 | return $this->createProviderArray(array(
104 | true,
105 | true,
106 | true,
107 | false,
108 | false
109 | ));
110 | }
111 |
112 | public function escapeStreamProvider()
113 | {
114 | return $this->escapeProvider();
115 | }
116 |
117 | public function nonasciiInputProvider()
118 | {
119 | return array(
120 | array(false)
121 | );
122 | }
123 |
124 | }
125 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/Format/Mailbox/MailboxUtf8Test.php:
--------------------------------------------------------------------------------
1 |
20 | * @category Horde
21 | * @copyright 2014-2016 Horde LLC
22 | * @ignore
23 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
24 | * @package Imap_Client
25 | * @subpackage UnitTests
26 | */
27 | class MailboxUtf8Test extends TestBase
28 | {
29 | protected $cname = 'Horde_Imap_Client_Data_Format_Mailbox_Utf8';
30 |
31 | public function stringRepresentationProvider()
32 | {
33 | return array(
34 | array('Foo', 'Foo'),
35 | array('Foo(', 'Foo('),
36 | array('Foo%Bar', 'Foo%Bar'),
37 | array('Foo*Bar', 'Foo*Bar'),
38 | array('Envoyé', 'Envoyé')
39 | );
40 | }
41 |
42 | public function escapeProvider()
43 | {
44 | return array(
45 | array('Foo', 'Foo'),
46 | array('Foo(', '"Foo("'),
47 | array('Foo%Bar', '"Foo%Bar"'),
48 | array('Foo*Bar', '"Foo*Bar"'),
49 | array('Envoyé', '"Envoyé"')
50 | );
51 | }
52 |
53 | public function verifyProvider()
54 | {
55 | return array(
56 | array('Foo', false),
57 | array('Foo(', false),
58 | array('Foo%Bar', false),
59 | array('Foo*Bar', false),
60 | array('Envoyé', false)
61 | );
62 | }
63 |
64 | public function binaryProvider()
65 | {
66 | return array(
67 | array('Foo', false),
68 | array('Foo(', false),
69 | array('Foo%Bar', false),
70 | array('Foo*Bar', false),
71 | array('Envoyé', false)
72 | );
73 | }
74 |
75 | public function literalProvider()
76 | {
77 | return array(
78 | array('Foo', false),
79 | array('Foo(', false),
80 | array('Foo%Bar', false),
81 | array('Foo*Bar', false),
82 | array('Envoyé', false)
83 | );
84 | }
85 |
86 | public function quotedProvider()
87 | {
88 | return array(
89 | array('Foo', false),
90 | array('Foo(', true),
91 | array('Foo%Bar', true),
92 | array('Foo*Bar', true),
93 | array('Envoyé', true)
94 | );
95 | }
96 |
97 | public function escapeStreamProvider()
98 | {
99 | return array(
100 | array('Foo', '"Foo"'),
101 | array('Foo(', '"Foo("'),
102 | array('Foo%Bar', '"Foo%Bar"'),
103 | array('Foo*Bar', '"Foo*Bar"'),
104 | array('Envoyé', '"Envoyé"')
105 | );
106 | }
107 |
108 | public function testBadInput()
109 | {
110 | $this->expectException('Horde_Imap_Client_Data_Format_Exception');
111 |
112 | new $this->cname("foo\1");
113 | }
114 |
115 | }
116 |
--------------------------------------------------------------------------------
/lib/Horde/Imap/Client/Data/Format/List.php:
--------------------------------------------------------------------------------
1 |
18 | * @category Horde
19 | * @copyright 2012-2017 Horde LLC
20 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
21 | * @package Imap_Client
22 | */
23 | class Horde_Imap_Client_Data_Format_List extends Horde_Imap_Client_Data_Format implements Countable, IteratorAggregate
24 | {
25 | /**
26 | * @see add()
27 | */
28 | public function __construct($data = null)
29 | {
30 | parent::__construct(array());
31 |
32 | if (!is_null($data)) {
33 | $this->add($data);
34 | }
35 | }
36 |
37 | /**
38 | * Add an element to the list.
39 | *
40 | * @param mixed $data The data element(s) to add. Either a
41 | * Horde_Imap_Client_Data_Format object, a string
42 | * value that will be treated as an IMAP atom, or
43 | * an array (or iterable object) of objects to add.
44 | * @param boolean $merge Merge the contents of any container objects,
45 | * instead of adding the objects themselves?
46 | *
47 | * @return Horde_Imap_Client_Data_Format_List This object to allow for
48 | * chainable calls (since
49 | * 2.10.0).
50 | */
51 | public function add($data, $merge = false)
52 | {
53 | if (is_array($data) || ($merge && ($data instanceof Traversable))) {
54 | foreach ($data as $val) {
55 | $this->add($val);
56 | }
57 | } elseif (is_object($data)) {
58 | $this->_data[] = $data;
59 | } elseif (!is_null($data)) {
60 | $this->_data[] = new Horde_Imap_Client_Data_Format_Atom($data);
61 | }
62 |
63 | return $this;
64 | }
65 |
66 | /**
67 | */
68 | public function __toString()
69 | {
70 | $out = '';
71 |
72 | foreach ($this as $val) {
73 | if ($val instanceof $this) {
74 | $out .= '(' . $val->escape() . ') ';
75 | } elseif (($val instanceof Horde_Imap_Client_Data_Format_String) &&
76 | $val->literal()) {
77 | /* ERROR: Requires literal output. */
78 | return '';
79 | } else {
80 | $out .= $val->escape() . ' ';
81 | }
82 | }
83 |
84 | return rtrim($out);
85 | }
86 |
87 | /* Countable methods. */
88 |
89 | /**
90 | */
91 | #[ReturnTypeWillChange]
92 | public function count()
93 | {
94 | return count($this->_data);
95 | }
96 |
97 | /* IteratorAggregate method. */
98 |
99 | /**
100 | * Iterator loops through the data elements contained in this list.
101 | */
102 | #[ReturnTypeWillChange]
103 | public function getIterator()
104 | {
105 | return new ArrayIterator($this->_data);
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/Format/Mailbox/ListMailboxTest.php:
--------------------------------------------------------------------------------
1 |
20 | * @category Horde
21 | * @copyright 2011-2016 Horde LLC
22 | * @ignore
23 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
24 | * @package Imap_Client
25 | * @subpackage UnitTests
26 | */
27 | class ListMailboxTest extends TestBase
28 | {
29 | protected $cname = 'Horde_Imap_Client_Data_Format_ListMailbox';
30 |
31 | public function stringRepresentationProvider()
32 | {
33 | return array(
34 | array('Foo', 'Foo'),
35 | array('Foo(', 'Foo('),
36 | array('Foo]', 'Foo]'),
37 | array('Foo%Bar', 'Foo%Bar'),
38 | array('Foo*Bar', 'Foo*Bar'),
39 | array('Envoyé', 'Envoyé')
40 | );
41 | }
42 |
43 | public function escapeProvider()
44 | {
45 | return array(
46 | array('Foo', 'Foo'),
47 | array('Foo(', '"Foo("'),
48 | array('Foo]', 'Foo]'),
49 | /* Don't escape '%'. */
50 | array('Foo%Bar', 'Foo%Bar'),
51 | /* Don't escape '*'. */
52 | array('Foo*Bar', 'Foo*Bar'),
53 | array('Envoyé', 'Envoy&AOk-')
54 | );
55 | }
56 |
57 | public function verifyProvider()
58 | {
59 | return array(
60 | array('Foo', false),
61 | array('Foo(', false),
62 | array('Foo]', false),
63 | array('Foo%Bar', false),
64 | array('Foo*Bar', false),
65 | array('Envoyé', false)
66 | );
67 | }
68 |
69 | public function binaryProvider()
70 | {
71 | return array(
72 | array('Foo', false),
73 | array('Foo(', false),
74 | array('Foo]', false),
75 | array('Foo%Bar', false),
76 | array('Foo*Bar', false),
77 | array('Envoyé', false)
78 | );
79 | }
80 |
81 | public function literalProvider()
82 | {
83 | return array(
84 | array('Foo', false),
85 | array('Foo(', false),
86 | array('Foo]', false),
87 | array('Foo%Bar', false),
88 | array('Foo*Bar', false),
89 | array('Envoyé', false)
90 | );
91 | }
92 |
93 | public function quotedProvider()
94 | {
95 | return array(
96 | array('Foo', false),
97 | array('Foo(', true),
98 | array('Foo]', false),
99 | array('Foo%Bar', false),
100 | array('Foo*Bar', false),
101 | array('Envoyé', false)
102 | );
103 | }
104 |
105 | public function escapeStreamProvider()
106 | {
107 | return array(
108 | array('Foo', '"Foo"'),
109 | array('Foo(', '"Foo("'),
110 | array('Foo]', '"Foo]"'),
111 | array('Foo%Bar', '"Foo%Bar"'),
112 | array('Foo*Bar', '"Foo*Bar"'),
113 | array('Envoyé', '"Envoy&AOk-"')
114 | );
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/Format/Mailbox/ListMailboxUtf8Test.php:
--------------------------------------------------------------------------------
1 |
20 | * @category Horde
21 | * @copyright 2014-2016 Horde LLC
22 | * @ignore
23 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
24 | * @package Imap_Client
25 | * @subpackage UnitTests
26 | */
27 | class ListMailboxUtf8Test extends TestBase
28 | {
29 | protected $cname = 'Horde_Imap_Client_Data_Format_ListMailbox_Utf8';
30 |
31 | public function stringRepresentationProvider()
32 | {
33 | return array(
34 | array('Foo', 'Foo'),
35 | array('Foo(', 'Foo('),
36 | array('Foo]', 'Foo]'),
37 | array('Foo%Bar', 'Foo%Bar'),
38 | array('Foo*Bar', 'Foo*Bar'),
39 | array('Envoyé', 'Envoyé')
40 | );
41 | }
42 |
43 | public function escapeProvider()
44 | {
45 | return array(
46 | array('Foo', 'Foo'),
47 | array('Foo(', '"Foo("'),
48 | array('Foo]', 'Foo]'),
49 | /* Don't escape '%'. */
50 | array('Foo%Bar', 'Foo%Bar'),
51 | /* Don't escape '*'. */
52 | array('Foo*Bar', 'Foo*Bar'),
53 | array('Envoyé', '"Envoyé"')
54 | );
55 | }
56 |
57 | public function verifyProvider()
58 | {
59 | return array(
60 | array('Foo', false),
61 | array('Foo(', false),
62 | array('Foo]', false),
63 | array('Foo%Bar', false),
64 | array('Foo*Bar', false),
65 | array('Envoyé', false)
66 | );
67 | }
68 |
69 | public function binaryProvider()
70 | {
71 | return array(
72 | array('Foo', false),
73 | array('Foo(', false),
74 | array('Foo]', false),
75 | array('Foo%Bar', false),
76 | array('Foo*Bar', false),
77 | array('Envoyé', false)
78 | );
79 | }
80 |
81 | public function literalProvider()
82 | {
83 | return array(
84 | array('Foo', false),
85 | array('Foo(', false),
86 | array('Foo]', false),
87 | array('Foo%Bar', false),
88 | array('Foo*Bar', false),
89 | array('Envoyé', false)
90 | );
91 | }
92 |
93 | public function quotedProvider()
94 | {
95 | return array(
96 | array('Foo', false),
97 | array('Foo(', true),
98 | array('Foo]', false),
99 | array('Foo%Bar', false),
100 | array('Foo*Bar', false),
101 | array('Envoyé', true)
102 | );
103 | }
104 |
105 | public function escapeStreamProvider()
106 | {
107 | return array(
108 | array('Foo', '"Foo"'),
109 | array('Foo(', '"Foo("'),
110 | array('Foo]', '"Foo]"'),
111 | array('Foo%Bar', '"Foo%Bar"'),
112 | array('Foo*Bar', '"Foo*Bar"'),
113 | array('Envoyé', '"Envoyé"')
114 | );
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Live/Pop3.php:
--------------------------------------------------------------------------------
1 |
20 | * @category Horde
21 | * @copyright 2013-2016 Horde LLC
22 | * @ignore
23 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
24 | * @package Imap_Client
25 | * @subpackage UnitTests
26 | */
27 | class Pop3 extends Base
28 | {
29 | public static $config;
30 |
31 | public static function setUpBeforeClass()
32 | {
33 | $c = array_shift(self::$config);
34 |
35 | try {
36 | $c['client_config']['cache'] = array(
37 | 'cacheob' => new Horde_Cache(
38 | new Horde_Cache_Storage_Mock(),
39 | array('compress' => true)
40 | )
41 | );
42 | } catch (Exception $e) {}
43 |
44 | self::$live = new Horde_Imap_Client_Socket_Pop3(
45 | $c['client_config']
46 | );
47 | }
48 |
49 | /* Tests */
50 |
51 | public function testPreLoginCommands()
52 | {
53 | $c = self::$live->capability;
54 |
55 | $this->assertInstanceOf(
56 | 'Horde_Imap_Client_Data_Capability',
57 | $c
58 | );
59 | }
60 |
61 | /**
62 | * @depends testPreLoginCommands
63 | */
64 | public function testLogin()
65 | {
66 | /* Throws exception on error, which will prevent all further testing
67 | * on this server. */
68 | self::$live->login();
69 | }
70 |
71 | /**
72 | * @depends testLogin
73 | */
74 | public function testPostLoginCapability()
75 | {
76 | /* Re-use testPreLoginCommands(). */
77 | $this->testPreLoginCommands();
78 | }
79 |
80 | /**
81 | * @depends testLogin
82 | */
83 | public function testOpenMailbox()
84 | {
85 | self::$live->openMailbox('INBOX', Horde_Imap_Client::OPEN_READONLY);
86 | self::$live->openMailbox('INBOX', Horde_Imap_Client::OPEN_READWRITE);
87 | self::$live->openMailbox('INBOX', Horde_Imap_Client::OPEN_AUTO);
88 | }
89 |
90 | /**
91 | * @depends testLogin
92 | */
93 | public function testListMailbox()
94 | {
95 | // Listing all mailboxes (flat format).
96 | $l = self::$live->listMailboxes(
97 | '*',
98 | Horde_Imap_Client::MBOX_ALL,
99 | array('flat' => true)
100 | );
101 |
102 | $this->assertEquals(1, count($l));
103 | }
104 |
105 | /**
106 | * @depends testLogin
107 | */
108 | public function testStatus()
109 | {
110 | $s = self::$live->status('INBOX', Horde_Imap_Client::STATUS_ALL);
111 |
112 | $this->assertInternalType('array', $s);
113 |
114 | $this->assertArrayHasKey('messages', $s);
115 | $this->assertArrayHasKey('recent', $s);
116 | $this->assertEquals($s['messages'], $s['recent']);
117 | $this->assertArrayHasKey('uidnext', $s);
118 | $this->assertArrayHasKey('uidvalidity', $s);
119 | $this->assertArrayHasKey('unseen', $s);
120 | $this->assertEquals(0, $s['unseen']);
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/Format/AtomTest.php:
--------------------------------------------------------------------------------
1 |
21 | * @category Horde
22 | * @copyright 2011-2016 Horde LLC
23 | * @ignore
24 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
25 | * @package Imap_Client
26 | * @subpackage UnitTests
27 | */
28 | class AtomTest extends TestBase
29 | {
30 | protected function getTestObs()
31 | {
32 | return array(
33 | new Horde_Imap_Client_Data_Format_Atom('Foo'),
34 | /* Illegal atom character. */
35 | new Horde_Imap_Client_Data_Format_Atom('Foo('),
36 | /* This is an invalid atom, but valid (non-quoted) astring. */
37 | new Horde_Imap_Client_Data_Format_Atom('Foo]'),
38 | new Horde_Imap_Client_Data_Format_Atom('')
39 | );
40 | }
41 |
42 | /**
43 | * @dataProvider stringRepresentationProvider
44 | */
45 | public function testStringRepresentation($ob, $expected)
46 | {
47 | $this->assertEquals(
48 | $expected,
49 | strval($ob)
50 | );
51 | }
52 |
53 | public function stringRepresentationProvider()
54 | {
55 | return $this->createProviderArray(array(
56 | 'Foo',
57 | 'Foo(',
58 | 'Foo]',
59 | '',
60 | ));
61 | }
62 |
63 | /**
64 | * @dataProvider escapeProvider
65 | */
66 | public function testEscape($ob, $expected)
67 | {
68 | $this->assertEquals(
69 | $expected,
70 | $ob->escape()
71 | );
72 | }
73 |
74 | public function escapeProvider()
75 | {
76 | return $this->createProviderArray(array(
77 | 'Foo',
78 | 'Foo(',
79 | 'Foo]',
80 | '""',
81 | ));
82 | }
83 |
84 | /**
85 | * @dataProvider verifyProvider
86 | */
87 | public function testVerify($ob, $expected)
88 | {
89 | if ($expected) {
90 | $this->expectException('Horde_Imap_Client_Data_Format_Exception');
91 | }
92 |
93 | $ob->verify();
94 |
95 | $this->markTestSkipped('Horde\Imap\Client\Data\Format\AtomTest::testVerify - No Exception should be thrown here. ');
96 | }
97 |
98 | public function verifyProvider()
99 | {
100 | return $this->createProviderArray(array(
101 | false,
102 | true,
103 | true,
104 | false
105 | ));
106 | }
107 |
108 | /**
109 | * @dataProvider stripNonAtomCharactersProvider
110 | */
111 | public function testStripNonAtomCharacters($str, $expected)
112 | {
113 | $atom = new Horde_Imap_Client_Data_Format_Atom($str);
114 | $this->assertEquals(
115 | $expected,
116 | $atom->stripNonAtomCharacters()
117 | );
118 | }
119 |
120 | public function stripNonAtomCharactersProvider()
121 | {
122 | return array(
123 | array('ABC123abc', 'ABC123abc'),
124 | array('A[{À*"A', 'A[A')
125 | );
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/lib/Horde/Imap/Client/Namespace/List.php:
--------------------------------------------------------------------------------
1 |
18 | * @category Horde
19 | * @copyright 2014-2017 Horde LLC
20 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
21 | * @package Imap_Client
22 | * @since 2.21.0
23 | */
24 | class Horde_Imap_Client_Namespace_List
25 | implements ArrayAccess, Countable, IteratorAggregate
26 | {
27 | /**
28 | * The list of namespace objects.
29 | *
30 | * @var array
31 | */
32 | protected $_ns = array();
33 |
34 | /**
35 | * Constructor.
36 | *
37 | * @param array $ns The list of namespace objects.
38 | */
39 | public function __construct($ns = array())
40 | {
41 | foreach ($ns as $val) {
42 | $this->_ns[strval($val)] = $val;
43 | }
44 | }
45 |
46 | /**
47 | * Get namespace info for a full mailbox path.
48 | *
49 | * @param string $mbox The mailbox path.
50 | * @param boolean $personal If true, will return the empty namespace only
51 | * if it is a personal namespace.
52 | *
53 | * @return mixed The Horde_Imap_Client_Data_Namespace object for the
54 | * mailbox path, or null if the path doesn't exist.
55 | */
56 | public function getNamespace($mbox, $personal = false)
57 | {
58 | $mbox = strval($mbox);
59 |
60 | if ($ns = $this[$mbox]) {
61 | return $ns;
62 | }
63 |
64 | foreach ($this->_ns as $val) {
65 | $mbox = $mbox . $val->delimiter;
66 | if (strlen($val->name) && (strpos($mbox, $val->name) === 0)) {
67 | return $val;
68 | }
69 | }
70 |
71 | return (($ns = $this['']) && (!$personal || ($ns->type === $ns::NS_PERSONAL)))
72 | ? $ns
73 | : null;
74 | }
75 |
76 | /* ArrayAccess methods. */
77 |
78 | /**
79 | */
80 | #[ReturnTypeWillChange]
81 | public function offsetExists($offset)
82 | {
83 | return isset($this->_ns[strval($offset)]);
84 | }
85 |
86 | /**
87 | */
88 | #[ReturnTypeWillChange]
89 | public function offsetGet($offset)
90 | {
91 | $offset = strval($offset);
92 |
93 | return isset($this->_ns[$offset])
94 | ? $this->_ns[$offset]
95 | : null;
96 | }
97 |
98 | /**
99 | */
100 | #[ReturnTypeWillChange]
101 | public function offsetSet($offset, $value)
102 | {
103 | if ($value instanceof Horde_Imap_Client_Data_Namespace) {
104 | $this->_ns[strval($value)] = $value;
105 | }
106 | }
107 |
108 | /**
109 | */
110 | #[ReturnTypeWillChange]
111 | public function offsetUnset($offset)
112 | {
113 | unset($this->_ns[strval($offset)]);
114 | }
115 |
116 | /* Countable methods. */
117 |
118 | /**
119 | */
120 | #[ReturnTypeWillChange]
121 | public function count()
122 | {
123 | return count($this->_ns);
124 | }
125 |
126 | /* IteratorAggregate methods. */
127 |
128 | /**
129 | */
130 | #[ReturnTypeWillChange]
131 | public function getIterator()
132 | {
133 | return new ArrayIterator($this->_ns);
134 | }
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/Format/Mailbox/TestBase.php:
--------------------------------------------------------------------------------
1 |
21 | * @category Horde
22 | * @copyright 2014-2016 Horde LLC
23 | * @ignore
24 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
25 | * @package Imap_Client
26 | * @subpackage UnitTests
27 | */
28 | abstract class TestBase extends TestCase
29 | {
30 | protected $cname;
31 |
32 | /**
33 | * @dataProvider stringRepresentationProvider
34 | */
35 | public function testStringRepresentation($mbox, $str)
36 | {
37 | $m = new $this->cname($mbox);
38 |
39 | $this->assertEquals(
40 | $str,
41 | strval($m)
42 | );
43 | }
44 |
45 | abstract public function stringRepresentationProvider();
46 |
47 | /**
48 | * @dataProvider escapeProvider
49 | */
50 | public function testEscape($mbox, $str)
51 | {
52 | $m = new $this->cname($mbox);
53 |
54 | $this->assertEquals(
55 | $str,
56 | $m->escape()
57 | );
58 | }
59 |
60 | abstract public function escapeProvider();
61 |
62 | /**
63 | * @dataProvider verifyProvider
64 | */
65 | public function testVerify($mbox, $exception)
66 | {
67 | if ($exception) {
68 | $this->expectException('Exception');
69 | }
70 |
71 | $m = new $this->cname($mbox);
72 |
73 | $this->markTestSkipped('Horde\Imap\Client\Data\Format\Mailbox\MailboxUtf8Test::testVerify - No Exception should be thrown here. ');
74 | }
75 |
76 | abstract public function verifyProvider();
77 |
78 | /**
79 | * @dataProvider binaryProvider
80 | */
81 | public function testBinary($mbox, $expected)
82 | {
83 | $m = new $this->cname($mbox);
84 |
85 | if ($expected) {
86 | $this->assertTrue($m->binary());
87 | } else {
88 | $this->assertFalse($m->binary());
89 | }
90 | }
91 |
92 | abstract public function binaryProvider();
93 |
94 | /**
95 | * @dataProvider literalProvider
96 | */
97 | public function testLiteral($mbox, $expected)
98 | {
99 | $m = new $this->cname($mbox);
100 |
101 | if ($expected) {
102 | $this->assertTrue($m->literal());
103 | } else {
104 | $this->assertFalse($m->literal());
105 | }
106 | }
107 |
108 | abstract public function literalProvider();
109 |
110 | /**
111 | * @dataProvider quotedProvider
112 | */
113 | public function testQuoted($mbox, $expected)
114 | {
115 | $m = new $this->cname($mbox);
116 |
117 | if ($expected) {
118 | $this->assertTrue($m->quoted());
119 | } else {
120 | $this->assertFalse($m->quoted());
121 | }
122 | }
123 |
124 | abstract public function quotedProvider();
125 |
126 | /**
127 | * @dataProvider escapeStreamProvider
128 | */
129 | public function testEscapeStream($mbox, $expected)
130 | {
131 | $m = new $this->cname($mbox);
132 |
133 | $this->assertEquals(
134 | $expected,
135 | stream_get_contents($m->escapeStream(), -1, 0)
136 | );
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Url/Pop3Test.php:
--------------------------------------------------------------------------------
1 |
20 | * @category Horde
21 | * @copyright 2014-2016 Horde LLC
22 | * @ignore
23 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
24 | * @package Imap_Client
25 | * @subpackage UnitTests
26 | */
27 | class Pop3Test extends TestBase
28 | {
29 | protected $classname = 'Horde_Imap_Client_Url_Pop3';
30 | protected $host = 'host';
31 | protected $protocol = 'pop';
32 |
33 | public function testUrlProvider()
34 | {
35 | $this->markTestIncomplete();
36 |
37 | return array(
38 | array(
39 | 'pop://test.example.com/',
40 | null,
41 | array(
42 | 'host' => 'test.example.com',
43 | 'port' => 110
44 | )
45 | ),
46 | array(
47 | 'pop://test.example.com:110/',
48 | 'pop://test.example.com/',
49 | array(
50 | 'host' => 'test.example.com',
51 | 'port' => 110
52 | )
53 | ),
54 | array(
55 | 'pop://testuser@test.example.com/',
56 | null,
57 | array(
58 | 'host' => 'test.example.com',
59 | 'port' => 110,
60 | 'username' => 'testuser'
61 | )
62 | ),
63 | // This is the default port for IMAP, not POP3
64 | array(
65 | 'pop://testuser@test.example.com:143/',
66 | null,
67 | array(
68 | 'host' => 'test.example.com',
69 | 'port' => 143,
70 | 'username' => 'testuser'
71 | )
72 | ),
73 | array(
74 | 'pop://testuser;AUTH=*@test.example.com:110/',
75 | 'pop://testuser@test.example.com/',
76 | array(
77 | 'auth' => null,
78 | 'host' => 'test.example.com',
79 | 'port' => 110,
80 | 'username' => 'testuser'
81 | )
82 | ),
83 | array(
84 | 'pop://testuser;AUTH=PLAIN@test.example.com/',
85 | null,
86 | array(
87 | 'host' => 'test.example.com',
88 | 'port' => 110,
89 | 'username' => 'testuser',
90 | 'auth' => 'PLAIN'
91 | )
92 | ),
93 | // Ignore everything after the port.
94 | array(
95 | 'pop://test.example.com:110/INBOX.Quarant%26AOQ-ne;UIDVALIDITY=1240054819/;UID=39193/;SECTION=HEADER',
96 | 'pop://test.example.com/',
97 | array(
98 | 'host' => 'test.example.com',
99 | 'port' => 110,
100 | 'section' => '',
101 | 'uid' => '',
102 | 'uidvalidity' => '',
103 | 'mailbox' => ''
104 | )
105 | )
106 | );
107 | }
108 |
109 | public function serializeProvider()
110 | {
111 | return array(
112 | array('pop://test.example.com/')
113 | );
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Namespace/ListTest.php:
--------------------------------------------------------------------------------
1 |
23 | * @category Horde
24 | * @copyright 2014-2016 Horde LLC
25 | * @ignore
26 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
27 | * @package Imap_Client
28 | * @subpackage UnitTests
29 | */
30 | class ListTest extends TestCase
31 | {
32 | private $ob;
33 |
34 | public function setUp(): void
35 | {
36 | $this->ob = new Horde_Imap_Client_Namespace_List();
37 |
38 | $ob2 = new Horde_Imap_Client_Data_Namespace();
39 | $ob2->delimiter = '.';
40 | $ob2->type = $ob2::NS_SHARED;
41 | $this->ob[''] = $ob2;
42 |
43 | $ob3 = new Horde_Imap_Client_Data_Namespace();
44 | $ob3->delimiter = '.';
45 | $ob3->hidden = true;
46 | $ob3->name = 'foo';
47 | $this->ob['foo'] = $ob3;
48 | }
49 |
50 | /**
51 | * @dataProvider arrayProvider
52 | */
53 | public function testArrayAccess($name, $exists = true)
54 | {
55 | if ($exists) {
56 | $this->assertTrue(isset($this->ob[$name]));
57 | $this->assertInstanceof(
58 | 'Horde_Imap_Client_Data_Namespace',
59 | $this->ob[$name]
60 | );
61 | } else {
62 | $this->assertFalse(isset($this->ob[$name]));
63 | $this->assertNull($this->ob[$name]);
64 | }
65 | }
66 |
67 | /**
68 | */
69 | public function testCountable()
70 | {
71 | $this->assertEquals(
72 | 2,
73 | count($this->ob)
74 | );
75 | }
76 |
77 | /**
78 | */
79 | public function testIterator()
80 | {
81 | foreach ($this->ob as $val) {
82 | $this->assertInstanceof(
83 | 'Horde_Imap_Client_Data_Namespace',
84 | $val
85 | );
86 | }
87 | }
88 |
89 | /**
90 | */
91 | public function testSerialize()
92 | {
93 | $ob2 = unserialize(serialize($this->ob));
94 |
95 | $this->assertEquals(
96 | 2,
97 | count($this->ob)
98 | );
99 | }
100 |
101 | /**
102 | * @dataProvider getNamespaceProvider
103 | */
104 | public function testGetNamespace($mbox, $personal, $expected)
105 | {
106 | if (is_null($expected)) {
107 | $this->assertNull($this->ob->getNamespace($mbox, $personal));
108 | } else {
109 | $this->assertEquals(
110 | $expected,
111 | strval($this->ob->getNamespace($mbox, $personal))
112 | );
113 | }
114 | }
115 |
116 | /**
117 | */
118 | public function arrayProvider()
119 | {
120 | return array(
121 | array(''),
122 | array('foo'),
123 | array('bar', false)
124 | );
125 | }
126 |
127 | /**
128 | */
129 | public function getNamespaceProvider()
130 | {
131 | return array(
132 | array('baz', false, ''),
133 | array('baz', true, null),
134 | array('foo.bar', false, 'foo'),
135 | array('foo.bar', true, 'foo'),
136 | array('baz.bar', false, ''),
137 | array('baz.bar', true, null)
138 | );
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/AuthTest.php:
--------------------------------------------------------------------------------
1 |
23 | * @category Horde
24 | * @copyright 2011-2016 Horde LLC
25 | * @ignore
26 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
27 | * @package Imap_Client
28 | * @subpackage UnitTests
29 |
30 | */
31 | class AuthTest extends TestCase
32 | {
33 | public static function setUpBeforeClass(): void
34 | {
35 | require_once __DIR__ . '/Stub/DigestMD5.php';
36 | require_once __DIR__ . '/Stub/Scram.php';
37 | }
38 |
39 | /**
40 | * @dataProvider digestMd5Provider
41 | */
42 | public function testDigestMd5($c)
43 | {
44 | $ob = new DigestMD5(
45 | $c['user'],
46 | $c['pass'],
47 | $c['challenge'],
48 | $c['hostname'],
49 | $c['service'],
50 | $c['cnonce']
51 | );
52 |
53 | $this->assertEquals(
54 | $c['expected'],
55 | $ob->response
56 | );
57 | }
58 |
59 | public function digestMd5Provider()
60 | {
61 | return array(
62 | array(
63 | // IMAP example from RFC 2831 [4]
64 | array(
65 | 'user' => 'chris',
66 | 'pass' => 'secret',
67 | 'challenge' => base64_decode('cmVhbG09ImVsd29vZC5pbm5vc29mdC5jb20iLG5vbmNlPSJPQTZNRzl0RVFHbTJoaCIscW9wPSJhdXRoIixhbGdvcml0aG09bWQ1LXNlc3MsY2hhcnNldD11dGYtOA=='),
68 | 'hostname' => 'elwood.innosoft.com',
69 | 'service' => 'imap',
70 | 'cnonce' => 'OA6MHXh6VqTrRk',
71 | 'expected' => 'd388dad90d4bbd760a152321f2143af7'
72 | )
73 | )
74 | );
75 | }
76 |
77 | /**
78 | * @dataProvider scramProvider
79 | */
80 | public function testScram($c)
81 | {
82 | $this->expectException('Horde_Imap_Client_Exception');
83 |
84 | $ob = new Scram(
85 | $c['user'],
86 | $c['pass'],
87 | $c['hash']
88 | );
89 | $ob->setNonce($c['nonce']);
90 |
91 | $this->assertEquals(
92 | $c['c1'],
93 | $ob->getClientFirstMessage()
94 | );
95 |
96 | $this->assertTrue($ob->parseServerFirstMessage($c['s1']));
97 |
98 | $this->assertEquals(
99 | $c['c2'],
100 | $ob->getClientFinalMessage()
101 | );
102 |
103 | $this->assertTrue($ob->parseServerFinalMessage($c['s2']));
104 | }
105 |
106 | public function scramProvider()
107 | {
108 | return array(
109 | array(
110 | // Example from RFC 5802 [5]
111 | array(
112 | 'user' => 'user',
113 | 'pass' => 'pencil',
114 | 'hash' => 'SHA1',
115 | 'nonce' => 'fyko+d2lbbFgONRv9qkxdawL',
116 | 'c1' => 'n,,n=user,r=fyko+d2lbbFgONRv9qkxdawL',
117 | 's1' => 'r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,i=4096',
118 | 'c2' => 'c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=',
119 | 's2' => 'v=rmF9pqV8S7suAoZWja4dJRkFsKQ='
120 | )
121 | )
122 | );
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/test/Horde/Imap/Client/Data/Format/ListTest.php:
--------------------------------------------------------------------------------
1 |
24 | * @category Horde
25 | * @copyright 2011-2016 Horde LLC
26 | * @ignore
27 | * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
28 | * @package Imap_Client
29 | * @subpackage UnitTests
30 | */
31 | class ListTest extends TestCase
32 | {
33 | public function testBasicListFunctions()
34 | {
35 | $ob = new Horde_Imap_Client_Data_Format_List();
36 |
37 | $this->assertEquals(
38 | 0,
39 | count($ob)
40 | );
41 |
42 | $ob->add(new Horde_Imap_Client_Data_Format_Atom('Foo'));
43 | $ob->add(new Horde_Imap_Client_Data_Format_Atom('Bar'));
44 | $ob->add(new Horde_Imap_Client_Data_Format_String('Baz'));
45 |
46 | $this->assertEquals(
47 | 3,
48 | count($ob)
49 | );
50 |
51 | $this->assertEquals(
52 | 'Foo Bar "Baz"',
53 | strval($ob)
54 | );
55 |
56 | $this->assertEquals(
57 | 'Foo Bar "Baz"',
58 | $ob->escape()
59 | );
60 |
61 | foreach ($ob as $key => $val) {
62 | switch ($key) {
63 | case 0:
64 | case 1:
65 | $this->assertEquals(
66 | 'Horde_Imap_Client_Data_Format_Atom',
67 | get_class($val)
68 | );
69 | break;
70 |
71 | case 2:
72 | $this->assertEquals(
73 | 'Horde_Imap_Client_Data_Format_String',
74 | get_class($val)
75 | );
76 | break;
77 | }
78 | }
79 |
80 | }
81 |
82 | public function testAdvancedListFunctions()
83 | {
84 | $ob = new Horde_Imap_Client_Data_Format_List('Foo');
85 |
86 | $this->assertEquals(
87 | 1,
88 | count($ob)
89 | );
90 |
91 | $ob_array = iterator_to_array($ob);
92 | $this->assertEquals(
93 | 'Horde_Imap_Client_Data_Format_Atom',
94 | get_class(reset($ob_array))
95 | );
96 |
97 | $ob->add(array(
98 | 'Foo',
99 | new Horde_Imap_Client_Data_Format_List(array('Bar'))
100 | ));
101 |
102 | $this->assertEquals(
103 | 3,
104 | count($ob)
105 | );
106 |
107 | $this->assertEquals(
108 | 'Foo Foo (Bar)',
109 | $ob->escape()
110 | );
111 |
112 | $ob = new Horde_Imap_Client_Data_Format_List(array(
113 | 'Foo',
114 | new Horde_Imap_Client_Data_Format_List(array(
115 | 'Foo1'
116 | )),
117 | 'Bar',
118 | new Horde_Imap_Client_Data_Format_List(array(
119 | new Horde_Imap_Client_Data_Format_String('Bar1'),
120 | new Horde_Imap_Client_Data_Format_List(array(
121 | 'Baz'
122 | ))
123 | ))
124 | ));
125 |
126 | $this->assertEquals(
127 | 4,
128 | count($ob)
129 | );
130 |
131 | $this->assertEquals(
132 | 'Foo (Foo1) Bar ("Bar1" (Baz))',
133 | $ob->escape()
134 | );
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------