zendframework / zend-mime

Mime component from Zend Framework
BSD 3-Clause "New" or "Revised" License
62 stars 37 forks source link

Mime::encodeQuotedPrintableHeader breaks Zend_Mail's parsing if encoding is needed and there are multiple recipients #12

Open ftzdomino opened 8 years ago

ftzdomino commented 8 years ago

The following code illustrates the weirdness:

<?php

require_once __DIR__.'/vendor/autoload.php';
use Zend\Mime\Mime;

$str = '=?iso-8859-1?Q?Jorgen?= <foo1@example.com>,=?iso-8859-1?Q?Schmorgen?= <foo2@example.com>';
$header = iconv_mime_decode($str);

$encoded = Mime::encodeQuotedPrintableHeader($header, 'UTF-8', 78, "\r\n");
echo $encoded;

The output:

=?UTF-8?Q?Jorgen=20<foo1@example.com>,Schmorgen=20<foo2@example.com>?=

This is a problem now that zend-mail explodes the whole encoded string on a comma to due to this: https://github.com/zendframework/zend-mail/pull/44 Which results in the prefix and suffix being split up, breaking the parsing of the header.

The RFCs don't seem to be clear about whether the header field separator is allowed in the middle of a quoted-printable string, but do say that it should only be used if necessary for a given token.

mleko commented 8 years ago

According to https://tools.ietf.org/html/rfc2047#section-2 encoded strings are designed to be recognized as 'atom's by an RFC 822 parser

So separator is not allowed inside encoded string(but comma is)

BTW quoted printable name is misused here, you should split before decoding and combine after recoding

weierophinney commented 4 years ago

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