Adding support to keep original Filename of Attachment and open more flexibility#645
Adding support to keep original Filename of Attachment and open more flexibility#645fglueck wants to merge 17 commits into
Conversation
Adding support for "original" Filename. $mailbox->setAttachmentsFilenameMode(Mailbox::ATTACH_FILE_NAMERANDOM); # filename by random (old way) $mailbox->setAttachmentsFilenameMode(Mailbox::ATTACH_FILE_NAMEORIGINAL); # filename by email
|
@fglueck can you please resolve the conflicts? |
|
@fglueck friendly reminder :) |
|
Can you please also squash your commits at the end, so that it's only one? It would be also cool, when the commit message would be Thank you! :) |
|
sorry I miss the button "Squash and merge". Is it possible that you must first "allow" this? |
|
I have unfortunately no permissions to change any settings of this project. But you can usually rebase and squash locally and force push the changes, don't you? Ok, if it's not possible, I also can squash and merge it through the buttons here. :) |
|
Wouldn't it be a bit more beautiful and more human readable, when there would be some more underscores in the constant names? Like this? public const ATTACH_FILE_NAME_RANDOM = 1; // Filename is unique (random)
public const ATTACH_FILE_NAME_ORIGINAL = 2; // Filename is Attachment-Filename
public const ATTACH_FILE_NAME_ITTERATED = 3; // Filename is Attachment-Filename but if allready exists it will be extend by Number (#nr) |
|
Your right, I change the names and add itterated filename. |
|
Perfect, I've already seen it. There are some more reviews (see above). :) |
|
You meen the "squash" ? I never do this before... so I can try to do this... |
|
No, I mean these pending reviews in the code. |
Adding support for "original" Filename. $mailbox->setAttachmentsFilenameMode(Mailbox::ATTACH_FILE_NAME_RANDOM); # filename by random (old way) $mailbox->setAttachmentsFilenameMode(Mailbox::ATTACH_FILE_NAME_ORIGINAL); # filename by email
Sebbo94BY
left a comment
There was a problem hiding this comment.
Sorry, forgot to publish my review. 😞
| 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; |
There was a problem hiding this comment.
| protected $attachmentsFilenameMode = self::ATTACH_FILE_NAMERANDOM; | |
| protected $attachmentsFilenameMode = self::ATTACH_FILE_NAMERANDOM; | |
|
|
||
| public const ATTACH_FILE_NAMERANDOM = 1; // Filename is unique (random) | ||
| public const ATTACH_FILE_NAMEORIGINAL = 2; // Filename is Attachment-Filename | ||
| /** @var int */ |
There was a problem hiding this comment.
| /** @var int */ | |
| /** @var int */ |
| /** | ||
| * Set $this->setAttachmentsRandomFilename param. | ||
| * | ||
| * @param int $random ATTACH_FILE_NAMERANDOM, ATTACH_FILE_NAMEORIGINAL |
There was a problem hiding this comment.
The variable in the comment should match the actual parameter variable.
| * @param int $random ATTACH_FILE_NAMERANDOM, ATTACH_FILE_NAMEORIGINAL | |
| * @param int $mode ATTACH_FILE_NAMERANDOM, ATTACH_FILE_NAMEORIGINAL |
| public function setAttachmentsFilenameMode(int $mode) : Mailbox | ||
| { | ||
| $this->attachmentsFilenameMode = $mode; | ||
| return $this; |
There was a problem hiding this comment.
Do we really need this return here? Wouldn't be a void function enough?
| */ | ||
| public function setAttachmentsFilenameMode(int $mode) : Mailbox | ||
| { | ||
| $this->attachmentsFilenameMode = $mode; |
There was a problem hiding this comment.
I miss a check here, which ensures, that only supported modes can be set. Something like this:
| $this->attachmentsFilenameMode = $mode; | |
| if (!defined($mode)) | |
| { | |
| throw new UnexpectedValueException("The defined mode '$mode' is not supported. Supported modes: ATTACH_FILE_NAMERANDOM, ATTACH_FILE_NAMEORIGINAL"); | |
| } | |
| $this->attachmentsFilenameMode = $mode; |
Note: I haven't tested this code.
The existing boolean `setAttachmentFilenameMode(true|false)` stays intact for backward compatibility, and attachment downloads now either overwrite as before or generate `name (1).ext`, `name (2).ext`, while still sanitizing path separators and respecting the file-path limit (`src/PhpImap/Mailbox.php:1532`, `src/PhpImap/Mailbox.php:1827`). Co-authored by @fglueck Refs: - #645
can be extend with settings like "OVERWRITE_EXISTING _FILES" or like "GENERATE_FILENAME_IF_FILE_EXISTS"...