Skip to content

Commit d240b52

Browse files
coverage
1 parent 4534a00 commit d240b52

File tree

6 files changed

+78
-5
lines changed

6 files changed

+78
-5
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ test-num-msg:
7777
test-ping:
7878
@docker-compose run --rm phpunit tests --filter CompatibilityTest::testPing
7979

80+
test-get-mailboxes:
81+
@docker-compose run --rm phpunit tests --filter CompatibilityTest::testGetMailboxes
82+
8083
test-xoauth:
8184
@docker-compose run --rm phpunit tests --filter XoauthTest
8285

src/Connection.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ protected function connect()
104104
'ssl_mode' => $this->sslMode,
105105
'auth_type' => $this->flags & OP_XOAUTH2 ? 'XOAUTH2' : 'CHECK',
106106
'timeout' => -1,
107+
'force_caps' => false,
107108
]);
108109

109110
if (empty($success)) {
@@ -137,7 +138,6 @@ public function getMailbox()
137138
return $this->mailbox;
138139
}
139140

140-
141141
/**
142142
*
143143
*/
@@ -146,6 +146,14 @@ public function getMailboxName()
146146
return $this->currentMailbox;
147147
}
148148

149+
/**
150+
*
151+
*/
152+
public function getHost()
153+
{
154+
return $this->host;
155+
}
156+
149157
/**
150158
*
151159
*/

src/Functions.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,40 @@ public static function writeAddressFromEnvelope($addressList)
108108

109109
return implode(', ', $sanitizedAddress);
110110
}
111+
112+
/**
113+
*
114+
*/
115+
public static function getListAttributesValue($attributes)
116+
{
117+
$attributesValue = 0;
118+
119+
foreach ($attributes as $attribute) {
120+
switch ($attribute) {
121+
case '\\NoInferiors':
122+
$attributesValue |= LATT_NOINFERIORS;
123+
break;
124+
case '\\NoSelect':
125+
$attributesValue |= LATT_NOSELECT;
126+
break;
127+
case '\\Marked':
128+
$attributesValue |= LATT_MARKED;
129+
break;
130+
case '\\UnMarked':
131+
$attributesValue |= LATT_UNMARKED;
132+
break;
133+
case '\\Referral':
134+
$attributesValue |= LATT_REFERRAL;
135+
break;
136+
case '\\HasChildren':
137+
$attributesValue |= LATT_HASCHILDREN;
138+
break;
139+
case '\\HasNoChildren':
140+
$attributesValue |= LATT_HASNOCHILDREN;
141+
break;
142+
}
143+
}
144+
145+
return $attributesValue;
146+
}
111147
}

src/ImapClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ protected function putLineC($string, $endln=true, $anonymized=false)
146146
$res = 0;
147147
if ($parts = preg_split('/(\{[0-9]+\}\r\n)/m', $string, -1, PREG_SPLIT_DELIM_CAPTURE)) {
148148
for ($i=0, $cnt=count($parts); $i<$cnt; $i++) {
149-
if (preg_match('/^\{([0-9]+)\}\r\n$/', $parts[$i+1], $matches)) {
149+
if (isset($parts[$i+1]) && preg_match('/^\{([0-9]+)\}\r\n$/', $parts[$i+1], $matches)) {
150150
// LITERAL+ support
151151
if ($this->prefs['literal+']) {
152152
$parts[$i+1] = sprintf("{%d+}\r\n", $matches[1]);
@@ -1592,6 +1592,8 @@ protected function _listMailboxes($ref, $mailbox, $subscribed=false,
15921592
if (!empty($opts)) {
15931593
$rets = array_merge($rets, $opts);
15941594
}
1595+
} else {
1596+
$lstatus = false;
15951597
}
15961598

15971599
if (!empty($rets)) {

src/Mailbox.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,20 @@ public static function getMailboxes($imap, $reference, $pattern)
212212

213213
$referenceParts = explode('}', $reference);
214214
$client = $imap->getClient();
215+
$client->setDebug(true);
215216
$return = [];
217+
$delimiter = $client->getHierarchyDelimiter();
216218
$mailboxes = $client->listMailboxes($referenceParts[1], $pattern);
217219
foreach ($mailboxes as $mailbox) {
218-
if (in_array('\\Noselect', $client->data['LIST'][$mailbox])) {
219-
continue;
220+
$attributesValue = Functions::getListAttributesValue($client->data['LIST'][$mailbox]);
221+
if ($mailbox == '[Gmail]' && $imap->getHost() == 'imap.gmail.com') {
222+
$attributesValue = 34;
220223
}
221-
$return[] = $referenceParts[0].'}'.$mailbox;
224+
$return[] = (object) [
225+
'name' => $referenceParts[0].'}'.$mailbox,
226+
'attributes' => $attributesValue,
227+
'delimiter' => $delimiter,
228+
];
222229
}
223230

224231
return $return;

tests/CompatibilityTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,23 @@ public function testStatus()
177177
imap2_close($imap2);
178178
}
179179

180+
public function testGetMailboxes()
181+
{
182+
$imap1 = imap_open($this->mailbox, $this->username, $this->password);
183+
$imap2 = imap2_open($this->mailbox, $this->username, $this->accessToken, OP_XOAUTH2);
184+
185+
$mailboxes1 = imap_getmailboxes($imap1, $this->mailbox, '*');
186+
$mailboxes2 = imap2_getmailboxes($imap2, $this->mailbox, '*');
187+
188+
file_put_contents('l1.json', json_encode($mailboxes1, JSON_PRETTY_PRINT));
189+
file_put_contents('l2.json', json_encode($mailboxes2, JSON_PRETTY_PRINT));
190+
191+
$this->assertEquals($mailboxes1, $mailboxes2);
192+
193+
imap_close($imap1);
194+
imap2_close($imap2);
195+
}
196+
180197
public function testAlerts()
181198
{
182199
@imap_open('wrong-mailbox', $this->username, $this->password);

0 commit comments

Comments
 (0)