Skip to content

Commit

Permalink
Mail\MimePart::getEncodedHeader() don't use base64 encoding where can…
Browse files Browse the repository at this point in the history
… be quoted string [Closes nette/mail#4]
  • Loading branch information
dg committed Aug 25, 2014
1 parent bfbd9a1 commit a0f15cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Nette/Mail/MimePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function getEncodedHeader($name)
$s = '';
foreach ($this->headers[$name] as $email => $name) {
if ($name != NULL) { // intentionally ==
$s .= self::encodeHeader($name, $offset, strpbrk($name, '.,;<@>()[]"=?'));
$s .= self::encodeHeader($name, $offset, TRUE);
$email = " <$email>";
}
$s .= self::append($email . ',', $offset);
Expand Down Expand Up @@ -297,9 +297,12 @@ public function getEncodedMessage()
* @param bool
* @return string
*/
private static function encodeHeader($s, & $offset = 0, $force = FALSE)
private static function encodeHeader($s, & $offset = 0, $quotes = FALSE)
{
if (!$force && strspn($s, "!\"#$%&\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}=? _\r\n\t") === strlen($s)) {
if (strspn($s, "!\"#$%&\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}~=? _\r\n\t") === strlen($s)) {
if ($quotes && preg_match('#[^ a-zA-Z0-9!\#$%&\'*+/?^_`{|}~-]#', $s)) { // RFC 2822 atext except =
return self::append('"' . addcslashes($s, '"\\') . '"', $offset);
}
return self::append($s, $offset);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/Nette/Mail/Mail.email.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $mail->addTo('doe3@example.com', "John 'jd' Doe");

$mail->addCc('The\Mail <nette@example.com>');
$mail->addCc('doe4@example.com', 'John Doe');
$mail->addCc('The.Mail <nette2@example.com>');

$mail->addBcc('Žluťoučký kůň <kun5@example.com>');
$mail->addBcc('doe5@example.com');
Expand All @@ -43,7 +44,8 @@ Reply-To: =?UTF-8?B?xb1sdcWlb3XEjWvDvSBrxa/FiA==?= <kun2@example.com>,
John Doe <doe2@example.com>
To: =?UTF-8?B?xb1sdcWlb3XEjWvDvSAia8WvxYgi?= <kun3@example.com>,
John 'jd' Doe <doe3@example.com>
Cc: The\Mail <nette@example.com>,John Doe <doe4@example.com>
Cc: "The\\Mail" <nette@example.com>,John Doe <doe4@example.com>,"The.Mail"
<nette2@example.com>
Bcc: =?UTF-8?B?xb1sdcWlb3XEjWvDvSBrxa/FiA==?= <kun5@example.com>,
doe5@example.com
Return-Path: doe@example.com
Expand Down

0 comments on commit a0f15cd

Please sign in to comment.