zendframework / zend-mail

Mail component from Zend Framework
BSD 3-Clause "New" or "Revised" License
96 stars 111 forks source link

Content-Type paramater does not trim paramater name #220

Open cody121 opened 5 years ago

cody121 commented 5 years ago

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 commented 4 years ago

This repository has been closed and moved to laminas/laminas-mail; a new issue has been opened at https://github.com/laminas/laminas-mail/issues/23.