From d9d9d42c814facba30e9b657cab26b07a0ac0ff2 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 20 Jan 2023 11:24:26 +0000 Subject: [PATCH] MDL-76089 lib: upgrade horde library --- .../Horde/Crypt/Blowfish/Openssl.php | 7 ++- lib/horde/framework/Horde/Domhtml.php | 5 ++ .../framework/Horde/Exception/LastError.php | 2 +- .../Horde/Exception/PermissionDenied.php | 2 +- lib/horde/framework/Horde/Idna.php | 6 +++ .../framework/Horde/Imap/Client/Base.php | 38 ++++++++++----- .../Horde/Imap/Client/Base/Alerts.php | 3 ++ .../Horde/Imap/Client/Cache/Backend.php | 18 ++++++-- .../Horde/Imap/Client/Cache/Backend/Cache.php | 10 +++- .../framework/Horde/Imap/Client/Data/Acl.php | 28 ++++++++++- .../Horde/Imap/Client/Data/AclRights.php | 33 +++++++++++-- .../Horde/Imap/Client/Data/Capability.php | 24 +++++++++- .../Horde/Imap/Client/Data/Envelope.php | 24 +++++++--- .../Horde/Imap/Client/Data/Fetch.php | 8 ++-- .../Imap/Client/Data/Format/Filter/Quote.php | 2 + .../Imap/Client/Data/Format/Filter/String.php | 2 + .../Horde/Imap/Client/Data/Format/List.php | 2 + .../Horde/Imap/Client/Data/Namespace.php | 21 ++++++++- .../Horde/Imap/Client/Data/SearchCharset.php | 24 +++++++++- .../Imap/Client/Data/SearchCharset/Utf8.php | 12 +++++ .../Horde/Imap/Client/Data/Thread.php | 25 ++++++++-- .../framework/Horde/Imap/Client/DateTime.php | 10 ++-- .../framework/Horde/Imap/Client/Exception.php | 2 +- .../Horde/Imap/Client/Fetch/Query.php | 10 ++++ .../Horde/Imap/Client/Fetch/Results.php | 6 +++ lib/horde/framework/Horde/Imap/Client/Ids.php | 45 ++++++++++++------ .../framework/Horde/Imap/Client/Ids/Map.php | 34 ++++++++++---- .../Imap/Client/Interaction/Pipeline.php | 2 + .../framework/Horde/Imap/Client/Mailbox.php | 21 ++++++++- .../Horde/Imap/Client/Mailbox/List.php | 2 + .../Horde/Imap/Client/Namespace/List.php | 6 +++ .../Horde/Imap/Client/Search/Query.php | 22 +++++++-- .../framework/Horde/Imap/Client/Socket.php | 2 +- .../framework/Horde/Imap/Client/Tokenize.php | 5 ++ lib/horde/framework/Horde/Imap/Client/Url.php | 21 ++++++++- .../framework/Horde/Imap/Client/Url/Base.php | 21 ++++++++- lib/horde/framework/Horde/Mail/Mbox/Parse.php | 10 ++++ lib/horde/framework/Horde/Mail/Rfc822.php | 4 +- .../framework/Horde/Mail/Rfc822/Address.php | 12 ++--- .../framework/Horde/Mail/Rfc822/Group.php | 1 + .../Horde/Mail/Rfc822/Identification.php | 4 +- .../framework/Horde/Mail/Rfc822/List.php | 21 +++++++++ lib/horde/framework/Horde/Mail/Transport.php | 4 +- .../framework/Horde/Mime/Filter/Encoding.php | 2 + lib/horde/framework/Horde/Mime/Headers.php | 44 ++++++++++++++---- .../Horde/Mime/Headers/ContentParam.php | 36 +++++++++++++-- .../ContentParam/ContentDisposition.php | 1 + .../framework/Horde/Mime/Headers/Element.php | 4 ++ lib/horde/framework/Horde/Mime/Part.php | 46 +++++++++++++------ .../framework/Horde/Mime/Part/Iterator.php | 6 +++ lib/horde/framework/Horde/Mime/Related.php | 1 + lib/horde/framework/Horde/Mime/Uudecode.php | 2 + lib/horde/framework/Horde/Socket/Client.php | 3 +- lib/horde/framework/Horde/Stream.php | 35 ++++++++++---- .../framework/Horde/Stream/Filter/Bin2hex.php | 1 + .../framework/Horde/Stream/Filter/Crc32.php | 2 + .../framework/Horde/Stream/Filter/Eol.php | 2 + .../Horde/Stream/Filter/Htmlspecialchars.php | 1 + .../framework/Horde/Stream/Filter/Null.php | 2 + .../framework/Horde/Stream/TempString.php | 38 ++++++++++----- .../Horde/Stream/Wrapper/Combine.php | 8 ++-- lib/horde/framework/Horde/String.php | 16 +++++-- lib/horde/framework/Horde/Support/Array.php | 6 +++ .../Horde/Support/CaseInsensitiveArray.php | 4 ++ lib/horde/framework/Horde/Support/Guid.php | 2 +- lib/horde/framework/Horde/Support/Stub.php | 6 +++ lib/horde/readme_moodle.txt | 9 ++-- 67 files changed, 678 insertions(+), 160 deletions(-) diff --git a/lib/horde/framework/Horde/Crypt/Blowfish/Openssl.php b/lib/horde/framework/Horde/Crypt/Blowfish/Openssl.php index c03191f8ad7..c799932f495 100644 --- a/lib/horde/framework/Horde/Crypt/Blowfish/Openssl.php +++ b/lib/horde/framework/Horde/Crypt/Blowfish/Openssl.php @@ -26,7 +26,12 @@ class Horde_Crypt_Blowfish_Openssl extends Horde_Crypt_Blowfish_Base */ public static function supported() { - return extension_loaded('openssl'); + if (extension_loaded('openssl')) { + $ciphers = openssl_get_cipher_methods(); + return in_array('bf-ecb', $ciphers) && in_array('bf-cbc', $ciphers); + } + + return false; } /** diff --git a/lib/horde/framework/Horde/Domhtml.php b/lib/horde/framework/Horde/Domhtml.php index 33ccd66266c..234c4dd804b 100644 --- a/lib/horde/framework/Horde/Domhtml.php +++ b/lib/horde/framework/Horde/Domhtml.php @@ -265,6 +265,7 @@ class Horde_Domhtml implements Iterator /** */ + #[ReturnTypeWillChange] public function current() { if ($this->_iterator instanceof DOMDocument) { @@ -277,6 +278,7 @@ class Horde_Domhtml implements Iterator /** */ + #[ReturnTypeWillChange] public function key() { return 0; @@ -284,6 +286,7 @@ class Horde_Domhtml implements Iterator /** */ + #[ReturnTypeWillChange] public function next() { /* Iterate in the reverse direction through the node list. This allows @@ -321,6 +324,7 @@ class Horde_Domhtml implements Iterator /** */ + #[ReturnTypeWillChange] public function rewind() { $this->_iterator = $this->dom; @@ -328,6 +332,7 @@ class Horde_Domhtml implements Iterator /** */ + #[ReturnTypeWillChange] public function valid() { return !is_null($this->_iterator); diff --git a/lib/horde/framework/Horde/Exception/LastError.php b/lib/horde/framework/Horde/Exception/LastError.php index a66e195b53c..cbe79059326 100644 --- a/lib/horde/framework/Horde/Exception/LastError.php +++ b/lib/horde/framework/Horde/Exception/LastError.php @@ -48,7 +48,7 @@ class Horde_Exception_LastError extends Horde_Exception $this->file = $code_or_lasterror['file']; $this->line = $code_or_lasterror['line']; } else { - parent::__construct($message, $code_or_lasterror); + parent::__construct($message, $code_or_lasterror ?? 0); } } diff --git a/lib/horde/framework/Horde/Exception/PermissionDenied.php b/lib/horde/framework/Horde/Exception/PermissionDenied.php index afd1d86b93c..3edd25181d3 100644 --- a/lib/horde/framework/Horde/Exception/PermissionDenied.php +++ b/lib/horde/framework/Horde/Exception/PermissionDenied.php @@ -27,7 +27,7 @@ class Horde_Exception_PermissionDenied extends Horde_Exception * * @see Horde_Exception::__construct() * - * @param mixed $message The exception message, a PEAR_Error + * @param string|Exception $message The exception message, a PEAR_Error * object, or an Exception object. * @param integer $code A numeric error code. */ diff --git a/lib/horde/framework/Horde/Idna.php b/lib/horde/framework/Horde/Idna.php index 1380682cbc1..f2ecbe81a8c 100644 --- a/lib/horde/framework/Horde/Idna.php +++ b/lib/horde/framework/Horde/Idna.php @@ -36,9 +36,15 @@ class Horde_Idna { switch ($backend = static::_getBackend()) { case 'INTL': + if ($data === null) { + return false; + } return idn_to_ascii($data); case 'INTL_UTS46': + if ($data === null) { + return false; + } $result = idn_to_ascii($data, 0, INTL_IDNA_VARIANT_UTS46, $info); self::_checkForError($info); return $result; diff --git a/lib/horde/framework/Horde/Imap/Client/Base.php b/lib/horde/framework/Horde/Imap/Client/Base.php index 6d596992e9f..f6eb80ee21a 100644 --- a/lib/horde/framework/Horde/Imap/Client/Base.php +++ b/lib/horde/framework/Horde/Imap/Client/Base.php @@ -232,7 +232,7 @@ implements Serializable, SplObserver * DEFAULT: 30 seconds * - username: (string) [REQUIRED] The username. * - authusername (string) The username used for SASL authentication. - * If specified this is the user name whose password is used + * If specified this is the user name whose password is used * (e.g. administrator). * Only valid for RFC 2595/4616 - PLAIN SASL mechanism. * DEFAULT: the same value provided in the username parameter. @@ -346,6 +346,7 @@ implements Serializable, SplObserver /** */ + #[ReturnTypeWillChange] public function update(SplSubject $subject) { if (($subject instanceof Horde_Imap_Client_Data_Capability) || @@ -363,11 +364,7 @@ implements Serializable, SplObserver */ public function serialize() { - return serialize(array( - 'i' => $this->_init, - 'p' => $this->_params, - 'v' => self::VERSION - )); + return serialize($this->__serialize()); } /** @@ -375,9 +372,27 @@ implements Serializable, SplObserver public function unserialize($data) { $data = @unserialize($data); - if (!is_array($data) || - !isset($data['v']) || - ($data['v'] != self::VERSION)) { + if (!is_array($data)) { + throw new Exception('Cache version change'); + } + $this->__unserialize($data); + } + + /** + * @return array + */ + public function __serialize() + { + return array( + 'i' => $this->_init, + 'p' => $this->_params, + 'v' => self::VERSION + ); + } + + public function __unserialize(array $data) + { + if (empty($data['v']) || $data['v'] != self::VERSION) { throw new Exception('Cache version change'); } @@ -3993,9 +4008,8 @@ implements Serializable, SplObserver $vanished = $this->vanished($this->_selected, $modseq, array( 'ids' => $uids_ob )); - $disappear = array_diff($uids_ob->ids, $vanished->ids); - if (!empty($disappear)) { - $this->_deleteMsgs($this->_selected, $this->getIdsOb($disappear)); + if (!empty($vanished->ids)) { + $this->_deleteMsgs($this->_selected, $this->getIdsOb($vanished->ids)); } $mbox_ob->sync = true; diff --git a/lib/horde/framework/Horde/Imap/Client/Base/Alerts.php b/lib/horde/framework/Horde/Imap/Client/Base/Alerts.php index aae072df09d..a481688848d 100644 --- a/lib/horde/framework/Horde/Imap/Client/Base/Alerts.php +++ b/lib/horde/framework/Horde/Imap/Client/Base/Alerts.php @@ -73,6 +73,7 @@ implements SplSubject /** */ + #[ReturnTypeWillChange] public function attach(SplObserver $observer) { $this->detach($observer); @@ -81,6 +82,7 @@ implements SplSubject /** */ + #[ReturnTypeWillChange] public function detach(SplObserver $observer) { if (($key = array_search($observer, $this->_observers, true)) !== false) { @@ -92,6 +94,7 @@ implements SplSubject * Notification is triggered internally whenever the object's internal * data storage is altered. */ + #[ReturnTypeWillChange] public function notify() { foreach ($this->_observers as $val) { diff --git a/lib/horde/framework/Horde/Imap/Client/Cache/Backend.php b/lib/horde/framework/Horde/Imap/Client/Cache/Backend.php index 02bdc1fb5b1..610b26ad0ec 100644 --- a/lib/horde/framework/Horde/Imap/Client/Cache/Backend.php +++ b/lib/horde/framework/Horde/Imap/Client/Cache/Backend.php @@ -151,15 +151,27 @@ abstract class Horde_Imap_Client_Cache_Backend implements Serializable */ public function serialize() { - return serialize($this->_params); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $this->_params = unserialize($data); - $this->_initOb(); + $this->__unserialize(unserialize($data)); + } + + /** + * @return array + */ + public function __serialize() + { + return $this->_params; + } + + public function __unserialize(array $data) + { + $this->_params = $data; } } diff --git a/lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php b/lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php index 536b81bd444..378be889217 100644 --- a/lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php +++ b/lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php @@ -498,9 +498,17 @@ extends Horde_Imap_Client_Cache_Backend /** */ public function serialize() + { + return $this->__serialize(); + } + + /** + * @return array + */ + public function __serialize() { $this->save(); - return parent::serialize(); + return parent::__serialize(); } } diff --git a/lib/horde/framework/Horde/Imap/Client/Data/Acl.php b/lib/horde/framework/Horde/Imap/Client/Data/Acl.php index 828da44082c..69e8e51139e 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/Acl.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/Acl.php @@ -100,6 +100,7 @@ class Horde_Imap_Client_Data_Acl extends Horde_Imap_Client_Data_AclCommon implem /** */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return $this[$offset]; @@ -107,6 +108,7 @@ class Horde_Imap_Client_Data_Acl extends Horde_Imap_Client_Data_AclCommon implem /** */ + #[ReturnTypeWillChange] public function offsetGet($offset) { return in_array($offset, $this->_rights); @@ -114,6 +116,7 @@ class Horde_Imap_Client_Data_Acl extends Horde_Imap_Client_Data_AclCommon implem /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { if ($value) { @@ -133,6 +136,7 @@ class Horde_Imap_Client_Data_Acl extends Horde_Imap_Client_Data_AclCommon implem /** */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { $this->_rights = array_values(array_diff($this->_rights, array($offset))); @@ -140,6 +144,7 @@ class Horde_Imap_Client_Data_Acl extends Horde_Imap_Client_Data_AclCommon implem /* IteratorAggregate method. */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_rights); @@ -151,14 +156,33 @@ class Horde_Imap_Client_Data_Acl extends Horde_Imap_Client_Data_AclCommon implem */ public function serialize() { - return json_encode($this->_rights); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $this->_rights = json_decode($data); + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version changed.'); + } + $this->__unserialize($data); + } + + /** + * @return array + */ + public function __serialize() + { + return array( + 'rights' => $this->_rights + ); + } + + public function __unserialize(array $data) + { + $this->_rights = $data['rights']; } } diff --git a/lib/horde/framework/Horde/Imap/Client/Data/AclRights.php b/lib/horde/framework/Horde/Imap/Client/Data/AclRights.php index 9666d1b3774..2a9c0d181be 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/AclRights.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/AclRights.php @@ -94,6 +94,7 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon /** */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return (bool)$this[$offset]; @@ -101,6 +102,7 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon /** */ + #[ReturnTypeWillChange] public function offsetGet($offset) { if (isset($this->_optional[$offset])) { @@ -116,6 +118,7 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->_optional[$offset] = $value; @@ -124,6 +127,7 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon /** */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->_optional[$offset]); @@ -140,6 +144,7 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon /** */ + #[ReturnTypeWillChange] public function current() { $val = current($this->_required); @@ -150,6 +155,7 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon /** */ + #[ReturnTypeWillChange] public function key() { $key = key($this->_required); @@ -160,6 +166,7 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon /** */ + #[ReturnTypeWillChange] public function next() { if (key($this->_required) === null) { @@ -171,6 +178,7 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon /** */ + #[ReturnTypeWillChange] public function rewind() { reset($this->_required); @@ -179,6 +187,7 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon /** */ + #[ReturnTypeWillChange] public function valid() { return ((key($this->_required) !== null) || @@ -192,17 +201,31 @@ class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon */ public function serialize() { - return json_encode(array( - $this->_required, - $this->_optional - )); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - list($this->_required, $this->_optional) = json_decode($data); + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version changed.'); + } + $this->__unserialize($data); + } + + /** + * @return array + */ + public function __serialize() + { + return [$this->_required, $this->_optional]; + } + + public function __unserialize(array $data) + { + list($this->_required, $this->_optional) = $data; } } diff --git a/lib/horde/framework/Horde/Imap/Client/Data/Capability.php b/lib/horde/framework/Horde/Imap/Client/Data/Capability.php index 81a710cf23c..e5c1eb97648 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/Capability.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/Capability.php @@ -169,6 +169,7 @@ implements Serializable, SplSubject /** */ + #[ReturnTypeWillChange] public function attach(SplObserver $observer) { $this->detach($observer); @@ -177,6 +178,7 @@ implements Serializable, SplSubject /** */ + #[ReturnTypeWillChange] public function detach(SplObserver $observer) { if (($key = array_search($observer, $this->_observers, true)) !== false) { @@ -188,6 +190,7 @@ implements Serializable, SplSubject * Notification is triggered internally whenever the object's internal * data storage is altered. */ + #[ReturnTypeWillChange] public function notify() { foreach ($this->_observers as $val) { @@ -201,14 +204,31 @@ implements Serializable, SplSubject */ public function serialize() { - return json_encode($this->_data); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $this->_data = json_decode($data, true); + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version change.'); + } + $this->__unserialize(); + } + + /** + * @return array + */ + public function __serialize() + { + return $this->_data; + } + + public function __unserialize(array $data) + { + $this->_data = $data; } } diff --git a/lib/horde/framework/Horde/Imap/Client/Data/Envelope.php b/lib/horde/framework/Horde/Imap/Client/Data/Envelope.php index a1404e20286..098b2e4d198 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/Envelope.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/Envelope.php @@ -205,18 +205,30 @@ class Horde_Imap_Client_Data_Envelope implements Serializable */ public function serialize() { - return serialize(array( - 'd' => $this->_data, - 'v' => self::VERSION - )); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $data = @unserialize($data); - if (empty($data['v']) || ($data['v'] != self::VERSION)) { + $this->__unserialize(@unserialize($data)); + } + + /** + * @return array + */ + public function __serialize() + { + return array( + 'd' => $this->_data, + 'v' => self::VERSION, + ); + } + + public function __unserialize(array $data) + { + if (empty($data['v']) || $data['v'] != self::VERSION) { throw new Exception('Cache version change'); } diff --git a/lib/horde/framework/Horde/Imap/Client/Data/Fetch.php b/lib/horde/framework/Horde/Imap/Client/Data/Fetch.php index 4a476ef3b53..458da659c0c 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/Fetch.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/Fetch.php @@ -618,14 +618,14 @@ class Horde_Imap_Client_Data_Fetch case Horde_Imap_Client::FETCH_HEADERTEXT: case Horde_Imap_Client::FETCH_MIMEHEADER: - $hdrs = $this->_data[$key][$id]; - break; + return Horde_Mime_Headers::parseHeaders($this->_data[$key][$id]); } } else { $hdrs = $this->_getHeaders($id, self::HEADER_STREAM, $key); + $parsed = Horde_Mime_Headers::parseHeaders($hdrs); + fclose($hdrs); + return $parsed; } - - return Horde_Mime_Headers::parseHeaders($hdrs); } if (!isset($this->_data[$key][$id])) { diff --git a/lib/horde/framework/Horde/Imap/Client/Data/Format/Filter/Quote.php b/lib/horde/framework/Horde/Imap/Client/Data/Format/Filter/Quote.php index 0196741e0db..1f652b2e312 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/Format/Filter/Quote.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/Format/Filter/Quote.php @@ -31,6 +31,7 @@ class Horde_Imap_Client_Data_Format_Filter_Quote extends php_user_filter /** */ + #[ReturnTypeWillChange] public function onCreate() { $this->_prepend = false; @@ -39,6 +40,7 @@ class Horde_Imap_Client_Data_Format_Filter_Quote extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { if (!$this->_prepend) { diff --git a/lib/horde/framework/Horde/Imap/Client/Data/Format/Filter/String.php b/lib/horde/framework/Horde/Imap/Client/Data/Format/Filter/String.php index 4ed20244701..0ddd081da52 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/Format/Filter/String.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/Format/Filter/String.php @@ -33,6 +33,7 @@ class Horde_Imap_Client_Data_Format_Filter_String extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function onCreate() { $this->params->binary = false; @@ -47,6 +48,7 @@ class Horde_Imap_Client_Data_Format_Filter_String extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { $p = $this->params; diff --git a/lib/horde/framework/Horde/Imap/Client/Data/Format/List.php b/lib/horde/framework/Horde/Imap/Client/Data/Format/List.php index 1aae9b7df59..075fb1b5857 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/Format/List.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/Format/List.php @@ -88,6 +88,7 @@ class Horde_Imap_Client_Data_Format_List extends Horde_Imap_Client_Data_Format i /** */ + #[ReturnTypeWillChange] public function count() { return count($this->_data); @@ -98,6 +99,7 @@ class Horde_Imap_Client_Data_Format_List extends Horde_Imap_Client_Data_Format i /** * Iterator loops through the data elements contained in this list. */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_data); diff --git a/lib/horde/framework/Horde/Imap/Client/Data/Namespace.php b/lib/horde/framework/Horde/Imap/Client/Data/Namespace.php index e85be6559dc..61e3f35f9d5 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/Namespace.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/Namespace.php @@ -130,14 +130,31 @@ class Horde_Imap_Client_Data_Namespace implements Serializable */ public function serialize() { - return json_encode($this->_data); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $this->_data = json_decode($data, true); + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version change.'); + } + $this->__unserialize($data); + } + + /** + * @return array + */ + public function __serialize() + { + return $this->_data; + } + + public function __unserialize(array $data) + { + $this->_data = $data; } } diff --git a/lib/horde/framework/Horde/Imap/Client/Data/SearchCharset.php b/lib/horde/framework/Horde/Imap/Client/Data/SearchCharset.php index 6c6b7cc122a..181c285f995 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/SearchCharset.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/SearchCharset.php @@ -133,6 +133,7 @@ implements Serializable, SplSubject /** */ + #[ReturnTypeWillChange] public function attach(SplObserver $observer) { $this->detach($observer); @@ -141,6 +142,7 @@ implements Serializable, SplSubject /** */ + #[ReturnTypeWillChange] public function detach(SplObserver $observer) { if (($key = array_search($observer, $this->_observers, true)) !== false) { @@ -152,6 +154,7 @@ implements Serializable, SplSubject * Notification is triggered internally whenever the object's internal * data storage is altered. */ + #[ReturnTypeWillChange] public function notify() { foreach ($this->_observers as $val) { @@ -165,14 +168,31 @@ implements Serializable, SplSubject */ public function serialize() { - return json_encode($this->_charsets); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $this->_charsets = json_decode($data, true); + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version change'); + } + $this->__unserialize($data); + } + + /** + * @return array + */ + public function __serialize() + { + return $this->_charsets; + } + + public function __unserialize(array $data) + { + $this->_charsets = $data; } } diff --git a/lib/horde/framework/Horde/Imap/Client/Data/SearchCharset/Utf8.php b/lib/horde/framework/Horde/Imap/Client/Data/SearchCharset/Utf8.php index 9465df11731..a842020d72d 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/SearchCharset/Utf8.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/SearchCharset/Utf8.php @@ -63,4 +63,16 @@ extends Horde_Imap_Client_Data_SearchCharset { } + /** + * @return array + */ + public function __serialize() + { + return array(); + } + + public function __unserialize(array $data) + { + } + } diff --git a/lib/horde/framework/Horde/Imap/Client/Data/Thread.php b/lib/horde/framework/Horde/Imap/Client/Data/Thread.php index 0fc857e9c09..391dab7efc5 100644 --- a/lib/horde/framework/Horde/Imap/Client/Data/Thread.php +++ b/lib/horde/framework/Horde/Imap/Client/Data/Thread.php @@ -171,6 +171,7 @@ class Horde_Imap_Client_Data_Thread implements Countable, Serializable /** */ + #[ReturnTypeWillChange] public function count() { return count($this->_getAllIndices()); @@ -182,17 +183,31 @@ class Horde_Imap_Client_Data_Thread implements Countable, Serializable */ public function serialize() { - return json_encode(array( - $this->_thread, - $this->_type - )); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - list($this->_thread, $this->_type) = json_decode($data, true); + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version changed.'); + } + $this->__unserialize($data); + } + + /** + * @return array + */ + public function __serialize() + { + return [$this->_thread, $this->_type]; + } + + public function __unserialize(array $data) + { + list($this->_thread, $this->_type) = $data; } /* Protected methods. */ diff --git a/lib/horde/framework/Horde/Imap/Client/DateTime.php b/lib/horde/framework/Horde/Imap/Client/DateTime.php index 8cdf1e81358..f7225b7cdf9 100644 --- a/lib/horde/framework/Horde/Imap/Client/DateTime.php +++ b/lib/horde/framework/Horde/Imap/Client/DateTime.php @@ -35,7 +35,7 @@ class Horde_Imap_Client_DateTime extends DateTime /* Bug #14381 Catch malformed offset - which doesn't cause DateTime to throw exception. */ - if (substr(rtrim($time), -5) === ' 0000') { + if ($time !== null && substr(rtrim($time), -5) === ' 0000') { $time = substr(trim($time), 0, strlen(trim($time)) - 5) . ' +0000'; try { if ($bug_67118) { @@ -48,15 +48,15 @@ class Horde_Imap_Client_DateTime extends DateTime try { if ($bug_67118) { - new DateTime($time, $tz); + new DateTime($time === null ? 'now' : $time, $tz); } - parent::__construct($time, $tz); + parent::__construct($time === null ? 'now' : $time, $tz); return; } catch (Exception $e) {} /* Check for malformed day-of-week parts, usually incorrectly * localized. E.g. Fr, 15 Apr 2016 15:15:09 +0000 */ - if (!preg_match("/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun),/", $time)) { + if ($time !== null && !preg_match("/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun),/", $time)) { $time = preg_replace("/^(\S*,)/", '', $time, 1, $i); if ($i) { try { @@ -70,7 +70,7 @@ class Horde_Imap_Client_DateTime extends DateTime } /* Bug #5717 - Check for UT vs. UTC. */ - if (substr(rtrim($time), -3) === ' UT') { + if ($time !== null && substr(rtrim($time), -3) === ' UT') { try { if ($bug_67118) { new DateTime($time . 'C', $tz); diff --git a/lib/horde/framework/Horde/Imap/Client/Exception.php b/lib/horde/framework/Horde/Imap/Client/Exception.php index ef60af69e0c..dce0d144884 100644 --- a/lib/horde/framework/Horde/Imap/Client/Exception.php +++ b/lib/horde/framework/Horde/Imap/Client/Exception.php @@ -253,7 +253,7 @@ class Horde_Imap_Client_Exception extends Horde_Exception_Wrapped * Constructor. * * @param string $message Error message (non-translated). - * @param code $code Error code. + * @param int $code Error code. */ public function __construct($message = null, $code = null) { diff --git a/lib/horde/framework/Horde/Imap/Client/Fetch/Query.php b/lib/horde/framework/Horde/Imap/Client/Fetch/Query.php index 04022fe0f33..efa35a92d5c 100644 --- a/lib/horde/framework/Horde/Imap/Client/Fetch/Query.php +++ b/lib/horde/framework/Horde/Imap/Client/Fetch/Query.php @@ -302,6 +302,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->_data[$offset]); @@ -309,6 +310,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function offsetGet($offset) { return isset($this->_data[$offset]) @@ -318,6 +320,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->_data[$offset] = $value; @@ -325,6 +328,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->_data[$offset]); @@ -334,6 +338,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function count() { return count($this->_data); @@ -343,6 +348,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function current() { $opts = current($this->_data); @@ -354,6 +360,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function key() { return key($this->_data); @@ -361,6 +368,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function next() { next($this->_data); @@ -368,6 +376,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function rewind() { reset($this->_data); @@ -375,6 +384,7 @@ class Horde_Imap_Client_Fetch_Query implements ArrayAccess, Countable, Iterator /** */ + #[ReturnTypeWillChange] public function valid() { return !is_null($this->key()); diff --git a/lib/horde/framework/Horde/Imap/Client/Fetch/Results.php b/lib/horde/framework/Horde/Imap/Client/Fetch/Results.php index eb50ea18927..e0cb1e87cee 100644 --- a/lib/horde/framework/Horde/Imap/Client/Fetch/Results.php +++ b/lib/horde/framework/Horde/Imap/Client/Fetch/Results.php @@ -132,6 +132,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->_data[$offset]); @@ -139,6 +140,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetGet($offset) { return isset($this->_data[$offset]) @@ -148,6 +150,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->_data[$offset] = $value; @@ -155,6 +158,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->_data[$offset]); @@ -164,6 +168,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function count() { return count($this->_data); @@ -173,6 +178,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function getIterator() { ksort($this->_data); diff --git a/lib/horde/framework/Horde/Imap/Client/Ids.php b/lib/horde/framework/Horde/Imap/Client/Ids.php index 314964e39a9..f70c5c8f466 100644 --- a/lib/horde/framework/Horde/Imap/Client/Ids.php +++ b/lib/horde/framework/Horde/Imap/Client/Ids.php @@ -377,6 +377,7 @@ class Horde_Imap_Client_Ids implements Countable, Iterator, Serializable /** */ + #[ReturnTypeWillChange] public function count() { return is_array($this->_ids) @@ -388,6 +389,7 @@ class Horde_Imap_Client_Ids implements Countable, Iterator, Serializable /** */ + #[ReturnTypeWillChange] public function current() { return is_array($this->_ids) @@ -397,6 +399,7 @@ class Horde_Imap_Client_Ids implements Countable, Iterator, Serializable /** */ + #[ReturnTypeWillChange] public function key() { return is_array($this->_ids) @@ -406,6 +409,7 @@ class Horde_Imap_Client_Ids implements Countable, Iterator, Serializable /** */ + #[ReturnTypeWillChange] public function next() { if (is_array($this->_ids)) { @@ -415,6 +419,7 @@ class Horde_Imap_Client_Ids implements Countable, Iterator, Serializable /** */ + #[ReturnTypeWillChange] public function rewind() { if (is_array($this->_ids)) { @@ -424,16 +429,30 @@ class Horde_Imap_Client_Ids implements Countable, Iterator, Serializable /** */ + #[ReturnTypeWillChange] public function valid() { return !is_null($this->key()); } - /* Serializable methods. */ + public function serialize() + { + return serialize($this->__serialize()); + } + + public function unserialize($data) + { + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version change.'); + } + + $this->__unserialize($data); + } /** */ - public function serialize() + public function __serialize() { $save = array(); @@ -467,27 +486,25 @@ class Horde_Imap_Client_Ids implements Countable, Iterator, Serializable break; } - return serialize($save); + return $save; } /** */ - public function unserialize($data) + public function __unserialize($data) { - $save = @unserialize($data); + $this->duplicates = !empty($data['d']); + $this->_sequence = !empty($data['s']); + $this->_sorted = !empty($data['is']); - $this->duplicates = !empty($save['d']); - $this->_sequence = !empty($save['s']); - $this->_sorted = !empty($save['is']); - - if (isset($save['a'])) { + if (isset($data['a'])) { $this->_ids = self::ALL; - } elseif (isset($save['l'])) { + } elseif (isset($data['l'])) { $this->_ids = self::LARGEST; - } elseif (isset($save['sr'])) { + } elseif (isset($data['sr'])) { $this->_ids = self::SEARCH_RES; - } elseif (isset($save['i'])) { - $this->add($save['i']); + } elseif (isset($data['i'])) { + $this->add($data['i']); } } diff --git a/lib/horde/framework/Horde/Imap/Client/Ids/Map.php b/lib/horde/framework/Horde/Imap/Client/Ids/Map.php index 87d85ab2e90..b2b6f87704a 100644 --- a/lib/horde/framework/Horde/Imap/Client/Ids/Map.php +++ b/lib/horde/framework/Horde/Imap/Client/Ids/Map.php @@ -196,6 +196,7 @@ class Horde_Imap_Client_Ids_Map implements Countable, IteratorAggregate, Seriali /** */ + #[ReturnTypeWillChange] public function count() { return count($this->_ids); @@ -205,6 +206,7 @@ class Horde_Imap_Client_Ids_Map implements Countable, IteratorAggregate, Seriali /** */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_ids); @@ -212,25 +214,37 @@ class Horde_Imap_Client_Ids_Map implements Countable, IteratorAggregate, Seriali /* Serializable methods. */ - /** - */ public function serialize() { - /* Sort before storing; provides more compressible representation. */ - $this->sort(); + return serialize($this->__serialize()); + } - return json_encode(array( - strval(new Horde_Imap_Client_Ids(array_keys($this->_ids))), - strval(new Horde_Imap_Client_Ids(array_values($this->_ids))) - )); + public function unserialize($data) + { + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version change.'); + } + $this->__unserialize($data); } /** */ - public function unserialize($data) + public function __serialize() { - $data = json_decode($data, true); + /* Sort before storing; provides more compressible representation. */ + $this->sort(); + return [ + strval(new Horde_Imap_Client_Ids(array_keys($this->_ids))), + strval(new Horde_Imap_Client_Ids(array_values($this->_ids))) + ]; + } + + /** + */ + public function __unserialize($data) + { $keys = new Horde_Imap_Client_Ids($data[0]); $vals = new Horde_Imap_Client_Ids($data[1]); $this->_ids = array_combine($keys->ids, $vals->ids); diff --git a/lib/horde/framework/Horde/Imap/Client/Interaction/Pipeline.php b/lib/horde/framework/Horde/Imap/Client/Interaction/Pipeline.php index ea4304d1b6b..1c99a9a1506 100644 --- a/lib/horde/framework/Horde/Imap/Client/Interaction/Pipeline.php +++ b/lib/horde/framework/Horde/Imap/Client/Interaction/Pipeline.php @@ -143,6 +143,7 @@ class Horde_Imap_Client_Interaction_Pipeline implements Countable, IteratorAggre /** */ + #[ReturnTypeWillChange] public function count() { return count($this->_commands); @@ -152,6 +153,7 @@ class Horde_Imap_Client_Interaction_Pipeline implements Countable, IteratorAggre /** */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_commands); diff --git a/lib/horde/framework/Horde/Imap/Client/Mailbox.php b/lib/horde/framework/Horde/Imap/Client/Mailbox.php index cd5686302dc..0064274c48f 100644 --- a/lib/horde/framework/Horde/Imap/Client/Mailbox.php +++ b/lib/horde/framework/Horde/Imap/Client/Mailbox.php @@ -134,14 +134,31 @@ class Horde_Imap_Client_Mailbox implements Serializable */ public function serialize() { - return json_encode(array($this->_utf7imap, $this->_utf8)); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - list($this->_utf7imap, $this->_utf8) = json_decode($data, true); + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache value changed.'); + } + $this->__unserialize($data); + } + + /** + * @return array + */ + public function __serialize() + { + return [$this->_utf7imap, $this->_utf8]; + } + + public function __unserialize(array $data) + { + list($this->_utf7imap, $this->_utf8) = $data; } } diff --git a/lib/horde/framework/Horde/Imap/Client/Mailbox/List.php b/lib/horde/framework/Horde/Imap/Client/Mailbox/List.php index d2b647cdd6c..d64498178bc 100644 --- a/lib/horde/framework/Horde/Imap/Client/Mailbox/List.php +++ b/lib/horde/framework/Horde/Imap/Client/Mailbox/List.php @@ -141,6 +141,7 @@ class Horde_Imap_Client_Mailbox_List implements Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function count() { return count($this->_mboxes); @@ -150,6 +151,7 @@ class Horde_Imap_Client_Mailbox_List implements Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_mboxes); diff --git a/lib/horde/framework/Horde/Imap/Client/Namespace/List.php b/lib/horde/framework/Horde/Imap/Client/Namespace/List.php index 032e7fab7b1..7c394204c54 100644 --- a/lib/horde/framework/Horde/Imap/Client/Namespace/List.php +++ b/lib/horde/framework/Horde/Imap/Client/Namespace/List.php @@ -77,6 +77,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->_ns[strval($offset)]); @@ -84,6 +85,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetGet($offset) { $offset = strval($offset); @@ -95,6 +97,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { if ($value instanceof Horde_Imap_Client_Data_Namespace) { @@ -104,6 +107,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->_ns[strval($offset)]); @@ -113,6 +117,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function count() { return count($this->_ns); @@ -122,6 +127,7 @@ implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_ns); diff --git a/lib/horde/framework/Horde/Imap/Client/Search/Query.php b/lib/horde/framework/Horde/Imap/Client/Search/Query.php index 0a4307d3d1a..179f8d46544 100644 --- a/lib/horde/framework/Horde/Imap/Client/Search/Query.php +++ b/lib/horde/framework/Horde/Imap/Client/Search/Query.php @@ -859,12 +859,27 @@ class Horde_Imap_Client_Search_Query implements Serializable /* Serializable methods. */ + public function serialize() + { + return serialize($this->__serialize()); + } + + public function unserialize($data) + { + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version change.'); + } + + $this->__unserialize($data); + } + /** * Serialization. * * @return string Serialized data. */ - public function serialize() + public function __serialize() { $data = array( // Serialized data ID. @@ -876,7 +891,7 @@ class Horde_Imap_Client_Search_Query implements Serializable $data[] = $this->_charset; } - return serialize($data); + return $data; } /** @@ -886,9 +901,8 @@ class Horde_Imap_Client_Search_Query implements Serializable * * @throws Exception */ - public function unserialize($data) + public function __unserialize($data) { - $data = @unserialize($data); if (!is_array($data) || !isset($data[0]) || ($data[0] != self::VERSION)) { diff --git a/lib/horde/framework/Horde/Imap/Client/Socket.php b/lib/horde/framework/Horde/Imap/Client/Socket.php index f9864b0074a..9fddb7d9a06 100644 --- a/lib/horde/framework/Horde/Imap/Client/Socket.php +++ b/lib/horde/framework/Horde/Imap/Client/Socket.php @@ -2951,7 +2951,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base case Horde_Imap_Client::FETCH_BODYPART: case Horde_Imap_Client::FETCH_HEADERS: foreach ($c_val as $key => $val) { - $cmd = ($key == 0) + $cmd = ((int)$key == 0) ? '' : $key . '.'; $main_cmd = 'BODY'; diff --git a/lib/horde/framework/Horde/Imap/Client/Tokenize.php b/lib/horde/framework/Horde/Imap/Client/Tokenize.php index 776b543ffeb..33ee4c32e17 100644 --- a/lib/horde/framework/Horde/Imap/Client/Tokenize.php +++ b/lib/horde/framework/Horde/Imap/Client/Tokenize.php @@ -220,6 +220,7 @@ class Horde_Imap_Client_Tokenize implements Iterator /** */ + #[ReturnTypeWillChange] public function current() { return $this->_current; @@ -227,6 +228,7 @@ class Horde_Imap_Client_Tokenize implements Iterator /** */ + #[ReturnTypeWillChange] public function key() { return $this->_key; @@ -236,6 +238,7 @@ class Horde_Imap_Client_Tokenize implements Iterator * @return mixed Either a string, boolean (true for open paren, false for * close paren/EOS), Horde_Stream object, or null. */ + #[ReturnTypeWillChange] public function next() { $level = isset($this->_nextModify['level']) @@ -395,6 +398,7 @@ class Horde_Imap_Client_Tokenize implements Iterator /** */ + #[ReturnTypeWillChange] public function rewind() { $this->_stream->rewind(); @@ -405,6 +409,7 @@ class Horde_Imap_Client_Tokenize implements Iterator /** */ + #[ReturnTypeWillChange] public function valid() { return ($this->_level !== false); diff --git a/lib/horde/framework/Horde/Imap/Client/Url.php b/lib/horde/framework/Horde/Imap/Client/Url.php index 563a1b24de4..68d1f38cbca 100644 --- a/lib/horde/framework/Horde/Imap/Client/Url.php +++ b/lib/horde/framework/Horde/Imap/Client/Url.php @@ -289,14 +289,31 @@ class Horde_Imap_Client_Url implements Serializable */ public function serialize() { - return strval($this); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $this->_parse($data); + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version changed'); + } + $this->__unserialize($data); + } + + /** + * @return array + */ + public function __serialize() + { + return array((string)$this); + } + + public function __unserialize(array $data) + { + $this->_parse($data[0]); } } diff --git a/lib/horde/framework/Horde/Imap/Client/Url/Base.php b/lib/horde/framework/Horde/Imap/Client/Url/Base.php index f1fc77ecc47..13742e92010 100644 --- a/lib/horde/framework/Horde/Imap/Client/Url/Base.php +++ b/lib/horde/framework/Horde/Imap/Client/Url/Base.php @@ -160,14 +160,31 @@ abstract class Horde_Imap_Client_Url_Base implements Serializable */ public function serialize() { - return strval($this); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $this->_parse($data); + $data = @unserialize($data); + if (!is_array($data)) { + throw new Exception('Cache version change.'); + } + $this->__unserialize($data); + } + + /** + * @return array + */ + public function __serialize() + { + return array((string)$this); + } + + public function __unserialize(array $data) + { + $this->_parse($data[0]); } } diff --git a/lib/horde/framework/Horde/Mail/Mbox/Parse.php b/lib/horde/framework/Horde/Mail/Mbox/Parse.php index fa2915143f2..6b4d6e13ceb 100644 --- a/lib/horde/framework/Horde/Mail/Mbox/Parse.php +++ b/lib/horde/framework/Horde/Mail/Mbox/Parse.php @@ -133,6 +133,7 @@ implements ArrayAccess, Countable, Iterator /** */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->_parsed[$offset]); @@ -140,6 +141,7 @@ implements ArrayAccess, Countable, Iterator /** */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { if (!isset($this->_parsed[$offset])) { @@ -179,6 +181,7 @@ implements ArrayAccess, Countable, Iterator /** */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { // NOOP @@ -186,6 +189,7 @@ implements ArrayAccess, Countable, Iterator /** */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { // NOOP @@ -198,6 +202,7 @@ implements ArrayAccess, Countable, Iterator * * @return integer The number of messages. */ + #[\ReturnTypeWillChange] public function count() { return count($this->_parsed); @@ -218,6 +223,7 @@ implements ArrayAccess, Countable, Iterator /* Iterator methods. */ + #[\ReturnTypeWillChange] public function current() { $key = $this->key(); @@ -227,11 +233,13 @@ implements ArrayAccess, Countable, Iterator : $this[$key]; } + #[\ReturnTypeWillChange] public function key() { return key($this->_parsed); } + #[\ReturnTypeWillChange] public function next() { if ($this->valid()) { @@ -239,11 +247,13 @@ implements ArrayAccess, Countable, Iterator } } + #[\ReturnTypeWillChange] public function rewind() { reset($this->_parsed); } + #[\ReturnTypeWillChange] public function valid() { return !is_null($this->key()); diff --git a/lib/horde/framework/Horde/Mail/Rfc822.php b/lib/horde/framework/Horde/Mail/Rfc822.php index 9b5eafa3ed1..a6ea2f42fec 100644 --- a/lib/horde/framework/Horde/Mail/Rfc822.php +++ b/lib/horde/framework/Horde/Mail/Rfc822.php @@ -406,7 +406,7 @@ class Horde_Mail_Rfc822 if ($this->_curr() == '@') { try { $this->_rfc822ParseDomain($host); - if (strlen($host)) { + if (!empty($host)) { $ob->host = $host; } } catch (Horde_Mail_Exception $e) { @@ -647,7 +647,7 @@ class Horde_Mail_Rfc822 /* TODO: Optimize by duplicating rfc822IsAtext code here */ !$this->_rfc822IsAtext($chr, ',<:')) { $this->_rfc822SkipLwsp(); - if (!$this->_params['validate']) { + if (!$this->_params['validate'] && $str !== null) { $str = trim($str); } return; diff --git a/lib/horde/framework/Horde/Mail/Rfc822/Address.php b/lib/horde/framework/Horde/Mail/Rfc822/Address.php index 1c525b1d2df..22c429c964f 100644 --- a/lib/horde/framework/Horde/Mail/Rfc822/Address.php +++ b/lib/horde/framework/Horde/Mail/Rfc822/Address.php @@ -99,7 +99,7 @@ class Horde_Mail_Rfc822_Address extends Horde_Mail_Rfc822_Object break; case 'personal': - $this->_personal = strlen($value) + $this->_personal = !empty($value) ? Horde_Mime::decode($value) : null; break; @@ -144,7 +144,7 @@ class Horde_Mail_Rfc822_Address extends Horde_Mail_Rfc822_Object : $this->_personal; case 'personal': - return (strcasecmp($this->_personal, $this->bare_address) === 0) + return $this->_personal === null || (strcasecmp($this->_personal, $this->bare_address) === 0) ? null : $this->_personal; @@ -152,7 +152,7 @@ class Horde_Mail_Rfc822_Address extends Horde_Mail_Rfc822_Object return Horde_Mime::encode($this->personal); case 'valid': - return (bool)strlen($this->mailbox); + return !empty($this->mailbox); } } @@ -164,11 +164,11 @@ class Horde_Mail_Rfc822_Address extends Horde_Mail_Rfc822_Object $address = $rfc822->encode($this->mailbox, 'address'); $host = empty($opts['idn']) ? $this->host : $this->host_idn; - if (strlen($host)) { + if (!empty($host)) { $address .= '@' . $host; } $personal = $this->personal; - if (strlen($personal)) { + if (!empty($personal)) { if (!empty($opts['encode'])) { $personal = Horde_Mime::encode($this->personal, $opts['encode']); } @@ -182,7 +182,7 @@ class Horde_Mail_Rfc822_Address extends Horde_Mail_Rfc822_Object } } - return (strlen($personal) && ($personal != $address)) + return (!empty($personal) && ($personal != $address)) ? ltrim($personal) . ' <' . $address . '>' : $address; } diff --git a/lib/horde/framework/Horde/Mail/Rfc822/Group.php b/lib/horde/framework/Horde/Mail/Rfc822/Group.php index 2c5b2cb97e8..638c1b17e68 100644 --- a/lib/horde/framework/Horde/Mail/Rfc822/Group.php +++ b/lib/horde/framework/Horde/Mail/Rfc822/Group.php @@ -137,6 +137,7 @@ class Horde_Mail_Rfc822_Group * * @return integer The number of addresses. */ + #[\ReturnTypeWillChange] public function count() { return count($this->addresses); diff --git a/lib/horde/framework/Horde/Mail/Rfc822/Identification.php b/lib/horde/framework/Horde/Mail/Rfc822/Identification.php index d726f875a81..6596eccacb7 100644 --- a/lib/horde/framework/Horde/Mail/Rfc822/Identification.php +++ b/lib/horde/framework/Horde/Mail/Rfc822/Identification.php @@ -44,11 +44,11 @@ class Horde_Mail_Rfc822_Identification extends Horde_Mail_Rfc822 /** * Parse an identification header. * - * @param string $value Identification field value to parse. + * @param string|null $value Identification field value to parse. */ public function parse($value) { - if (!strlen($value)) { + if (empty($value)) { return; } diff --git a/lib/horde/framework/Horde/Mail/Rfc822/List.php b/lib/horde/framework/Horde/Mail/Rfc822/List.php index 3011405ed2b..d098da1583e 100644 --- a/lib/horde/framework/Horde/Mail/Rfc822/List.php +++ b/lib/horde/framework/Horde/Mail/Rfc822/List.php @@ -331,6 +331,7 @@ class Horde_Mail_Rfc822_List /** */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return !is_null($this[$offset]); @@ -338,6 +339,7 @@ class Horde_Mail_Rfc822_List /** */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { try { @@ -350,6 +352,7 @@ class Horde_Mail_Rfc822_List /** */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { if ($ob = $this[$offset]) { @@ -367,6 +370,7 @@ class Horde_Mail_Rfc822_List /** */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { if ($ob = $this[$offset]) { @@ -387,6 +391,7 @@ class Horde_Mail_Rfc822_List * * @return integer The number of addresses. */ + #[\ReturnTypeWillChange] public function count() { return count($this->addresses); @@ -394,6 +399,7 @@ class Horde_Mail_Rfc822_List /* Iterator methods. */ + #[\ReturnTypeWillChange] public function current() { if (!$this->valid()) { @@ -407,11 +413,13 @@ class Horde_Mail_Rfc822_List : $ob->addresses[$this->_ptr['subidx']]; } + #[\ReturnTypeWillChange] public function key() { return $this->_ptr['key']; } + #[\ReturnTypeWillChange] public function next() { if (is_null($this->_ptr['subidx'])) { @@ -437,6 +445,7 @@ class Horde_Mail_Rfc822_List } } + #[\ReturnTypeWillChange] public function rewind() { $this->_ptr = array( @@ -453,11 +462,13 @@ class Horde_Mail_Rfc822_List } } + #[\ReturnTypeWillChange] public function valid() { return (!empty($this->_ptr) && isset($this->_data[$this->_ptr['idx']])); } + #[\ReturnTypeWillChange] public function seek($position) { if (!$this->valid() || @@ -515,4 +526,14 @@ class Horde_Mail_Rfc822_List $this->_data = unserialize($data); } + public function __serialize() { + return array( + 'data' => $this->_data + ); + } + + public function __unserialize(array $data) { + $this->_data = $data['data']; + } + } diff --git a/lib/horde/framework/Horde/Mail/Transport.php b/lib/horde/framework/Horde/Mail/Transport.php index 3481229df1f..eea77c8d202 100644 --- a/lib/horde/framework/Horde/Mail/Transport.php +++ b/lib/horde/framework/Horde/Mail/Transport.php @@ -208,7 +208,7 @@ abstract class Horde_Mail_Transport protected function _sanitizeHeaders($headers) { foreach (array_diff(array_keys($headers), array('_raw')) as $key) { - $headers[$key] = preg_replace('=((||0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i', null, $headers[$key]); + $headers[$key] = preg_replace('=((||0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i', '', $headers[$key]); } return $headers; @@ -251,7 +251,7 @@ abstract class Horde_Mail_Transport } } - if (!strlen($from)) { + if (empty($from)) { throw new Horde_Mail_Exception('No from address provided.'); } diff --git a/lib/horde/framework/Horde/Mime/Filter/Encoding.php b/lib/horde/framework/Horde/Mime/Filter/Encoding.php index eefcdc24a2e..8c8a0140cc2 100644 --- a/lib/horde/framework/Horde/Mime/Filter/Encoding.php +++ b/lib/horde/framework/Horde/Mime/Filter/Encoding.php @@ -34,6 +34,7 @@ class Horde_Mime_Filter_Encoding extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function onCreate() { $this->params->body = false; @@ -44,6 +45,7 @@ class Horde_Mime_Filter_Encoding extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { diff --git a/lib/horde/framework/Horde/Mime/Headers.php b/lib/horde/framework/Horde/Mime/Headers.php index 1b4a4b1dd1e..b801ab6a30f 100644 --- a/lib/horde/framework/Horde/Mime/Headers.php +++ b/lib/horde/framework/Horde/Mime/Headers.php @@ -388,15 +388,41 @@ implements ArrayAccess, IteratorAggregate, Serializable */ public function serialize() { - $data = array( + return serialize($this->__serialize()); + } + + /** + * Serialization. + * + * @return array Serialized data. + */ + public function __serialize(): array + { + return array( // Serialized data ID. self::VERSION, $this->_headers->getArrayCopy(), // TODO: BC $this->_eol ); + } - return serialize($data); + /** + * Unserialization. + * + * @param array $data Serialized data. + * + * @throws Horde_Mime_Exception + */ + public function __unserialize(array $data): void + { + if (!isset($data[0]) || ($data[0] != self::VERSION)) { + throw new Horde_Mime_Exception('Cache version change'); + } + + $this->_headers = new Horde_Support_CaseInsensitiveArray($data[1]); + // TODO: BC + $this->_eol = $data[2]; } /** @@ -409,15 +435,10 @@ implements ArrayAccess, IteratorAggregate, Serializable public function unserialize($data) { $data = @unserialize($data); - if (!is_array($data) || - !isset($data[0]) || - ($data[0] != self::VERSION)) { + if (!is_array($data)) { throw new Horde_Mime_Exception('Cache version change'); } - - $this->_headers = new Horde_Support_CaseInsensitiveArray($data[1]); - // TODO: BC - $this->_eol = $data[2]; + $this->__unserialize($data); } /* ArrayAccess methods. */ @@ -431,6 +452,7 @@ implements ArrayAccess, IteratorAggregate, Serializable * * @return boolean True if header exists. */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->_headers[trim($offset)]); @@ -446,6 +468,7 @@ implements ArrayAccess, IteratorAggregate, Serializable * @return Horde_Mime_Headers_Element Element object, or null if not * found. */ + #[ReturnTypeWillChange] public function offsetGet($offset) { return $this->_headers[trim($offset)]; @@ -459,6 +482,7 @@ implements ArrayAccess, IteratorAggregate, Serializable * @param string $offset Not used. * @param Horde_Mime_Headers_Element $elt Header element. */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->addHeaderOb($value); @@ -471,6 +495,7 @@ implements ArrayAccess, IteratorAggregate, Serializable * * @param string $offset Header name. */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->_headers[trim($offset)]); @@ -481,6 +506,7 @@ implements ArrayAccess, IteratorAggregate, Serializable /** * @since 2.5.0 */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_headers); diff --git a/lib/horde/framework/Horde/Mime/Headers/ContentParam.php b/lib/horde/framework/Horde/Mime/Headers/ContentParam.php index e61ba07519b..4d18c34f918 100644 --- a/lib/horde/framework/Horde/Mime/Headers/ContentParam.php +++ b/lib/horde/framework/Horde/Mime/Headers/ContentParam.php @@ -368,6 +368,7 @@ implements ArrayAccess, Horde_Mime_Headers_Extension_Mime, Serializable /** */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return isset($this->_params[$offset]); @@ -375,6 +376,7 @@ implements ArrayAccess, Horde_Mime_Headers_Extension_Mime, Serializable /** */ + #[ReturnTypeWillChange] public function offsetGet($offset) { return $this->_params[$offset]; @@ -382,6 +384,7 @@ implements ArrayAccess, Horde_Mime_Headers_Extension_Mime, Serializable /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->_params[$offset] = $this->_sanityCheck($value); @@ -389,6 +392,7 @@ implements ArrayAccess, Horde_Mime_Headers_Extension_Mime, Serializable /** */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->_params[$offset]); @@ -397,22 +401,36 @@ implements ArrayAccess, Horde_Mime_Headers_Extension_Mime, Serializable /* Serializable methods */ /** + * Serialize (until PHP 7.3) + * + * @return string serialized object state */ public function serialize() + { + return serialize($this->__serialize()); + } + + /** + * Serialize (PHP 7.4+) + * + * @return array object state + */ + public function __serialize(): array { $vars = array_filter(get_object_vars($this)); if (isset($vars['_params'])) { $vars['_params'] = $vars['_params']->getArrayCopy(); } - return serialize($vars); + return $vars; } /** + * Unserialize (PHP 7.4+) + * + * @param array $data */ - public function unserialize($data) + public function __unserialize(array $data): void { - $data = unserialize($data); - foreach ($data as $key => $val) { switch ($key) { case '_params': @@ -426,4 +444,14 @@ implements ArrayAccess, Horde_Mime_Headers_Extension_Mime, Serializable } } + /** + * Unserialize (until PHP 7.3) + * + * @param string $data + */ + public function unserialize($data) + { + $this->__unserialize(unserialize($data)); + } + } diff --git a/lib/horde/framework/Horde/Mime/Headers/ContentParam/ContentDisposition.php b/lib/horde/framework/Horde/Mime/Headers/ContentParam/ContentDisposition.php index 6bca2b56f7f..6439a663e85 100644 --- a/lib/horde/framework/Horde/Mime/Headers/ContentParam/ContentDisposition.php +++ b/lib/horde/framework/Horde/Mime/Headers/ContentParam/ContentDisposition.php @@ -90,6 +90,7 @@ extends Horde_Mime_Headers_ContentParam /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { if (strcasecmp($offset, 'size') === 0) { diff --git a/lib/horde/framework/Horde/Mime/Headers/Element.php b/lib/horde/framework/Horde/Mime/Headers/Element.php index de053ad2eb1..124cc89fa78 100644 --- a/lib/horde/framework/Horde/Mime/Headers/Element.php +++ b/lib/horde/framework/Horde/Mime/Headers/Element.php @@ -142,6 +142,9 @@ implements IteratorAggregate } /* Ensure no null characters exist in header data. */ + if ($data === null) { + return ''; + } return str_replace("\0", '', $data); } @@ -173,6 +176,7 @@ implements IteratorAggregate /** */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_values); diff --git a/lib/horde/framework/Horde/Mime/Part.php b/lib/horde/framework/Horde/Mime/Part.php index ca2a32f7424..a20760a4ff4 100644 --- a/lib/horde/framework/Horde/Mime/Part.php +++ b/lib/horde/framework/Horde/Mime/Part.php @@ -2229,6 +2229,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return ($this[$offset] !== null); @@ -2236,6 +2237,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** */ + #[ReturnTypeWillChange] public function offsetGet($offset) { $this->_reindex(); @@ -2261,6 +2263,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { if (is_null($offset)) { @@ -2280,6 +2283,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { if ($part = $this[$offset]) { @@ -2303,6 +2307,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable * * @return integer Number of message parts. */ + #[ReturnTypeWillChange] public function count() { return count($this->_parts); @@ -2313,6 +2318,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** * @since 2.8.0 */ + #[ReturnTypeWillChange] public function current() { return (($key = $this->key()) === null) @@ -2323,6 +2329,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** * @since 2.8.0 */ + #[ReturnTypeWillChange] public function key() { return (isset($this->_temp['iterate']) && isset($this->_parts[$this->_temp['iterate']])) @@ -2333,6 +2340,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** * @since 2.8.0 */ + #[ReturnTypeWillChange] public function next() { ++$this->_temp['iterate']; @@ -2341,6 +2349,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** * @since 2.8.0 */ + #[ReturnTypeWillChange] public function rewind() { $this->_reindex(); @@ -2351,6 +2360,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** * @since 2.8.0 */ + #[ReturnTypeWillChange] public function valid() { return ($this->key() !== null); @@ -2359,6 +2369,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** * @since 2.8.0 */ + #[ReturnTypeWillChange] public function hasChildren() { return (($curr = $this->current()) && count($curr)); @@ -2367,6 +2378,7 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable /** * @since 2.8.0 */ + #[ReturnTypeWillChange] public function getChildren() { return $this->current(); @@ -2380,6 +2392,11 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable * @return string Serialized data. */ public function serialize() + { + return serialize($this->__serialize()); + } + + public function __serialize(): array { $data = array( // Serialized data ID. @@ -2399,22 +2416,12 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable $data[] = $this->_readStream($this->_contents); } - return serialize($data); + return $data; } - /** - * Unserialization. - * - * @param string $data Serialized data. - * - * @throws Exception - */ - public function unserialize($data) + public function __unserialize(array $data): void { - $data = @unserialize($data); - if (!is_array($data) || - !isset($data[0]) || - ($data[0] != self::VERSION)) { + if (!isset($data[0]) || ($data[0] != self::VERSION)) { switch ($data[0]) { case 1: $convert = new Horde_Mime_Part_Upgrade_V1($data); @@ -2447,6 +2454,19 @@ implements ArrayAccess, Countable, RecursiveIterator, Serializable } } + /** + * Unserialization. + * + * @param string $data Serialized data. + * + * @throws Exception + */ + public function unserialize($data) + { + $data = @unserialize($data); + $this->__unserialize($data); + } + /* Deprecated elements. */ /** diff --git a/lib/horde/framework/Horde/Mime/Part/Iterator.php b/lib/horde/framework/Horde/Mime/Part/Iterator.php index 24b67ed4592..311172fa5c4 100644 --- a/lib/horde/framework/Horde/Mime/Part/Iterator.php +++ b/lib/horde/framework/Horde/Mime/Part/Iterator.php @@ -62,6 +62,7 @@ implements Countable, Iterator * * @return integer Number of message parts. */ + #[ReturnTypeWillChange] public function count() { return count(iterator_to_array($this)); @@ -71,6 +72,7 @@ implements Countable, Iterator /** */ + #[ReturnTypeWillChange] public function current() { return $this->valid() @@ -80,6 +82,7 @@ implements Countable, Iterator /** */ + #[ReturnTypeWillChange] public function key() { return ($curr = $this->current()) @@ -89,6 +92,7 @@ implements Countable, Iterator /** */ + #[ReturnTypeWillChange] public function next() { if (!isset($this->_state)) { @@ -115,6 +119,7 @@ implements Countable, Iterator /** */ + #[ReturnTypeWillChange] public function rewind() { $this->_state = new stdClass; @@ -129,6 +134,7 @@ implements Countable, Iterator /** */ + #[ReturnTypeWillChange] public function valid() { return !empty($this->_state); diff --git a/lib/horde/framework/Horde/Mime/Related.php b/lib/horde/framework/Horde/Mime/Related.php index 076c45888e4..252919d98e5 100644 --- a/lib/horde/framework/Horde/Mime/Related.php +++ b/lib/horde/framework/Horde/Mime/Related.php @@ -153,6 +153,7 @@ class Horde_Mime_Related implements IteratorAggregate /* IteratorAggregate method. */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_cids); diff --git a/lib/horde/framework/Horde/Mime/Uudecode.php b/lib/horde/framework/Horde/Mime/Uudecode.php index 89495299df3..42368748183 100644 --- a/lib/horde/framework/Horde/Mime/Uudecode.php +++ b/lib/horde/framework/Horde/Mime/Uudecode.php @@ -114,6 +114,7 @@ class Horde_Mime_Uudecode implements Countable, IteratorAggregate /* Countable method. */ + #[ReturnTypeWillChange] public function count() { return count($this->_data); @@ -121,6 +122,7 @@ class Horde_Mime_Uudecode implements Countable, IteratorAggregate /* IteratorAggregate method. */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_data); diff --git a/lib/horde/framework/Horde/Socket/Client.php b/lib/horde/framework/Horde/Socket/Client.php index a38d2233b2e..4d961c20c8f 100644 --- a/lib/horde/framework/Horde/Socket/Client.php +++ b/lib/horde/framework/Horde/Socket/Client.php @@ -144,7 +144,8 @@ class Client { if ($this->connected && !$this->secure) { if (defined('STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT')) { - $mode = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT + $mode = STREAM_CRYPTO_METHOD_TLS_CLIENT + | STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; } else { diff --git a/lib/horde/framework/Horde/Stream.php b/lib/horde/framework/Horde/Stream.php index 5052cc67a47..0ca1578381c 100644 --- a/lib/horde/framework/Horde/Stream.php +++ b/lib/horde/framework/Horde/Stream.php @@ -600,21 +600,40 @@ class Horde_Stream implements Serializable */ public function serialize() { - $this->_params['_pos'] = $this->pos(); - - return json_encode(array( - strval($this), - $this->_params - )); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $this->_init(); + $data = @unserialize($data, true); + if ($data == null || !is_array($data)) { + throw new Exception('Cache version change.'); + } + $this->__unserialize($data); + } - $data = json_decode($data, true); + /** + * @return array + */ + public function __serialize() + { + $this->_params['_pos'] = $this->pos(); + + return array( + strval($this), + $this->_params + ); + } + + /** + * @param array $data + * @return void + */ + public function __unserialize($data) + { + $this->_init(); $this->add($data[0]); $this->seek($data[1]['_pos'], false); unset($data[1]['_pos']); diff --git a/lib/horde/framework/Horde/Stream/Filter/Bin2hex.php b/lib/horde/framework/Horde/Stream/Filter/Bin2hex.php index fe802277cd9..43503135e85 100644 --- a/lib/horde/framework/Horde/Stream/Filter/Bin2hex.php +++ b/lib/horde/framework/Horde/Stream/Filter/Bin2hex.php @@ -22,6 +22,7 @@ class Horde_Stream_Filter_Bin2hex extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { diff --git a/lib/horde/framework/Horde/Stream/Filter/Crc32.php b/lib/horde/framework/Horde/Stream/Filter/Crc32.php index 8fb4372f697..a6a1ba08dd3 100644 --- a/lib/horde/framework/Horde/Stream/Filter/Crc32.php +++ b/lib/horde/framework/Horde/Stream/Filter/Crc32.php @@ -28,6 +28,7 @@ class Horde_Stream_Filter_Crc32 extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function onCreate() { $this->params->crc32 = 0; @@ -38,6 +39,7 @@ class Horde_Stream_Filter_Crc32 extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { diff --git a/lib/horde/framework/Horde/Stream/Filter/Eol.php b/lib/horde/framework/Horde/Stream/Filter/Eol.php index 89763ef47f3..7effb3f8ff6 100644 --- a/lib/horde/framework/Horde/Stream/Filter/Eol.php +++ b/lib/horde/framework/Horde/Stream/Filter/Eol.php @@ -56,6 +56,7 @@ class Horde_Stream_Filter_Eol extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function onCreate() { $eol = isset($this->params['eol']) @@ -82,6 +83,7 @@ class Horde_Stream_Filter_Eol extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { diff --git a/lib/horde/framework/Horde/Stream/Filter/Htmlspecialchars.php b/lib/horde/framework/Horde/Stream/Filter/Htmlspecialchars.php index e5383b38149..d3a52cb13f3 100644 --- a/lib/horde/framework/Horde/Stream/Filter/Htmlspecialchars.php +++ b/lib/horde/framework/Horde/Stream/Filter/Htmlspecialchars.php @@ -27,6 +27,7 @@ class Horde_Stream_Filter_Htmlspecialchars extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { diff --git a/lib/horde/framework/Horde/Stream/Filter/Null.php b/lib/horde/framework/Horde/Stream/Filter/Null.php index ef9a1a9117f..25d18795f2b 100644 --- a/lib/horde/framework/Horde/Stream/Filter/Null.php +++ b/lib/horde/framework/Horde/Stream/Filter/Null.php @@ -41,6 +41,7 @@ class Horde_Stream_Filter_Null extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function onCreate() { $this->_replace = isset($this->params->replace) @@ -53,6 +54,7 @@ class Horde_Stream_Filter_Null extends php_user_filter /** * @see stream_filter_register() */ + #[ReturnTypeWillChange] public function filter($in, $out, &$consumed, $closing) { while ($bucket = stream_bucket_make_writeable($in)) { diff --git a/lib/horde/framework/Horde/Stream/TempString.php b/lib/horde/framework/Horde/Stream/TempString.php index f83e1403e90..c80a8a08d26 100644 --- a/lib/horde/framework/Horde/Stream/TempString.php +++ b/lib/horde/framework/Horde/Stream/TempString.php @@ -251,28 +251,42 @@ class Horde_Stream_TempString extends Horde_Stream_Temp */ public function serialize() { - if ($this->_string) { - $data = array( - $this->_string, - $this->_params - ); - } else { - $data = parent::serialize(); - } - - return serialize($data); + return serialize($this->__serialize()); } /** */ public function unserialize($data) { - $data = unserialize($data); + $this->__unserialize(unserialize($data)); + } + + /** + * @return array + */ + public function __serialize() + { + if ($this->_string) { + return array( + $this->_string, + $this->_params + ); + } else { + return parent::__serialize(); + } + } + + /** + * @param array $data + * @return void + */ + public function __unserialize($data) + { if ($data[0] instanceof Horde_Stream_String) { $this->_string = $data[0]; $this->_params = $data[1]; } else { - parent::unserialize($data); + parent::__unserialize($data); } } diff --git a/lib/horde/framework/Horde/Stream/Wrapper/Combine.php b/lib/horde/framework/Horde/Stream/Wrapper/Combine.php index 80b723df1de..d7a4a751af6 100644 --- a/lib/horde/framework/Horde/Stream/Wrapper/Combine.php +++ b/lib/horde/framework/Horde/Stream/Wrapper/Combine.php @@ -171,9 +171,11 @@ class Horde_Stream_Wrapper_Combine } $curr_read = min($count, $tmp['l'] - $tmp['p']); - $out .= fread($tmp['fp'], $curr_read); - $count -= $curr_read; - $this->_position += $curr_read; + if ($curr_read > 0) { + $out .= fread($tmp['fp'], $curr_read); + $count -= $curr_read; + $this->_position += $curr_read; + } if ($this->_position == $this->_length) { if ($count) { diff --git a/lib/horde/framework/Horde/String.php b/lib/horde/framework/Horde/String.php index 9e6e16b0091..ff4f00a5c6c 100644 --- a/lib/horde/framework/Horde/String.php +++ b/lib/horde/framework/Horde/String.php @@ -157,9 +157,13 @@ class Horde_String /* Try mbstring. */ if (Horde_Util::extensionExists('mbstring')) { - $out = @mb_convert_encoding($input, $to, self::_mbstringCharset($from)); - if (!empty($out)) { - return $out; + try { + $out = @mb_convert_encoding($input, $to, self::_mbstringCharset($from)); + if (!empty($out)) { + return $out; + } + } catch (ValueError $e) { + // catch error thrown under PHP 8.0, if mbstring does not support the encoding } } @@ -195,7 +199,11 @@ class Horde_String if (!isset(self::$_lowers[$string])) { $language = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'C'); - self::$_lowers[$string] = strtolower($string); + if ($string === null) { + self::$_lowers[$string] = ''; + } else { + self::$_lowers[$string] = strtolower($string); + } setlocale(LC_CTYPE, $language); } diff --git a/lib/horde/framework/Horde/Support/Array.php b/lib/horde/framework/Horde/Support/Array.php index 590eb622269..958e5e78984 100644 --- a/lib/horde/framework/Horde/Support/Array.php +++ b/lib/horde/framework/Horde/Support/Array.php @@ -146,6 +146,7 @@ class Horde_Support_Array implements ArrayAccess, Countable, IteratorAggregate * * @return integer */ + #[ReturnTypeWillChange] public function count() { return count($this->_array); @@ -153,6 +154,7 @@ class Horde_Support_Array implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->_array); @@ -163,6 +165,7 @@ class Horde_Support_Array implements ArrayAccess, Countable, IteratorAggregate * * @see __get() */ + #[ReturnTypeWillChange] public function offsetGet($offset) { return $this->__get($offset); @@ -173,6 +176,7 @@ class Horde_Support_Array implements ArrayAccess, Countable, IteratorAggregate * * @see __set() */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { return $this->__set($offset, $value); @@ -183,6 +187,7 @@ class Horde_Support_Array implements ArrayAccess, Countable, IteratorAggregate * * @see __isset() */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return $this->__isset($offset); @@ -193,6 +198,7 @@ class Horde_Support_Array implements ArrayAccess, Countable, IteratorAggregate * * @see __unset() */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { return $this->__unset($offset); diff --git a/lib/horde/framework/Horde/Support/CaseInsensitiveArray.php b/lib/horde/framework/Horde/Support/CaseInsensitiveArray.php index 5726d162117..f9fb43de94e 100644 --- a/lib/horde/framework/Horde/Support/CaseInsensitiveArray.php +++ b/lib/horde/framework/Horde/Support/CaseInsensitiveArray.php @@ -24,6 +24,7 @@ class Horde_Support_CaseInsensitiveArray extends ArrayIterator { /** */ + #[ReturnTypeWillChange] public function offsetGet($offset) { return (is_null($offset = $this->_getRealOffset($offset))) @@ -33,6 +34,7 @@ class Horde_Support_CaseInsensitiveArray extends ArrayIterator /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { if (is_null($roffset = $this->_getRealOffset($offset))) { @@ -44,6 +46,7 @@ class Horde_Support_CaseInsensitiveArray extends ArrayIterator /** */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return !is_null($offset = $this->_getRealOffset($offset)); @@ -51,6 +54,7 @@ class Horde_Support_CaseInsensitiveArray extends ArrayIterator /** */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { if (!is_null($offset = $this->_getRealOffset($offset))) { diff --git a/lib/horde/framework/Horde/Support/Guid.php b/lib/horde/framework/Horde/Support/Guid.php index c105daf3739..a3eae2979b3 100644 --- a/lib/horde/framework/Horde/Support/Guid.php +++ b/lib/horde/framework/Horde/Support/Guid.php @@ -57,7 +57,7 @@ class Horde_Support_Guid . (isset($opts['prefix']) ? $opts['prefix'] . '.' : '') . strval(new Horde_Support_Randomid()) . '@' - . (isset($opts['server']) ? $opts['server'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost')); + . (isset($opts['server']) ? $opts['server'] : (!empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost')); } /** diff --git a/lib/horde/framework/Horde/Support/Stub.php b/lib/horde/framework/Horde/Support/Stub.php index 84d8655187f..dbb3206f2ec 100644 --- a/lib/horde/framework/Horde/Support/Stub.php +++ b/lib/horde/framework/Horde/Support/Stub.php @@ -95,6 +95,7 @@ class Horde_Support_Stub implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetGet($offset) { return null; @@ -102,12 +103,14 @@ class Horde_Support_Stub implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetSet($offset, $value) { } /** */ + #[ReturnTypeWillChange] public function offsetExists($offset) { return false; @@ -115,6 +118,7 @@ class Horde_Support_Stub implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function offsetUnset($offset) { } @@ -123,6 +127,7 @@ class Horde_Support_Stub implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function count() { return 0; @@ -132,6 +137,7 @@ class Horde_Support_Stub implements ArrayAccess, Countable, IteratorAggregate /** */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator(array()); diff --git a/lib/horde/readme_moodle.txt b/lib/horde/readme_moodle.txt index df47b9f2377..f3e1c98ada2 100644 --- a/lib/horde/readme_moodle.txt +++ b/lib/horde/readme_moodle.txt @@ -13,6 +13,10 @@ Description of import of Horde libraries passing in your path to Horde (the directory you've cloned the repository): /tmp/copyhorde.sh ~/git/base/directory/from/step/2 + +Notes: +* 2023-01-20 Horde/Mail is copied from https://github.com/bytestream/Mail/tree/v2.7.1 for PHP 8.1 compatibility + ==== #!/bin/sh @@ -36,8 +40,3 @@ do cp -Rf $locale/* $target/locale fi done - -Local modifications: -- lib/Horde/Imap/Client/Exception/ServerResponse.php has been minimally modified for php80 compatibility - The fix applied is already upstream, see https://github.com/horde/Imap_Client/pull/13 and it's available - in Imap_Client 2.30.4 and up. See MDL-73405 for more details.