Skip to content

Commit f179edd

Browse files
committed
fix: backport community fixes from bytestream fork
Original-Author: Anna Larch <anna@nextcloud.com> (Ids int cast, ceafee1) Original-Author: Richard Steinmetz <richard@steinmetz.cloud> (Tokenize resource leak, e72ae63) Original-Author: Daniel Kesselberg <mail@danielkesselberg.de> (Socket read timeout exception, 33dc825) Original-Author: Daniel Kesselberg <mail@danielkesselberg.de> (Socket vanished chunking, 69a022d) Original-Author: Kieran Brahney <kieran.brahney@gmail.com> (Pop3 null date cast, fed98c8) Original-Author: Kieran Brahney <kieran.brahney@gmail.com> (Exception constructor defaults, bdb0e46) Original-Author: Daniel Kesselberg <mail@danielkesselberg.de> (Connection debug message, f66eeb6)
1 parent f233f0d commit f179edd

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
lines changed

lib/Horde/Imap/Client/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class Horde_Imap_Client_Exception extends Horde_Exception_Wrapped
261261
* @param string $message Error message (non-translated).
262262
* @param int $code Error code.
263263
*/
264-
public function __construct($message = null, $code = null)
264+
public function __construct($message = '', $code = 0)
265265
{
266266
parent::__construct($message, $code);
267267

lib/Horde/Imap/Client/Ids.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function add($ids)
169169
} elseif ($add = $this->_resolveIds($ids)) {
170170
if (is_array($this->_ids) && !empty($this->_ids)) {
171171
foreach ($add as $val) {
172-
$this->_ids[] = $val;
172+
$this->_ids[] = (int) $val;
173173
}
174174
} else {
175175
$this->_ids = $add;
@@ -364,10 +364,10 @@ protected function _fromSequenceString($str)
364364
$range = explode(':', $val);
365365
if (isset($range[1])) {
366366
for ($i = min($range), $j = max($range); $i <= $j; ++$i) {
367-
$ids[] = $i;
367+
$ids[] = (int) $i;
368368
}
369369
} else {
370-
$ids[] = $val;
370+
$ids[] = (int) $val;
371371
}
372372
}
373373

lib/Horde/Imap/Client/Socket.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,21 +3568,29 @@ protected function _parseEnvelope(Horde_Imap_Client_Tokenize $data)
35683568
return $ret;
35693569
}
35703570

3571-
/**
3572-
*/
35733571
protected function _vanished($modseq, Horde_Imap_Client_Ids $ids)
35743572
{
3575-
$pipeline = $this->_pipeline(
3576-
$this->_command('UID FETCH')->add([
3577-
strval($ids),
3573+
// Unlike _fetchCmd(), sequence IDs are rejected before reaching
3574+
// here, so we always issue UID FETCH. Chunk UIDs to avoid
3575+
// exceeding the server's command length limit.
3576+
3577+
$modifiers = new Horde_Imap_Client_Data_Format_List([
3578+
'VANISHED',
3579+
'CHANGEDSINCE',
3580+
new Horde_Imap_Client_Data_Format_Number($modseq),
3581+
]);
3582+
3583+
$pipeline = $this->_pipeline();
3584+
3585+
foreach ($ids->split($this->_capability()->cmdlength) as $val) {
3586+
$cmd = $this->_command('UID FETCH')->add([
3587+
$val,
35783588
'UID',
3579-
new Horde_Imap_Client_Data_Format_List([
3580-
'VANISHED',
3581-
'CHANGEDSINCE',
3582-
new Horde_Imap_Client_Data_Format_Number($modseq),
3583-
]),
3584-
])
3585-
);
3589+
$modifiers,
3590+
]);
3591+
$pipeline->add($cmd);
3592+
}
3593+
35863594
$pipeline->data['vanished'] = $this->getIdsOb();
35873595

35883596
return $this->_sendCmd($pipeline)->data['vanished'];
@@ -4339,13 +4347,15 @@ protected function _sendCmdChunk($pipeline, $chunk)
43394347
$this->_temp['logout'] = true;
43404348
$this->logout();
43414349
throw $e;
4342-
}
43434350

4344-
/* For all other issues, catch and store exception; don't
4345-
* throw until all input is read since we need to clear
4346-
* incoming queue. (For now, only store first exception.) */
4347-
if (is_null($exception)) {
4348-
$exception = $e;
4351+
default:
4352+
/* For all other issues, catch and store exception;
4353+
* don't throw until all input is read since we need
4354+
* to clear incoming queue. (For now, only store first
4355+
* exception.) */
4356+
if (is_null($exception)) {
4357+
$exception = $e;
4358+
}
43494359
}
43504360

43514361
if (($e instanceof Horde_Imap_Client_Exception_ServerResponse)

lib/Horde/Imap/Client/Socket/Connection/Socket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function read($size = null)
197197
$read_now = microtime(true);
198198
$t_read = $read_now - $read_start;
199199
if ($t_read > $this->_params['timeout']) {
200-
$this->_params['debug']->info(sprintf('ERROR: read timeout. No data received for %d seconds.', $this->_params['read_timeout']));
200+
$this->_params['debug']->info(sprintf('ERROR: read timeout. No data received for %d seconds.', $this->_params['timeout']));
201201

202202
throw new Horde_Imap_Client_Exception(
203203
Horde_Imap_Client_Translation::r("Read timeout."),

lib/Horde/Imap/Client/Socket/Pop3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ protected function _fetchCmd(
10291029
case Horde_Imap_Client::FETCH_IMAPDATE:
10301030
foreach ($seq_ids as $id) {
10311031
$tmp = $this->_pop3Cache('hdrob', $id);
1032-
$results->get($lookup[$id])->setImapDate($tmp['Date']);
1032+
$results->get($lookup[$id])->setImapDate((string) $tmp['Date']);
10331033
}
10341034
break;
10351035

lib/Horde/Imap/Client/Tokenize.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public function __construct($data = null)
9494
}
9595
}
9696

97+
public function __destruct()
98+
{
99+
$this->_stream->close();
100+
}
101+
97102
/**
98103
*/
99104
public function __clone()

0 commit comments

Comments
 (0)