Aggiornato Composer

This commit is contained in:
Paolo A
2024-05-17 12:24:19 +00:00
parent 4ac62108b5
commit ec201d75b2
2238 changed files with 38684 additions and 59785 deletions

View File

@@ -81,17 +81,17 @@ final class CharacterStream
$this->fixedWidth = 2;
break;
// 32 bits
// 32 bits
case 'ucs4':
case 'ucs-4':
case 'utf32':
case 'utf-32':
$this->fixedWidth = 4;
break;
break;
// 7-8 bit charsets: (us-)?ascii, (iso|iec)-?8859-?[0-9]+, windows-?125[0-9], cp-?[0-9]+, ansi, macintosh,
// 7-8 bit charsets: (us-)?ascii, (iso|iec)-?8859-?[0-9]+, windows-?125[0-9], cp-?[0-9]+, ansi, macintosh,
// koi-?7, koi-?8-?.+, mik, (cork|t1), v?iscii
// and fallback
// and fallback
default:
$this->fixedWidth = 1;
}

View File

@@ -26,7 +26,7 @@ final class SMimeEncrypter extends SMime
* @param string|string[] $certificate The path (or array of paths) of the file(s) containing the X.509 certificate(s)
* @param int|null $cipher A set of algorithms used to encrypt the message. Must be one of these PHP constants: https://www.php.net/manual/en/openssl.ciphers.php
*/
public function __construct($certificate, int $cipher = null)
public function __construct($certificate, ?int $cipher = null)
{
if (!\extension_loaded('openssl')) {
throw new \LogicException('PHP extension "openssl" is required to use SMime.');

View File

@@ -31,7 +31,7 @@ final class SMimeSigner extends SMime
* @param string|null $extraCerts The path of the file containing intermediate certificates (in PEM format) needed by the signing certificate
* @param int|null $signOptions Bitwise operator options for openssl_pkcs7_sign() (@see https://secure.php.net/manual/en/openssl.pkcs7.flags.php)
*/
public function __construct(string $certificate, string $privateKey, string $privateKeyPassphrase = null, string $extraCerts = null, int $signOptions = null)
public function __construct(string $certificate, string $privateKey, ?string $privateKeyPassphrase = null, ?string $extraCerts = null, ?int $signOptions = null)
{
if (!\extension_loaded('openssl')) {
throw new \LogicException('PHP extension "openssl" is required to use SMime.');

View File

@@ -43,6 +43,10 @@ class Email extends Message
private $html;
private $htmlCharset;
private $attachments = [];
/**
* @var AbstractPart|null
*/
private $cachedBody; // Used to avoid wrong body hash in DKIM signatures with multiple parts (e.g. HTML + TEXT) due to multiple boundaries.
/**
* @return $this
@@ -117,6 +121,10 @@ class Email extends Message
*/
public function from(...$addresses)
{
if (!$addresses) {
throw new LogicException('"from()" must be called with at least one address.');
}
return $this->setListAddressHeaderBody('From', $addresses);
}
@@ -272,12 +280,17 @@ class Email extends Message
}
/**
* @param resource|string $body
* @param resource|string|null $body
*
* @return $this
*/
public function text($body, string $charset = 'utf-8')
{
if (null !== $body && !\is_string($body) && !\is_resource($body)) {
throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
}
$this->cachedBody = null;
$this->text = $body;
$this->textCharset = $charset;
@@ -304,6 +317,11 @@ class Email extends Message
*/
public function html($body, string $charset = 'utf-8')
{
if (null !== $body && !\is_string($body) && !\is_resource($body)) {
throw new \TypeError(sprintf('The body must be a string, a resource or null (got "%s").', get_debug_type($body)));
}
$this->cachedBody = null;
$this->html = $body;
$this->htmlCharset = $charset;
@@ -328,8 +346,13 @@ class Email extends Message
*
* @return $this
*/
public function attach($body, string $name = null, string $contentType = null)
public function attach($body, ?string $name = null, ?string $contentType = null)
{
if (!\is_string($body) && !\is_resource($body)) {
throw new \TypeError(sprintf('The body must be a string or a resource (got "%s").', get_debug_type($body)));
}
$this->cachedBody = null;
$this->attachments[] = ['body' => $body, 'name' => $name, 'content-type' => $contentType, 'inline' => false];
return $this;
@@ -338,8 +361,9 @@ class Email extends Message
/**
* @return $this
*/
public function attachFromPath(string $path, string $name = null, string $contentType = null)
public function attachFromPath(string $path, ?string $name = null, ?string $contentType = null)
{
$this->cachedBody = null;
$this->attachments[] = ['path' => $path, 'name' => $name, 'content-type' => $contentType, 'inline' => false];
return $this;
@@ -350,8 +374,13 @@ class Email extends Message
*
* @return $this
*/
public function embed($body, string $name = null, string $contentType = null)
public function embed($body, ?string $name = null, ?string $contentType = null)
{
if (!\is_string($body) && !\is_resource($body)) {
throw new \TypeError(sprintf('The body must be a string or a resource (got "%s").', get_debug_type($body)));
}
$this->cachedBody = null;
$this->attachments[] = ['body' => $body, 'name' => $name, 'content-type' => $contentType, 'inline' => true];
return $this;
@@ -360,8 +389,9 @@ class Email extends Message
/**
* @return $this
*/
public function embedFromPath(string $path, string $name = null, string $contentType = null)
public function embedFromPath(string $path, ?string $name = null, ?string $contentType = null)
{
$this->cachedBody = null;
$this->attachments[] = ['path' => $path, 'name' => $name, 'content-type' => $contentType, 'inline' => true];
return $this;
@@ -372,6 +402,7 @@ class Email extends Message
*/
public function attachPart(DataPart $part)
{
$this->cachedBody = null;
$this->attachments[] = ['part' => $part];
return $this;
@@ -430,9 +461,13 @@ class Email extends Message
*/
private function generateBody(): AbstractPart
{
if (null !== $this->cachedBody) {
return $this->cachedBody;
}
$this->ensureValidity();
[$htmlPart, $attachmentParts, $inlineParts] = $this->prepareParts();
[$htmlPart, $otherParts, $relatedParts] = $this->prepareParts();
$part = null === $this->text ? null : new TextPart($this->text, $this->textCharset);
if (null !== $htmlPart) {
@@ -443,19 +478,19 @@ class Email extends Message
}
}
if ($inlineParts) {
$part = new RelatedPart($part, ...$inlineParts);
if ($relatedParts) {
$part = new RelatedPart($part, ...$relatedParts);
}
if ($attachmentParts) {
if ($otherParts) {
if ($part) {
$part = new MixedPart($part, ...$attachmentParts);
$part = new MixedPart($part, ...$otherParts);
} else {
$part = new MixedPart(...$attachmentParts);
$part = new MixedPart(...$otherParts);
}
}
return $part;
return $this->cachedBody = $part;
}
private function prepareParts(): ?array
@@ -463,38 +498,52 @@ class Email extends Message
$names = [];
$htmlPart = null;
$html = $this->html;
if (null !== $this->html) {
if (null !== $html) {
$htmlPart = new TextPart($html, $this->htmlCharset, 'html');
$html = $htmlPart->getBody();
preg_match_all('(<img\s+[^>]*src\s*=\s*(?:([\'"])cid:([^"]+)\\1|cid:([^>\s]+)))i', $html, $names);
preg_match_all('(<img\s+[^>]*src\s*=\s*(?:([\'"])cid:(.+?)\\1|cid:([^>\s]+)))i', $html, $names);
$names = array_filter(array_unique(array_merge($names[2], $names[3])));
}
$attachmentParts = $inlineParts = [];
// usage of reflection is a temporary workaround for missing getters that will be added in 6.2
$nameRef = new \ReflectionProperty(TextPart::class, 'name');
$nameRef->setAccessible(true);
$otherParts = $relatedParts = [];
foreach ($this->attachments as $attachment) {
$part = $this->createDataPart($attachment);
if (isset($attachment['part'])) {
$attachment['name'] = $nameRef->getValue($part);
}
$related = false;
foreach ($names as $name) {
if (isset($attachment['part'])) {
continue;
}
if ($name !== $attachment['name']) {
continue;
}
if (isset($inlineParts[$name])) {
if (isset($relatedParts[$name])) {
continue 2;
}
$attachment['inline'] = true;
$inlineParts[$name] = $part = $this->createDataPart($attachment);
$html = str_replace('cid:'.$name, 'cid:'.$part->getContentId(), $html);
$part->setDisposition('inline');
$html = str_replace('cid:'.$name, 'cid:'.$part->getContentId(), $html, $count);
if ($count) {
$related = true;
}
$part->setName($part->getContentId());
continue 2;
break;
}
if ($related) {
$relatedParts[$attachment['name']] = $part;
} else {
$otherParts[] = $part;
}
$attachmentParts[] = $this->createDataPart($attachment);
}
if (null !== $htmlPart) {
$htmlPart = new TextPart($html, $this->htmlCharset, 'html');
}
return [$htmlPart, $attachmentParts, array_values($inlineParts)];
return [$htmlPart, $otherParts, array_values($relatedParts)];
}
private function createDataPart(array $attachment): DataPart

View File

@@ -24,11 +24,11 @@ class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface
private $magicFile;
/**
* @param string $magicFile A magic file to use with the finfo instance
* @param string|null $magicFile A magic file to use with the finfo instance
*
* @see http://www.php.net/manual/en/function.finfo-open.php
*/
public function __construct(string $magicFile = null)
public function __construct(?string $magicFile = null)
{
$this->magicFile = $magicFile;
}

View File

@@ -109,6 +109,11 @@ abstract class AbstractHeader implements HeaderInterface
}
$phraseStr = $this->encodeWords($header, $string, $usedLength);
}
} elseif (str_contains($phraseStr, '(')) {
foreach (['\\', '"'] as $char) {
$phraseStr = str_replace($char, '\\'.$char, $phraseStr);
}
$phraseStr = '"'.$phraseStr.'"';
}
return $phraseStr;
@@ -195,7 +200,7 @@ abstract class AbstractHeader implements HeaderInterface
$encodingWrapperLength = \strlen('=?'.$charsetDecl.'?'.self::$encoder->getName().'??=');
if ($firstLineOffset >= 75) {
//Does this logic need to be here?
// Does this logic need to be here?
$firstLineOffset = 0;
}
@@ -226,7 +231,7 @@ abstract class AbstractHeader implements HeaderInterface
/**
* Generate a list of all tokens in the final header.
*/
protected function toTokens(string $string = null): array
protected function toTokens(?string $string = null): array
{
if (null === $string) {
$string = $this->getBodyAsString();

View File

@@ -190,7 +190,7 @@ final class Headers
return array_shift($values);
}
public function all(string $name = null): iterable
public function all(?string $name = null): iterable
{
if (null === $name) {
foreach ($this->headers as $name => $collection) {

View File

@@ -44,9 +44,9 @@ final class MailboxListHeader extends AbstractHeader
}
/**
* @throws RfcComplianceException
*
* @return Address[]
*
* @throws RfcComplianceException
*/
public function getBody(): array
{
@@ -99,9 +99,9 @@ final class MailboxListHeader extends AbstractHeader
/**
* Gets the full mailbox list of this Header as an array of valid RFC 2822 strings.
*
* @throws RfcComplianceException
*
* @return string[]
*
* @throws RfcComplianceException
*/
public function getAddressStrings(): array
{

View File

@@ -85,7 +85,7 @@ final class ParameterizedHeader extends UnstructuredHeader
* This doesn't need to be overridden in theory, but it is for implementation
* reasons to prevent potential breakage of attributes.
*/
protected function toTokens(string $string = null): array
protected function toTokens(?string $string = null): array
{
$tokens = parent::toTokens(parent::getBodyAsString());

View File

@@ -1,4 +1,4 @@
Copyright (c) 2010-2022 Fabien Potencier
Copyright (c) 2010-present Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -24,7 +24,7 @@ class Message extends RawMessage
private $headers;
private $body;
public function __construct(Headers $headers = null, AbstractPart $body = null)
public function __construct(?Headers $headers = null, ?AbstractPart $body = null)
{
$this->headers = $headers ? clone $headers : new Headers();
$this->body = $body;
@@ -42,7 +42,7 @@ class Message extends RawMessage
/**
* @return $this
*/
public function setBody(AbstractPart $body = null)
public function setBody(?AbstractPart $body = null)
{
$this->body = $body;
@@ -140,7 +140,10 @@ class Message extends RawMessage
if ($this->headers->has('Sender')) {
$sender = $this->headers->get('Sender')->getAddress();
} elseif ($this->headers->has('From')) {
$sender = $this->headers->get('From')->getAddresses()[0];
if (!$froms = $this->headers->get('From')->getAddresses()) {
throw new LogicException('A "From" header must have at least one email address.');
}
$sender = $froms[0];
} else {
throw new LogicException('An email must have a "From" or a "Sender" header.');
}

View File

@@ -83,7 +83,7 @@ final class MessageConverter
2 === \count($parts) &&
$parts[0] instanceof TextPart && 'text' === $parts[0]->getMediaType() && 'plain' === $parts[0]->getMediaSubtype() &&
$parts[1] instanceof TextPart && 'text' === $parts[1]->getMediaType() && 'html' === $parts[1]->getMediaSubtype()
) {
) {
return (new Email(clone $message->getHeaders()))
->text($parts[0]->getBody(), $parts[0]->getPreparedHeaders()->getHeaderParameter('Content-Type', 'charset') ?: 'utf-8')
->html($parts[1]->getBody(), $parts[1]->getPreparedHeaders()->getHeaderParameter('Content-Type', 'charset') ?: 'utf-8')

View File

@@ -33,7 +33,7 @@ class DataPart extends TextPart
/**
* @param resource|string $body
*/
public function __construct($body, string $filename = null, string $contentType = null, string $encoding = null)
public function __construct($body, ?string $filename = null, ?string $contentType = null, ?string $encoding = null)
{
unset($this->_parent);
@@ -51,7 +51,7 @@ class DataPart extends TextPart
$this->setDisposition('attachment');
}
public static function fromPath(string $path, string $name = null, string $contentType = null): self
public static function fromPath(string $path, ?string $name = null, ?string $contentType = null): self
{
if (null === $contentType) {
$ext = strtolower(substr($path, strrpos($path, '.') + 1));
@@ -61,13 +61,20 @@ class DataPart extends TextPart
$contentType = self::$mimeTypes->getMimeTypes($ext)[0] ?? 'application/octet-stream';
}
if (false === is_readable($path)) {
if ((is_file($path) && !is_readable($path)) || is_dir($path)) {
throw new InvalidArgumentException(sprintf('Path "%s" is not readable.', $path));
}
if (false === $handle = @fopen($path, 'r', false)) {
throw new InvalidArgumentException(sprintf('Unable to open path "%s".', $path));
}
if (!is_file($path)) {
$cache = fopen('php://temp', 'r+');
stream_copy_to_stream($handle, $cache);
$handle = $cache;
}
$p = new self($handle, $name ?: basename($path), $contentType);
$p->handle = $handle;

View File

@@ -59,4 +59,17 @@ class MessagePart extends DataPart
{
return $this->message->toIterable();
}
/**
* @return array
*/
public function __sleep()
{
return ['message'];
}
public function __wakeup()
{
$this->__construct($this->message);
}
}

View File

@@ -58,7 +58,7 @@ final class FormDataPart extends AbstractMultipartPart
$values = [];
$prepare = function ($item, $key, $root = null) use (&$values, &$prepare) {
if (\is_int($key) && \is_array($item)) {
if (null === $root && \is_int($key) && \is_array($item)) {
if (1 !== \count($item)) {
throw new InvalidArgumentException(sprintf('Form field values with integer keys can only have one array element, the key being the field name and the value being the field value, %d provided.', \count($item)));
}

View File

@@ -42,7 +42,7 @@ class TextPart extends AbstractPart
/**
* @param resource|string $body
*/
public function __construct($body, ?string $charset = 'utf-8', string $subtype = 'plain', string $encoding = null)
public function __construct($body, ?string $charset = 'utf-8', string $subtype = 'plain', ?string $encoding = null)
{
unset($this->_headers);
@@ -197,6 +197,7 @@ class TextPart extends AbstractPart
// convert resources to strings for serialization
if (null !== $this->seekable) {
$this->body = $this->getBody();
$this->seekable = null;
}
$this->_headers = $this->getHeaders();

View File

@@ -18,6 +18,9 @@ use Symfony\Component\Mime\Exception\LogicException;
*/
class RawMessage implements \Serializable
{
/**
* @var iterable|string
*/
private $message;
/**

View File

@@ -9,6 +9,10 @@
* file that was distributed with this source code.
*/
if ('cli' !== \PHP_SAPI) {
throw new Exception('This script must be run from the command line.');
}
// load new map
$data = json_decode(file_get_contents('https://cdn.jsdelivr.net/gh/jshttp/mime-db@v1.49.0/db.json'), true);
$new = [];

View File

@@ -20,7 +20,7 @@ final class EmailAttachmentCount extends Constraint
private $expectedValue;
private $transport;
public function __construct(int $expectedValue, string $transport = null)
public function __construct(int $expectedValue, ?string $transport = null)
{
$this->expectedValue = $expectedValue;
$this->transport = $transport;

View File

@@ -55,12 +55,14 @@ final class EmailHeaderSame extends Constraint
*/
protected function failureDescription($message): string
{
return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message));
return sprintf('the Email %s (value is %s)', $this->toString(), $this->getHeaderValue($message) ?? 'null');
}
private function getHeaderValue($message): string
private function getHeaderValue($message): ?string
{
$header = $message->getHeaders()->get($this->headerName);
if (null === $header = $message->getHeaders()->get($this->headerName)) {
return null;
}
return $header instanceof UnstructuredHeader ? $header->getValue() : $header->getBodyAsString();
}

View File

@@ -23,18 +23,20 @@
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"egulias/email-validator": "^2.1.10|^3.1",
"egulias/email-validator": "^2.1.10|^3.1|^4",
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
"symfony/dependency-injection": "^4.4|^5.0|^6.0",
"symfony/process": "^5.4|^6.4",
"symfony/property-access": "^4.4|^5.1|^6.0",
"symfony/property-info": "^4.4|^5.1|^6.0",
"symfony/serializer": "^5.2|^6.0"
"symfony/serializer": "^5.4.35|~6.3.12|^6.4.3"
},
"conflict": {
"egulias/email-validator": "~3.0.0",
"phpdocumentor/reflection-docblock": "<3.2.2",
"phpdocumentor/type-resolver": "<1.4.0",
"symfony/mailer": "<4.4"
"symfony/mailer": "<4.4",
"symfony/serializer": "<5.4.35|>=6,<6.3.12|>=6.4,<6.4.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Mime\\": "" },