Skip to content
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

Content-Type paramater does not trim paramater name #23

Closed
weierophinney opened this issue Dec 31, 2019 · 1 comment · Fixed by #97
Closed

Content-Type paramater does not trim paramater name #23

weierophinney opened this issue Dec 31, 2019 · 1 comment · Fixed by #97

Comments

@weierophinney
Copy link
Member

Hello,

I am getting filenames for attachments using the getParameter() on the content-type header. I noticed some email parts that were supposed to be attachments did not have a filename. Inspecting the source header, I could see that there was in fact a filename set. Further inspection showed that the parameter name was being added with a leading space. I would expect that leading spaces would be trimmed.

Thanks,

Cody

Code to reproduce the issue

use Zend\Mail\Header\ContentType;
$ct = ContentType::fromString('Content-Type: text/plain; charset=utf-8; name="logfile.log";');
printf('r1 "%s"'.PHP_EOL, $ct->getParameter('name'));
printf('r2 "%s"'.PHP_EOL, $ct->getParameter(' name'));
var_dump($ct);

Actual results

r1 ""
r2 "logfile.log"
object(Zend\Mail\Header\ContentType)#3 (3) {
  ["type":protected]=>
  string(10) "text/plain"
  ["encoding":protected]=>
  string(5) "ASCII"
  ["parameters":protected]=>
  array(2) {
    ["charset"]=>
    string(5) "utf-8"
    [" name"]=>
    string(11) "logfile.log"
  }
}

My Fix

I would not presume to understand the best place to resolve this, but this hack solved my problem for the time being

$ diff ContentType.php ContentType.php.new
55c55
<                 $header->addParameter($values[$i], $value);
---
>                 $header->addParameter(trim($values[$i]), $value);

Originally posted by @cody121 at zendframework/zend-mail#220

@samsonasik
Copy link
Member

I've created PR #97 for it.

artemii-karkusha pushed a commit to artemii-karkusha/laminas-mail that referenced this issue May 24, 2023
artemii-karkusha pushed a commit to artemii-karkusha/laminas-mail that referenced this issue May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants