Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Content-Type paramater does not trim paramater name #220

Open
cody121 opened this issue Nov 9, 2018 · 1 comment
Open

Content-Type paramater does not trim paramater name #220

cody121 opened this issue Nov 9, 2018 · 1 comment

Comments

@cody121
Copy link

cody121 commented Nov 9, 2018

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);
@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-mail; a new issue has been opened at laminas/laminas-mail#23.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants