Skip to content

Commit

Permalink
Work around dropping attachments.
Browse files Browse the repository at this point in the history
Not sure exactly what the cause is, but with PHP 7.4, the
existing code would fail at file_put_contents (which would
return a false, despite the stream contents being added to
the tmp file). Explicitly copying in chunks like this
probably isn't ideal, but at least now it works.
  • Loading branch information
mrubinsk committed Aug 25, 2020
1 parent 652b282 commit 3e7b595
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Compose.php
Expand Up @@ -3164,14 +3164,19 @@ public function addAttachmentFromPart($part)
'stream' => true
));
rewind($stream);

if (file_put_contents($atc_file, $stream) === false) {
$dest_handle = fopen($atc_file, 'w+b');
while (!feof($stream)) {
fwrite($dest_handle, fread($stream, 1024));
}
fclose($dest_handle);
$size = ftell($stream);
if ($size === false) {
throw new IMP_Compose_Exception(sprintf(_("Could not attach %s to the message."), $part->getName()));
}

return $this->_addAttachment(
$atc_file,
ftell($stream),
$size,
$part->getName(true),
$part->getType()
);
Expand Down

0 comments on commit 3e7b595

Please sign in to comment.