Skip to content

Commit

Permalink
KAYAKOC-31831 | fix hebrew encoding issue (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
fpt-thanhdq2 authored Oct 21, 2022
1 parent 0de63da commit 83ce051
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/vendor/
/zf-mkdoc-theme.tgz
/zf-mkdoc-theme/
.idea
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.11.0 - fix hebrew encoding issue - 2022-10-21

## 2.10.1 - TBD

### Added
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "zendframework/zend-mail",
"name": "kayako-zend/zend-mail-kayako",
"description": "Provides generalized functionality to compose and send both text and MIME-compliant multipart e-mail messages",
"license": "BSD-3-Clause",
"keywords": [
Expand All @@ -21,7 +21,7 @@
"zendframework/zend-loader": "^2.5",
"zendframework/zend-mime": "^2.5",
"zendframework/zend-stdlib": "^2.7 || ^3.0",
"zendframework/zend-validator": "^2.10.2",
"kayako-zend/zend-validator-kayako": "^2.14.0",
"true/punycode": "^2.1"
},
"require-dev": {
Expand Down
21 changes: 9 additions & 12 deletions src/Header/AbstractAddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,15 @@ public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
$name = HeaderWrap::mimeEncodeValue($name, $encoding);
}

if (preg_match('/^(.+)@([^@]+)$/', $email, $matches)) {
$localPart = $matches[1];
$hostname = $this->idnToAscii($matches[2]);
$email = sprintf('%s@%s', $localPart, $hostname);
}
if (preg_match('/^(.*)\<(.+)@([^@]+)\>(.*)$/', $value, $matches)) {
$localPart = $matches[2];
$hostname = $this->idnToAscii($matches[3]);
$email = sprintf('%s@%s', $localPart, $hostname);
} elseif (preg_match('/^(.+)@([^@]+)$/', $value, $matches)) {
$localPart = $matches[1];
$hostname = $this->idnToAscii($matches[2]);
$email = sprintf('%s@%s', $localPart, $hostname);
}
}

if (empty($name)) {
Expand All @@ -159,13 +163,6 @@ public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
}
}

// Ensure the values are valid before sending them.
if ($format !== HeaderInterface::FORMAT_RAW) {
foreach ($emails as $email) {
HeaderValue::assertValid($email);
}
}

return implode(',' . Headers::FOLDING, $emails);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Header/GenericHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function setFieldValue($fieldValue)
{
$fieldValue = (string) $fieldValue;

if (! HeaderWrap::canBeEncoded($fieldValue)) {
if ($this->getFieldName() !== 'Thread-Topic' && ! HeaderWrap::canBeEncoded($fieldValue)) {
throw new Exception\InvalidArgumentException(
'Header value must be composed of printable US-ASCII characters and valid folding sequences.'
);
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getEncoding()
public function setSubject($subject)
{
$subject = (string) $subject;

$subject = HeaderWrap::canBeEncoded($subject) ? $subject : iconv('windows-1255', 'utf-8', $subject);
if (! HeaderWrap::canBeEncoded($subject)) {
throw new Exception\InvalidArgumentException(
'Subject value must be composed of printable US-ASCII or UTF-8 characters.'
Expand Down

0 comments on commit 83ce051

Please sign in to comment.