Skip to content

Commit

Permalink
Additional Attachment name fallback added to prevent missing attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
Webklex committed Jun 28, 2023
1 parent 141dc10 commit b8484ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@ protected function fetch(): void {
if (($name = $this->part->name) !== null) {
$this->name = $this->decodeName($name);
}
if (!$this->name && $this->filename != "") {
$this->name = $this->filename;
}

if (IMAP::ATTACHMENT_TYPE_MESSAGE == $this->part->type) {
if ($this->part->ifdescription) {
Expand All @@ -258,8 +255,12 @@ protected function fetch(): void {
}
$this->attributes = array_merge($this->part->getHeader()->getAttributes(), $this->attributes);

if(!$this->filename){
$this->filename = bin2hex(random_bytes(10));
if (!$this->filename) {
$this->filename = $this->hash;
}

if (!$this->name && $this->filename != "") {
$this->name = $this->filename;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ protected function addBody(string $subtype, string $content): void {
protected function fetchAttachment(Part $part): void {
$oAttachment = new Attachment($this, $part);

if ($oAttachment->getName() !== null && $oAttachment->getSize() > 0) {
if ($oAttachment->getSize() > 0) {
if ($oAttachment->getId() !== null && $this->attachments->offsetExists($oAttachment->getId())) {
$this->attachments->put($oAttachment->getId(), $oAttachment);
} else {
Expand Down

0 comments on commit b8484ba

Please sign in to comment.