Skip to content

Commit

Permalink
Issue #321: Fixed saving of attachments (did not not work anymore)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Krätzig committed May 15, 2019
1 parent efb68b3 commit caee2a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/PhpImap/IncomingMailAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public function __get ($name) {
return $this->filePath;
}

if(false === file_put_contents($this->filePath, $this->dataInfo->fetch())) {
unset($this->filePath);
unset($this->file_path);
return false;
}

return $this->filePath;
}

Expand All @@ -47,4 +41,18 @@ public function setFilePath($filePath) {
public function addDataPartInfo(DataPartInfo $dataInfo) {
$this->dataInfo = $dataInfo;
}

/*
* Saves the attachment object on the disk
* @return boolean True, if it could save the attachment on the disk
*/
public function saveToDisk() {
if(false === file_put_contents($this->filePath, $this->dataInfo->fetch())) {
unset($this->filePath);
unset($this->file_path);

return false;
}
return true;
}
}
5 changes: 3 additions & 2 deletions src/PhpImap/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,10 @@ protected function initMailPart(IncomingMail $mail, $partStructure, $partNum, $m
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
$filePath = substr($filePath, 0, 255 - 1 - strlen($ext)) . "." . $ext;
}
$attachment->setFilePath($filePath);
$attachment->setFilePath($filePath);
$attachment->addDataPartInfo($dataInfo);
$attachment->saveToDisk();
}
$attachment->addDataPartInfo($dataInfo);
$mail->addAttachment($attachment);
}
else {
Expand Down

0 comments on commit caee2a6

Please sign in to comment.