Skip to content

Commit b8484ba

Browse files
committed
Additional Attachment name fallback added to prevent missing attachments
1 parent 141dc10 commit b8484ba

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/Attachment.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ protected function fetch(): void {
243243
if (($name = $this->part->name) !== null) {
244244
$this->name = $this->decodeName($name);
245245
}
246-
if (!$this->name && $this->filename != "") {
247-
$this->name = $this->filename;
248-
}
249246

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

261-
if(!$this->filename){
262-
$this->filename = bin2hex(random_bytes(10));
258+
if (!$this->filename) {
259+
$this->filename = $this->hash;
260+
}
261+
262+
if (!$this->name && $this->filename != "") {
263+
$this->name = $this->filename;
263264
}
264265
}
265266

src/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ protected function addBody(string $subtype, string $content): void {
767767
protected function fetchAttachment(Part $part): void {
768768
$oAttachment = new Attachment($this, $part);
769769

770-
if ($oAttachment->getName() !== null && $oAttachment->getSize() > 0) {
770+
if ($oAttachment->getSize() > 0) {
771771
if ($oAttachment->getId() !== null && $this->attachments->offsetExists($oAttachment->getId())) {
772772
$this->attachments->put($oAttachment->getId(), $oAttachment);
773773
} else {

0 commit comments

Comments
 (0)