From 7bfe3a2d396e120b8a84e677c25160826e852a09 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Mon, 13 Apr 2026 00:07:42 +0200 Subject: [PATCH] fix: backport community fixes from bytestream fork Original-Author: Richard Steinmetz (Mail getRaw encoding + stream rewind, 8ae56b5 + 63eb217) Original-Author: David Dreschner (Headers null coalesce + iterator cast, Magic finfo_close removal, Part phpdoc, 22dcdbb) --- lib/Horde/Mime/Headers.php | 4 +++- lib/Horde/Mime/Magic.php | 2 -- lib/Horde/Mime/Mail.php | 20 +++++++++----------- lib/Horde/Mime/Part.php | 2 +- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/Horde/Mime/Headers.php b/lib/Horde/Mime/Headers.php index 72455a5..90f3a42 100644 --- a/lib/Horde/Mime/Headers.php +++ b/lib/Horde/Mime/Headers.php @@ -130,6 +130,8 @@ public function toArray(array $opts = []) $tmp = []; foreach ($ob->sendEncode(array_filter($sopts)) as $val) { + $val = $val ?? ''; + if (empty($opts['nowrap'])) { /* Remove any existing linebreaks and wrap the line. */ $htext = $ob->name . ': '; @@ -509,7 +511,7 @@ public function offsetUnset($offset) #[ReturnTypeWillChange] public function getIterator() { - return new ArrayIterator($this->_headers); + return new ArrayIterator((array) $this->_headers); } /* Deprecated functions */ diff --git a/lib/Horde/Mime/Magic.php b/lib/Horde/Mime/Magic.php index 63cf69b..849f68f 100644 --- a/lib/Horde/Mime/Magic.php +++ b/lib/Horde/Mime/Magic.php @@ -168,7 +168,6 @@ public static function analyzeFile( if ($res) { $type = trim(finfo_file($res, $path)); - finfo_close($res); /* Remove any additional information. */ if (empty($opts['nostrip'])) { @@ -219,7 +218,6 @@ public static function analyzeData( } $type = trim(finfo_buffer($res, $data)); - finfo_close($res); /* Remove any additional information. */ if (empty($opts['nostrip'])) { diff --git a/lib/Horde/Mime/Mail.php b/lib/Horde/Mime/Mail.php index ac0a15e..3078b10 100644 --- a/lib/Horde/Mime/Mail.php +++ b/lib/Horde/Mime/Mail.php @@ -500,19 +500,17 @@ public function send($mailer, $resend = false, $flowed = true) */ public function getRaw($stream = true) { - if ($stream) { - $hdr = new Horde_Stream(); - $hdr->add($this->_headers->toString(), true); - return Horde_Stream_Wrapper_Combine::getStream( - [$hdr->stream, - $this->getBasePart()->toString( - ['stream' => true, 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY] - ), - ] - ); + $raw = $this->getBasePart()->toString([ + 'stream' => $stream, + 'encode' => Horde_Mime_Part::ENCODE_7BIT | Horde_Mime_Part::ENCODE_8BIT | Horde_Mime_Part::ENCODE_BINARY, + 'headers' => $this->_headers, + ]); + + if ($stream && is_resource($raw)) { + rewind($raw); } - return $this->_headers->toString() . $this->getBasePart()->toString(); + return $raw; } /** diff --git a/lib/Horde/Mime/Part.php b/lib/Horde/Mime/Part.php index 46dd37a..80ac487 100644 --- a/lib/Horde/Mime/Part.php +++ b/lib/Horde/Mime/Part.php @@ -1126,7 +1126,7 @@ public function toString($options = []) * Get the transfer encoding for the part based on the user requested * transfer encoding and the current contents of the part. * - * @param integer $encode A mask of allowable encodings. + * @param int|null $encode A mask of allowable encodings. * * @return string The transfer-encoding of this part. */