-
Notifications
You must be signed in to change notification settings - Fork 456
Adding support to keep original Filename of Attachment and open more flexibility #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
682b25d
9f6ff93
282cbca
08ebd52
40253ce
bd1c98e
2b998b9
46cfc29
35df2e3
82547df
b5fcde5
8f9d27a
e866a8a
02d9347
37d2d03
44cddfb
c26851a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -156,9 +156,10 @@ class Mailbox | |||||||||||||||
| /** @var string */ | ||||||||||||||||
| protected $mailboxFolder; | ||||||||||||||||
|
|
||||||||||||||||
| /** @var bool|false */ | ||||||||||||||||
| protected $attachmentFilenameMode = false; | ||||||||||||||||
|
|
||||||||||||||||
| public const ATTACH_FILE_NAMERANDOM = 1; // Filename is unique (random) | ||||||||||||||||
| public const ATTACH_FILE_NAMEORIGINAL = 2; // Filename is Attachment-Filename | ||||||||||||||||
| /** @var int */ | ||||||||||||||||
| protected $attachmentsFilenameMode = self::ATTACH_FILE_NAMERANDOM; | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| /** @var resource|null */ | ||||||||||||||||
| private $imapStream; | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -326,7 +327,20 @@ public function setAttachmentsIgnore(bool $attachmentsIgnore): void | |||||||||||||||
| { | ||||||||||||||||
| $this->attachmentsIgnore = $attachmentsIgnore; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Set $this->setAttachmentsRandomFilename param. | ||||||||||||||||
| * | ||||||||||||||||
| * @param int $random ATTACH_FILE_NAMERANDOM, ATTACH_FILE_NAMEORIGINAL | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable in the comment should match the actual parameter variable.
Suggested change
|
||||||||||||||||
| * | ||||||||||||||||
| * @return Mailbox | ||||||||||||||||
| */ | ||||||||||||||||
| public function setAttachmentsFilenameMode(int $mode) : Mailbox | ||||||||||||||||
| { | ||||||||||||||||
| $this->attachmentsFilenameMode = $mode; | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I miss a check here, which ensures, that only supported modes can be set. Something like this:
Suggested change
Note: I haven't tested this code. |
||||||||||||||||
| return $this; | ||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this return here? Wouldn't be a |
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Get $this->attachmentsIgnore param. | ||||||||||||||||
| * | ||||||||||||||||
|
|
@@ -1401,20 +1415,22 @@ public function downloadAttachment(DataPartInfo $dataInfo, array $params, object | |||||||||||||||
|
|
||||||||||||||||
| $attachmentsDir = $this->getAttachmentsDir(); | ||||||||||||||||
|
|
||||||||||||||||
| if (null != $attachmentsDir) { | ||||||||||||||||
| if (true == $this->getAttachmentFilenameMode()) { | ||||||||||||||||
| $fileSysName = $attachment->name; | ||||||||||||||||
| } else { | ||||||||||||||||
| $fileSysName = \bin2hex(\random_bytes(16)).'.bin'; | ||||||||||||||||
| if (null !== $attachmentsDir) { | ||||||||||||||||
| switch($this->attachmentsFilenameMode) { | ||||||||||||||||
| case self::ATTACH_FILE_NAMEORIGINAL: | ||||||||||||||||
| $fileSysName = $fileName; | ||||||||||||||||
| break; | ||||||||||||||||
| case self::ATTACH_FILE_NAMERANDOM: | ||||||||||||||||
| default: | ||||||||||||||||
| $fileSysName = \bin2hex(\random_bytes(16)).'.bin'; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| $filePath = $attachmentsDir.DIRECTORY_SEPARATOR.$fileSysName; | ||||||||||||||||
|
|
||||||||||||||||
| if (\strlen($filePath) > self::MAX_LENGTH_FILEPATH) { | ||||||||||||||||
| $ext = \pathinfo($filePath, PATHINFO_EXTENSION); | ||||||||||||||||
| $filePath = \substr($filePath, 0, self::MAX_LENGTH_FILEPATH - 1 - \strlen($ext)).'.'.$ext; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| $attachment->setFilePath($filePath); | ||||||||||||||||
| $attachment->saveToDisk(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.