comparison program/lib/Roundcube/rcube_imap_generic.php @ 16:1866b439e6d3

Slowly cleaning up more php8 Warnings/deprecations
author Charlie Root
date Mon, 06 Oct 2025 10:34:51 -0400
parents 85a746e95663
children dd5ed6ef69c9
comparison
equal deleted inserted replaced
15:85a746e95663 16:1866b439e6d3
142 } 142 }
143 143
144 $res = 0; 144 $res = 0;
145 if ($parts = preg_split('/(\{[0-9]+\}\r\n)/m', $string, -1, PREG_SPLIT_DELIM_CAPTURE)) { 145 if ($parts = preg_split('/(\{[0-9]+\}\r\n)/m', $string, -1, PREG_SPLIT_DELIM_CAPTURE)) {
146 for ($i=0, $cnt=count($parts); $i<$cnt; $i++) { 146 for ($i=0, $cnt=count($parts); $i<$cnt; $i++) {
147 if (preg_match('/^\{([0-9]+)\}\r\n$/', $parts[$i+1], $matches)) { 147 if (($parts[$i+1]??null) &&
148 preg_match('/^\{([0-9]+)\}\r\n$/',
149 $parts[$i+1], $matches)) {
148 // LITERAL+ support 150 // LITERAL+ support
149 if ($this->prefs['literal+']) { 151 if ($this->prefs['literal+']) {
150 $parts[$i+1] = sprintf("{%d+}\r\n", $matches[1]); 152 $parts[$i+1] = sprintf("{%d+}\r\n", $matches[1]);
151 } 153 }
152 154
197 $size = 1024; 199 $size = 1024;
198 } 200 }
199 201
200 do { 202 do {
201 if ($this->eof()) { 203 if ($this->eof()) {
202 return $line ?: null; 204 return $line ?: null;
203 } 205 }
204 206
205 $buffer = fgets($this->fp, $size); 207 $buffer = fgets($this->fp, $size);
206 208
207 if ($buffer === false) { 209 if ($buffer === false) {
1504 if (!empty($return_opts) && $this->getCapability('LIST-EXTENDED')) { 1506 if (!empty($return_opts) && $this->getCapability('LIST-EXTENDED')) {
1505 $ext_opts = array('SUBSCRIBED', 'CHILDREN'); 1507 $ext_opts = array('SUBSCRIBED', 'CHILDREN');
1506 $rets = array_intersect($return_opts, $ext_opts); 1508 $rets = array_intersect($return_opts, $ext_opts);
1507 $return_opts = array_diff($return_opts, $rets); 1509 $return_opts = array_diff($return_opts, $rets);
1508 } 1510 }
1511 else {
1512 $ext_opts = $rets = $return_opts = null;
1513 }
1509 1514
1510 if (!empty($return_opts) && $this->getCapability('LIST-STATUS')) { 1515 if (!empty($return_opts) && $this->getCapability('LIST-STATUS')) {
1511 $lstatus = true; 1516 $lstatus = true;
1512 $status_opts = array('MESSAGES', 'RECENT', 'UIDNEXT', 'UIDVALIDITY', 'UNSEEN'); 1517 $status_opts = array('MESSAGES', 'RECENT', 'UIDNEXT', 'UIDVALIDITY', 'UNSEEN');
1513 $opts = array_diff($return_opts, $status_opts); 1518 $opts = array_diff($return_opts, $status_opts);
1519 1524
1520 if (!empty($opts)) { 1525 if (!empty($opts)) {
1521 $rets = array_merge($rets, $opts); 1526 $rets = array_merge($rets, $opts);
1522 } 1527 }
1523 } 1528 }
1529 else {
1530 $lstatus = $opts = $status_opts = $rets = null;
1531 }
1524 1532
1525 if (!empty($rets)) { 1533 if (!empty($rets)) {
1526 $args[] = 'RETURN (' . implode(' ', $rets) . ')'; 1534 $args[] = 'RETURN (' . implode(' ', $rets) . ')';
1527 } 1535 }
1528 1536
1615 if ($this->selected === $mailbox && isset($this->data['EXISTS'])) { 1623 if ($this->selected === $mailbox && isset($this->data['EXISTS'])) {
1616 return $this->data['EXISTS']; 1624 return $this->data['EXISTS'];
1617 } 1625 }
1618 1626
1619 // Check internal cache 1627 // Check internal cache
1620 $cache = $this->data['STATUS:'.$mailbox]; 1628 $cache = ($this->data['STATUS:'.$mailbox]??null);
1621 if (!empty($cache) && isset($cache['MESSAGES'])) { 1629 if (!empty($cache) && isset($cache['MESSAGES'])) {
1622 return (int) $cache['MESSAGES']; 1630 return (int) $cache['MESSAGES'];
1623 } 1631 }
1624 1632
1625 // Try STATUS (should be faster than SELECT) 1633 // Try STATUS (should be faster than SELECT)
2161 2169
2162 if (!$this->select($mailbox)) { 2170 if (!$this->select($mailbox)) {
2163 return null; 2171 return null;
2164 } 2172 }
2165 2173
2166 if ($uid = $this->data['UID-MAP'][$id]) { 2174 if (($map = ( $this->data['UID-MAP'] ?? null) ) &&
2175 ($uid = ( $map[$id] ?? null ) ) ) {
2167 return $uid; 2176 return $uid;
2168 } 2177 }
2169 2178
2170 if (isset($this->data['EXISTS']) && $id > $this->data['EXISTS']) { 2179 if (isset($this->data['EXISTS']) && $id > $this->data['EXISTS']) {
2171 return null; 2180 return null;
2426 2435
2427 $line .= $str; 2436 $line .= $str;
2428 } 2437 }
2429 2438
2430 // Tokenize response and assign to object properties 2439 // Tokenize response and assign to object properties
2431 while (list($name, $value) = $this->tokenizeResponse($line, 2)) { 2440 while ($token = $this->tokenizeResponse($line, 2)) {
2441 list($name, $value) = $token;
2442
2432 if ($name == 'UID') { 2443 if ($name == 'UID') {
2433 $result[$id]->uid = intval($value); 2444 $result[$id]->uid = intval($value);
2434 } 2445 }
2435 else if ($name == 'RFC822.SIZE') { 2446 else if ($name == 'RFC822.SIZE') {
2436 $result[$id]->size = intval($value); 2447 $result[$id]->size = intval($value);
2471 else if (stripos($name, 'BODY[') === 0) { 2482 else if (stripos($name, 'BODY[') === 0) {
2472 $name = str_replace(']', '', substr($name, 5)); 2483 $name = str_replace(']', '', substr($name, 5));
2473 2484
2474 if ($name == 'HEADER.FIELDS') { 2485 if ($name == 'HEADER.FIELDS') {
2475 // skip ']' after headers list 2486 // skip ']' after headers list
2476 $this->tokenizeResponse($line, 1); 2487 $this->tokenizeResponse($line, 1);
2477 $headers = $this->tokenizeResponse($line, 1); 2488 $headers = $this->tokenizeResponse($line, 1);
2478 } 2489 }
2479 else if (strlen($name)) { 2490 else if (strlen($name)) {
2480 $result[$id]->bodypart[$name] = $value; 2491 $result[$id]->bodypart[$name] = $value;
2481 } 2492 }
2482 else { 2493 else {
2483 $result[$id]->body = $value; 2494 $result[$id]->body = $value;
2484 } 2495 }
2485 } 2496 }
2497
2486 } 2498 }
2487 2499
2488 // create array with header field:data 2500 // create array with header field:data
2489 if (!empty($headers)) { 2501 if (!empty($headers)) {
2490 $headers = explode("\n", trim($headers)); 2502 $headers = explode("\n", trim($headers));