mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-11 03:51:25 +01:00
FIX: Update swiftmailer librairies
This commit is contained in:
@@ -43,14 +43,14 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
private $boundary;
|
||||
|
||||
/** Mime types to be used based on the nesting level */
|
||||
private $compositeRanges = array(
|
||||
'multipart/mixed' => array(self::LEVEL_TOP, self::LEVEL_MIXED),
|
||||
'multipart/alternative' => array(self::LEVEL_MIXED, self::LEVEL_ALTERNATIVE),
|
||||
'multipart/related' => array(self::LEVEL_ALTERNATIVE, self::LEVEL_RELATED),
|
||||
);
|
||||
private $compositeRanges = [
|
||||
'multipart/mixed' => [self::LEVEL_TOP, self::LEVEL_MIXED],
|
||||
'multipart/alternative' => [self::LEVEL_MIXED, self::LEVEL_ALTERNATIVE],
|
||||
'multipart/related' => [self::LEVEL_ALTERNATIVE, self::LEVEL_RELATED],
|
||||
];
|
||||
|
||||
/** A set of filter rules to define what level an entity should be nested at */
|
||||
private $compoundLevelFilters = array();
|
||||
private $compoundLevelFilters = [];
|
||||
|
||||
/** The nesting level of this entity */
|
||||
private $nestingLevel = self::LEVEL_ALTERNATIVE;
|
||||
@@ -59,20 +59,20 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
private $cache;
|
||||
|
||||
/** Direct descendants of this entity */
|
||||
private $immediateChildren = array();
|
||||
private $immediateChildren = [];
|
||||
|
||||
/** All descendants of this entity */
|
||||
private $children = array();
|
||||
private $children = [];
|
||||
|
||||
/** The maximum line length of the body of this entity */
|
||||
private $maxLineLength = 78;
|
||||
|
||||
/** The order in which alternative mime types should appear */
|
||||
private $alternativePartOrder = array(
|
||||
private $alternativePartOrder = [
|
||||
'text/plain' => 1,
|
||||
'text/html' => 2,
|
||||
'multipart/related' => 3,
|
||||
);
|
||||
];
|
||||
|
||||
/** The CID of this entity */
|
||||
private $id;
|
||||
@@ -84,20 +84,15 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
/**
|
||||
* Create a new SimpleMimeEntity with $headers, $encoder and $cache.
|
||||
*
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
*/
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator)
|
||||
{
|
||||
$this->cacheKey = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
|
||||
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
|
||||
$this->cache = $cache;
|
||||
$this->headers = $headers;
|
||||
$this->idGenerator = $idGenerator;
|
||||
$this->setEncoder($encoder);
|
||||
$this->headers->defineOrdering(array('Content-Type', 'Content-Transfer-Encoding'));
|
||||
$this->headers->defineOrdering(['Content-Type', 'Content-Transfer-Encoding']);
|
||||
|
||||
// This array specifies that, when the entire MIME document contains
|
||||
// $compoundLevel, then for each child within $level, if its Content-Type
|
||||
@@ -112,14 +107,14 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
// )
|
||||
// )
|
||||
|
||||
$this->compoundLevelFilters = array(
|
||||
(self::LEVEL_ALTERNATIVE + self::LEVEL_RELATED) => array(
|
||||
self::LEVEL_ALTERNATIVE => array(
|
||||
$this->compoundLevelFilters = [
|
||||
(self::LEVEL_ALTERNATIVE + self::LEVEL_RELATED) => [
|
||||
self::LEVEL_ALTERNATIVE => [
|
||||
'text/plain' => self::LEVEL_ALTERNATIVE,
|
||||
'text/html' => self::LEVEL_RELATED,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->id = $this->idGenerator->generateId();
|
||||
}
|
||||
@@ -168,6 +163,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
return $this->getHeaderFieldModel('Content-Type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Body Content-type of this entity.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBodyContentType()
|
||||
{
|
||||
return $this->userContentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Content-type of this entity.
|
||||
*
|
||||
@@ -293,16 +298,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
public function setChildren(array $children, $compoundLevel = null)
|
||||
{
|
||||
// TODO: Try to refactor this logic
|
||||
$compoundLevel = isset($compoundLevel) ? $compoundLevel : $this->getCompoundLevel($children);
|
||||
$immediateChildren = array();
|
||||
$grandchildren = array();
|
||||
$compoundLevel = $compoundLevel ?? $this->getCompoundLevel($children);
|
||||
$immediateChildren = [];
|
||||
$grandchildren = [];
|
||||
$newContentType = $this->userContentType;
|
||||
|
||||
foreach ($children as $child) {
|
||||
$level = $this->getNeededChildLevel($child, $compoundLevel);
|
||||
if (empty($immediateChildren)) {
|
||||
//first iteration
|
||||
$immediateChildren = array($child);
|
||||
$immediateChildren = [$child];
|
||||
} else {
|
||||
$nextLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
|
||||
if ($nextLevel == $level) {
|
||||
@@ -311,7 +316,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
// Re-assign immediateChildren to grandchildren
|
||||
$grandchildren = array_merge($grandchildren, $immediateChildren);
|
||||
// Set new children
|
||||
$immediateChildren = array($child);
|
||||
$immediateChildren = [$child];
|
||||
} else {
|
||||
$grandchildren[] = $child;
|
||||
}
|
||||
@@ -375,7 +380,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
}
|
||||
|
||||
$this->body = $body;
|
||||
if (isset($contentType)) {
|
||||
if (null !== $contentType) {
|
||||
$this->setContentType($contentType);
|
||||
}
|
||||
|
||||
@@ -395,8 +400,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
/**
|
||||
* Set the encoder used for the body of this entity.
|
||||
*
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEncoder(Swift_Mime_ContentEncoder $encoder)
|
||||
@@ -420,7 +423,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
public function getBoundary()
|
||||
{
|
||||
if (!isset($this->boundary)) {
|
||||
$this->boundary = '_=_swift_'.time().'_'.md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true)).'_=_';
|
||||
$this->boundary = '_=_swift_'.time().'_'.bin2hex(random_bytes(16)).'_=_';
|
||||
}
|
||||
|
||||
return $this->boundary;
|
||||
@@ -457,8 +460,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
/**
|
||||
* Receive notification that the encoder of this entity or a parent entity
|
||||
* has changed.
|
||||
*
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
*/
|
||||
public function encoderChanged(Swift_Mime_ContentEncoder $encoder)
|
||||
{
|
||||
@@ -522,8 +523,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
/**
|
||||
* Write this entire entity to a {@see Swift_InputByteStream}.
|
||||
*
|
||||
* @param Swift_InputByteStream
|
||||
*/
|
||||
public function toByteStream(Swift_InputByteStream $is)
|
||||
{
|
||||
@@ -535,8 +534,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
/**
|
||||
* Write this entire entity to a {@link Swift_InputByteStream}.
|
||||
*
|
||||
* @param Swift_InputByteStream
|
||||
*/
|
||||
protected function bodyToByteStream(Swift_InputByteStream $is)
|
||||
{
|
||||
@@ -637,7 +634,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
*/
|
||||
protected function fixHeaders()
|
||||
{
|
||||
if (count($this->immediateChildren)) {
|
||||
if (\count($this->immediateChildren)) {
|
||||
$this->setHeaderParameter('Content-Type', 'boundary',
|
||||
$this->getBoundary()
|
||||
);
|
||||
@@ -726,7 +723,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
private function getNeededChildLevel($child, $compoundLevel)
|
||||
{
|
||||
$filter = array();
|
||||
$filter = [];
|
||||
foreach ($this->compoundLevelFilters as $bitmask => $rules) {
|
||||
if (($compoundLevel & $bitmask) === $bitmask) {
|
||||
$filter = $rules + $filter;
|
||||
@@ -734,7 +731,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
}
|
||||
|
||||
$realLevel = $child->getNestingLevel();
|
||||
$lowercaseType = strtolower($child->getContentType());
|
||||
$lowercaseType = strtolower($child->getContentType() ?? '');
|
||||
|
||||
if (isset($filter[$realLevel]) && isset($filter[$realLevel][$lowercaseType])) {
|
||||
return $filter[$realLevel][$lowercaseType];
|
||||
@@ -769,7 +766,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
$shouldSort = false;
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
// NOTE: This include alternative parts moved into a related part
|
||||
if ($child->getNestingLevel() == self::LEVEL_ALTERNATIVE) {
|
||||
if (self::LEVEL_ALTERNATIVE == $child->getNestingLevel()) {
|
||||
$shouldSort = true;
|
||||
break;
|
||||
}
|
||||
@@ -778,13 +775,13 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
// Sort in order of preference, if there is one
|
||||
if ($shouldSort) {
|
||||
// Group the messages by order of preference
|
||||
$sorted = array();
|
||||
$sorted = [];
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
$type = $child->getContentType();
|
||||
$level = array_key_exists($type, $this->alternativePartOrder) ? $this->alternativePartOrder[$type] : max($this->alternativePartOrder) + 1;
|
||||
$level = \array_key_exists($type, $this->alternativePartOrder) ? $this->alternativePartOrder[$type] : max($this->alternativePartOrder) + 1;
|
||||
|
||||
if (empty($sorted[$level])) {
|
||||
$sorted[$level] = array();
|
||||
$sorted[$level] = [];
|
||||
}
|
||||
|
||||
$sorted[$level][] = $child;
|
||||
@@ -792,7 +789,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
ksort($sorted);
|
||||
|
||||
$this->immediateChildren = array_reduce($sorted, 'array_merge', array());
|
||||
$this->immediateChildren = array_reduce($sorted, 'array_merge', []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -813,11 +810,17 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
{
|
||||
$this->headers = clone $this->headers;
|
||||
$this->encoder = clone $this->encoder;
|
||||
$this->cacheKey = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
|
||||
$children = array();
|
||||
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
|
||||
$children = [];
|
||||
foreach ($this->children as $pos => $child) {
|
||||
$children[$pos] = clone $child;
|
||||
}
|
||||
$this->setChildren($children);
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
|
||||
$this->cache = new Swift_KeyCache_ArrayKeyCache(new Swift_KeyCache_SimpleKeyCacheInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user