Skip to content

Making into disposition string to lowercase to fix the comparision issue #566

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/PhpImap/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1249,9 +1249,9 @@ public function getMail(int $mailId, bool $markAsSeen = true): IncomingMail
*
* @return IncomingMailAttachment $attachment
*/
public function downloadAttachment(DataPartInfo $dataInfo, array $params, object $partStructure, bool $emlOrigin = false): IncomingMailAttachment
public function downloadAttachment(DataPartInfo $dataInfo, array $params, object $partStructure, bool $emlOrigin = false, bool $dispositionAttachment = false): IncomingMailAttachment
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are adding a new argument here and set it by default to false, but it seems like as it's never used, so it's always false. Isn't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, please see the whole changed function not only my changes.

{
if ('RFC822' == $partStructure->subtype && isset($partStructure->disposition) && 'attachment' == $partStructure->disposition) {
if ('RFC822' == $partStructure->subtype && isset($partStructure->disposition) && $dispositionAttachment) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure, if this is a good replacement. I think, this will break (also) something.

Before: string comparisation
After: boolean comparisation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function skipped attachments in some emails due to case sensitive comparison.
I've just put almost the same comparison (but now it is not case sensitive) in one place and then use the boolean replacement of it, kind of some refactoring)

$fileName = \strtolower($partStructure->subtype).'.eml';
} elseif ('ALTERNATIVE' == $partStructure->subtype) {
$fileName = \strtolower($partStructure->subtype).'.eml';
Expand Down Expand Up @@ -1674,10 +1674,10 @@ protected function initMailPart(IncomingMail $mail, object $partStructure, $part
}

// check if the part is a subpart of another attachment part (RFC822)
if ('RFC822' === $partStructure->subtype && isset($partStructure->disposition) && 'attachment' === $partStructure->disposition) {
if ('RFC822' === $partStructure->subtype && isset($partStructure->disposition) && $dispositionAttachment) {
// Although we are downloading each part separately, we are going to download the EML to a single file
//incase someone wants to process or parse in another process
$attachment = self::downloadAttachment($dataInfo, $params, $partStructure, false);
$attachment = self::downloadAttachment($dataInfo, $params, $partStructure, false, $dispositionAttachment);
$mail->addAttachment($attachment);
}

Expand All @@ -1695,7 +1695,7 @@ protected function initMailPart(IncomingMail $mail, object $partStructure, $part
}

if ($isAttachment) {
$attachment = self::downloadAttachment($dataInfo, $params, $partStructure, $emlParse);
$attachment = self::downloadAttachment($dataInfo, $params, $partStructure, $emlParse, $dispositionAttachment);
$mail->addAttachment($attachment);
} else {
if (isset($params['charset']) && !empty(\trim($params['charset']))) {
Expand All @@ -1705,14 +1705,14 @@ protected function initMailPart(IncomingMail $mail, object $partStructure, $part

if (!empty($partStructure->parts)) {
foreach ($partStructure->parts as $subPartNum => $subPartStructure) {
$not_attachment = (!isset($partStructure->disposition) || 'attachment' !== $partStructure->disposition);
$not_attachment = (!isset($partStructure->disposition) || !$dispositionAttachment);

if (TYPEMESSAGE === $partStructure->type && 'RFC822' === $partStructure->subtype && $not_attachment) {
$this->initMailPart($mail, $subPartStructure, $partNum, $markAsSeen);
} elseif (TYPEMULTIPART === $partStructure->type && 'ALTERNATIVE' === $partStructure->subtype && $not_attachment) {
// https://github.com/barbushin/php-imap/issues/198
$this->initMailPart($mail, $subPartStructure, $partNum, $markAsSeen);
} elseif ('RFC822' === $partStructure->subtype && isset($partStructure->disposition) && 'attachment' === $partStructure->disposition) {
} elseif ('RFC822' === $partStructure->subtype && isset($partStructure->disposition) && $dispositionAttachment) {
//If it comes from am EML attachment, download each part separately as a file
$this->initMailPart($mail, $subPartStructure, $partNum.'.'.($subPartNum + 1), $markAsSeen, true);
} else {
Expand Down