Skip to content

Check whether path is file in DataPart::fromPath() #36304

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

Merged
merged 1 commit into from
Jun 22, 2020

Conversation

freiondrej
Copy link
Contributor

Q A
Branch? 5.0
Bug fix? yes
New feature? no
Deprecations? no

Method getBody() uses stream_get_contents() to retrieve the body, however it fails to do so when the stream is a directory.

@@ -56,6 +56,10 @@ public static function fromPath(string $path, string $name = null, string $conte
$contentType = self::$mimeTypes->getMimeTypes($ext)[0] ?? 'application/octet-stream';
}

if (false === is_file($path)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think to put "is_readable"? And adapt the exception message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@maxhelias done :)

@fabpot fabpot changed the base branch from 5.0 to 4.4 June 22, 2020 14:55
@fabpot
Copy link
Member

fabpot commented Jun 22, 2020

Thank you @freiondrej.

@fabpot fabpot merged commit 030b10c into symfony:4.4 Jun 22, 2020
This was referenced Jul 24, 2020
chalasr added a commit that referenced this pull request Jun 1, 2022
…Path (wkania)

This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Mime] Check that the path is a file in the DataPart::fromPath

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

The directory can also be readable. Fix to the [PR](#36304).

Found it while working on another fix related to this method.

Commits
-------

a807523 [Mime] Check that the path is a file in the DataPart::fromPath
nicolas-grekas added a commit that referenced this pull request Jun 9, 2022
This PR was merged into the 4.4 branch.

Discussion
----------

[Mime] Allow url as a path in the DataPart::fromPath

| Q             | A
| ------------- | ---
| Branch?       |  4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

While switching from the Swift Mailer to the Symfony Mailer I encounter a bug `Symfony\Component\Mime\Exception\InvalidArgumentException`.
Steps to reproduce:
1. I have created an email with an attachment that is a remote file and saw `An exception has been thrown during the rendering of a template`.
2. Also when I have visited tab E-mails in the Symfony Profiler, saw the same Symfony Exception page

DataPart can't be created from url,  even if `fopen` can open url.
Apparently, before Symfony [4.4.11](#36304) this worked with URLs. At least in the context of email with attachments.
PHP doesn't support rewind on non-local streams, so calling multiple times method `getBody` from `TextPart` would return an empty string. So in another context, it worked partially.

Additional notes:
1. Network example based on [this](https://github.com/symfony/symfony/blob/60ce5a3dfbd90fad60cd39fcb3d7bf7888a48659/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php#L165)
2. Base64Encoder chunk split base64 encoded string so I only check the first line

Commits
-------

12bf8cb [Mime] Allow url as a path in the DataPart::fromPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants