Skip to content

Commit

Permalink
Merge branch 'master' of github.com:freescout-helpdesk/freescout into…
Browse files Browse the repository at this point in the history
… dist
  • Loading branch information
freescout-help-desk committed Jan 18, 2025
2 parents 3a33fd4 + 12584db commit ab8309b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion app/Misc/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ public static function parseHeaders($headers_str)
{
//try {
//return imap_rfc822_parse_headers($headers_str);
return (new \Webklex\PHPIMAP\Header(''))->rfc822_parse_headers($headers_str);
//return (new \Webklex\PHPIMAP\Header(''))->rfc822_parse_headers($headers_str);
return \Webklex\PHPIMAP\Header::rfc822_parse_headers($headers_str);
// } catch (\Exception $e) {
// return;
// }
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
| or any other location as required by the application or its packages.
*/

'version' => '1.8.164',
'version' => '1.8.165',

/*
|--------------------------------------------------------------------------
Expand Down
20 changes: 11 additions & 9 deletions overrides/webklex/php-imap/src/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private function clearBoundaryString(string $str): string {
* @throws InvalidMessageDateException
*/
protected function parse() {
$header = $this->rfc822_parse_headers($this->raw);
$header = self::rfc822_parse_headers($this->raw);

$this->extractAddresses($header);

Expand Down Expand Up @@ -246,14 +246,15 @@ protected function parse() {
*
* @return object
*/
public function rfc822_parse_headers($raw_headers) {
public static function rfc822_parse_headers($raw_headers) {
$headers = [];
$imap_headers = [];
if (extension_loaded('imap') && isset($this->config) && $this->config["rfc822"]) {
// Consider rfc822 option to be always 'true'.
if (extension_loaded('imap') /*&& isset($this->config) && $this->config["rfc822"]*/) {
$raw_imap_headers = (array)\imap_rfc822_parse_headers($raw_headers);
foreach ($raw_imap_headers as $key => $values) {
$key = str_replace("-", "_", $key);
$values = $this->sanitizeHeaderValue($values);
$values = self::sanitizeHeaderValue($values);
if (!is_array($values) || (is_array($values) && count($values))) {
$imap_headers[$key] = $values;
}
Expand Down Expand Up @@ -311,7 +312,7 @@ public function rfc822_parse_headers($raw_headers) {
case 'bcc':
case 'reply_to':
case 'sender':
$value = $this->decodeAddresses($values);
$value = self::decodeAddresses($values);
$headers[$key . "address"] = implode(", ", $values);
break;
case 'subject':
Expand All @@ -337,7 +338,7 @@ public function rfc822_parse_headers($raw_headers) {
}
break;
}
$value = $this->sanitizeHeaderValue($value);
$value = self::sanitizeHeaderValue($value);
if (!is_array($value) || (is_array($value) && count($value))) {
$headers[$key] = $value;
} elseif (is_array($value) && !count($value) && isset($headers[$key])) {
Expand All @@ -349,7 +350,7 @@ public function rfc822_parse_headers($raw_headers) {
}

// https://github.com/freescout-help-desk/freescout/issues/4158
public function sanitizeHeaderValue($value)
public static function sanitizeHeaderValue($value)
{
if (is_array($value)) {
foreach ($value as $i => $v) {
Expand Down Expand Up @@ -593,10 +594,11 @@ private function findPriority() {
*
* @return array
*/
private function decodeAddresses($values): array {
private static function decodeAddresses($values): array {
$addresses = [];

if (extension_loaded('mailparse') && $this->config["rfc822"]) {
// Consider rfc822 option to be always 'true'.
if (extension_loaded('mailparse') /*&& $this->config["rfc822"]*/) {
foreach ($values as $address) {
foreach (\mailparse_rfc822_parse_addresses($address) as $parsed_address) {
if (isset($parsed_address['address'])) {
Expand Down

0 comments on commit ab8309b

Please sign in to comment.