mirror of
https://github.com/itflow-org/itflow
synced 2026-08-16 12:35:11 +00:00
Bump ImapEngine from 1.25.1 to 1.25.2
This commit is contained in:
59
libs/vendor/directorytree/imapengine/src/Support/MimeParameterParser.php
vendored
Normal file
59
libs/vendor/directorytree/imapengine/src/Support/MimeParameterParser.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace DirectoryTree\ImapEngine\Support;
|
||||
|
||||
use ZBateson\MailMimeParser\Header\ParameterHeader;
|
||||
|
||||
class MimeParameterParser
|
||||
{
|
||||
/**
|
||||
* Parse and normalize MIME parameters.
|
||||
*
|
||||
* @param array<string, string> $parameters
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function parse(array $parameters): array
|
||||
{
|
||||
if (empty($parameters)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$header = new ParameterHeader(
|
||||
'Content-Type',
|
||||
'application/octet-stream; '.implode('; ', static::stringify($parameters))
|
||||
);
|
||||
|
||||
$parsed = [];
|
||||
|
||||
foreach (array_keys($parameters) as $name) {
|
||||
$name = strtolower(explode('*', $name, 2)[0]);
|
||||
|
||||
if (array_key_exists($name, $parsed)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! is_null($value = $header->getValueFor($name))) {
|
||||
$parsed[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert parameter values into MIME parameter syntax.
|
||||
*
|
||||
* @param array<string, string> $parameters
|
||||
* @return string[]
|
||||
*/
|
||||
protected static function stringify(array $parameters): array
|
||||
{
|
||||
$values = [];
|
||||
|
||||
foreach ($parameters as $name => $value) {
|
||||
$values[] = sprintf('%s="%s"', $name, Str::escape($value));
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
@@ -300,6 +300,10 @@ class Str
|
||||
*/
|
||||
public static function decodeMimeHeader(string $value): string
|
||||
{
|
||||
if (empty($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (! str_contains($value, '=?')) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user