Skip to content

Commit

Permalink
Cleaner way of handling setting of current stream into the same mime …
Browse files Browse the repository at this point in the history
…part

slightly optimize that case.
Also, cleanly/correctly close the existing stream. Shouldn't make a
difference since PHP should be doing GC automatically, but best to be
explicit.
  • Loading branch information
slusarz committed Jan 20, 2015
1 parent ab9b0ee commit df4d82b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions framework/Mime/lib/Horde/Mime/Part.php
Expand Up @@ -423,6 +423,10 @@ public function getName($default = false)
*/
public function setContents($contents, $options = array())
{
if (is_resource($contents) && ($contents === $this->_contents)) {
return;
}

if (empty($options['encoding'])) {
$options['encoding'] = $this->_transferEncoding;
}
Expand All @@ -431,6 +435,9 @@ public function setContents($contents, $options = array())
? $this->_writeStream($contents)
: $contents;

/* Properly close the existing stream. */
$this->clearContents();

$this->setTransferEncoding($options['encoding']);
$this->_contents = $this->_transferDecode($fp, $options['encoding']);
}
Expand Down

0 comments on commit df4d82b

Please sign in to comment.