mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
N°5122 - Update libs to new PHP requirements
This commit is contained in:
@@ -1,16 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-mime for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-mime/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-mime/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
<?php // phpcs:disable WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCaps
|
||||
|
||||
namespace Laminas\Mime;
|
||||
|
||||
use Laminas\Mail\Headers;
|
||||
use Laminas\Stdlib\ErrorHandler;
|
||||
|
||||
use function count;
|
||||
use function explode;
|
||||
use function iconv_mime_decode;
|
||||
use function preg_match;
|
||||
use function preg_match_all;
|
||||
use function preg_split;
|
||||
use function str_replace;
|
||||
use function strcasecmp;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function strtok;
|
||||
use function strtolower;
|
||||
use function substr;
|
||||
|
||||
use const E_NOTICE;
|
||||
use const E_WARNING;
|
||||
use const ICONV_MIME_DECODE_CONTINUE_ON_ERROR;
|
||||
|
||||
class Decode
|
||||
{
|
||||
/**
|
||||
@@ -29,7 +41,7 @@ class Decode
|
||||
$body = str_replace("\r", '', $body);
|
||||
|
||||
$start = 0;
|
||||
$res = [];
|
||||
$res = [];
|
||||
// find every mime part limiter and cut out the
|
||||
// string before it.
|
||||
// the part before the first boundary string is discarded:
|
||||
@@ -74,7 +86,7 @@ class Decode
|
||||
if (! $parts) {
|
||||
return;
|
||||
}
|
||||
$result = [];
|
||||
$result = [];
|
||||
$headers = null; // "Declare" variable before the first usage "for reading"
|
||||
$body = null; // "Declare" variable before the first usage "for reading"
|
||||
foreach ($parts as $part) {
|
||||
@@ -107,7 +119,7 @@ class Decode
|
||||
}
|
||||
// check for valid header at first line
|
||||
$firstlinePos = strpos($message, "\n");
|
||||
$firstline = $firstlinePos === false ? $message : substr($message, 0, $firstlinePos);
|
||||
$firstline = $firstlinePos === false ? $message : substr($message, 0, $firstlinePos);
|
||||
if (! preg_match('%^[^\s]+[^:]*:%', $firstline)) {
|
||||
$headers = new Headers();
|
||||
// TODO: we're ignoring \r for now - is this function fast enough and is it safe to assume noone needs \r?
|
||||
@@ -118,7 +130,7 @@ class Decode
|
||||
// see @Laminas-372, pops the first line off a message if it doesn't contain a header
|
||||
if (! $strict) {
|
||||
$parts = explode(':', $firstline, 2);
|
||||
if (count($parts) != 2) {
|
||||
if (count($parts) !== 2) {
|
||||
$message = substr($message, strpos($message, $EOL) + 1);
|
||||
}
|
||||
}
|
||||
@@ -131,19 +143,19 @@ class Decode
|
||||
// default is set new line
|
||||
// @todo Maybe this is too much "magic"; we should be more strict here
|
||||
if (strpos($message, $EOL . $EOL)) {
|
||||
list($headers, $body) = explode($EOL . $EOL, $message, 2);
|
||||
[$headers, $body] = explode($EOL . $EOL, $message, 2);
|
||||
// next is the standard new line
|
||||
} elseif ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
|
||||
list($headers, $body) = explode("\r\n\r\n", $message, 2);
|
||||
$headersEOL = "\r\n"; // Headers::fromString will fail with incorrect EOL
|
||||
} elseif ($EOL !== "\r\n" && strpos($message, "\r\n\r\n")) {
|
||||
[$headers, $body] = explode("\r\n\r\n", $message, 2);
|
||||
$headersEOL = "\r\n"; // Headers::fromString will fail with incorrect EOL
|
||||
// next is the other "standard" new line
|
||||
} elseif ($EOL != "\n" && strpos($message, "\n\n")) {
|
||||
list($headers, $body) = explode("\n\n", $message, 2);
|
||||
$headersEOL = "\n";
|
||||
} elseif ($EOL !== "\n" && strpos($message, "\n\n")) {
|
||||
[$headers, $body] = explode("\n\n", $message, 2);
|
||||
$headersEOL = "\n";
|
||||
// at last resort find anything that looks like a new line
|
||||
} else {
|
||||
ErrorHandler::start(E_NOTICE | E_WARNING);
|
||||
list($headers, $body) = preg_split("%([\r\n]+)\\1%U", $message, 2);
|
||||
[$headers, $body] = preg_split("%([\r\n]+)\\1%U", $message, 2);
|
||||
ErrorHandler::stop();
|
||||
}
|
||||
|
||||
@@ -173,13 +185,13 @@ class Decode
|
||||
*/
|
||||
public static function splitHeaderField($field, $wantedPart = null, $firstName = '0')
|
||||
{
|
||||
$wantedPart = strtolower($wantedPart);
|
||||
$firstName = strtolower($firstName);
|
||||
$wantedPart = strtolower($wantedPart ?? '');
|
||||
$firstName = strtolower($firstName);
|
||||
|
||||
// special case - a bit optimized
|
||||
if ($firstName === $wantedPart) {
|
||||
$field = strtok($field, ';');
|
||||
return $field[0] == '"' ? substr($field, 1, -1) : $field;
|
||||
return $field[0] === '"' ? substr($field, 1, -1) : $field;
|
||||
}
|
||||
|
||||
$field = $firstName . '=' . $field;
|
||||
@@ -192,7 +204,7 @@ class Decode
|
||||
if (strcasecmp($name, $wantedPart)) {
|
||||
continue;
|
||||
}
|
||||
if ($matches[2][$key][0] != '"') {
|
||||
if ($matches[2][$key][0] !== '"') {
|
||||
return $matches[2][$key];
|
||||
}
|
||||
return substr($matches[2][$key], 1, -1);
|
||||
@@ -203,7 +215,7 @@ class Decode
|
||||
$split = [];
|
||||
foreach ($matches[1] as $key => $name) {
|
||||
$name = strtolower($name);
|
||||
if ($matches[2][$key][0] == '"') {
|
||||
if ($matches[2][$key][0] === '"') {
|
||||
$split[$name] = substr($matches[2][$key], 1, -1);
|
||||
} else {
|
||||
$split[$name] = $matches[2][$key];
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-mime for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-mime/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-mime/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Mime\Exception;
|
||||
|
||||
interface ExceptionInterface
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-mime for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-mime/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-mime/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Mime\Exception;
|
||||
|
||||
class InvalidArgumentException extends \InvalidArgumentException implements
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-mime for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-mime/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-mime/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Mime\Exception;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-mime for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-mime/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-mime/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
<?php // phpcs:disable WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCaps,PSR12.Files.FileHeader.SpacingAfterBlock,PSR2.Methods.MethodDeclaration.Underscore
|
||||
|
||||
namespace Laminas\Mime;
|
||||
|
||||
use Laminas\Mail\Header\HeaderInterface;
|
||||
use Laminas\Mime\Mime;
|
||||
use Laminas\Mime\Part;
|
||||
|
||||
use function array_keys;
|
||||
use function base64_decode;
|
||||
use function count;
|
||||
use function current;
|
||||
use function quoted_printable_decode;
|
||||
use function sprintf;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
use function substr;
|
||||
use function trim;
|
||||
|
||||
class Message
|
||||
{
|
||||
/** @var Part[] */
|
||||
protected $parts = [];
|
||||
protected $mime = null;
|
||||
|
||||
/** @var null|Mime */
|
||||
protected $mime;
|
||||
|
||||
/**
|
||||
* Returns the list of all Laminas\Mime\Part in the message
|
||||
@@ -38,14 +51,13 @@ class Message
|
||||
/**
|
||||
* Append a new Laminas\Mime\Part to the current message
|
||||
*
|
||||
* @param \Laminas\Mime\Part $part
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return self
|
||||
*/
|
||||
public function addPart(Part $part)
|
||||
{
|
||||
foreach ($this->getParts() as $key => $row) {
|
||||
if ($part == $row) {
|
||||
foreach ($this->getParts() as $row) {
|
||||
if ($part === $row) {
|
||||
throw new Exception\InvalidArgumentException(sprintf(
|
||||
'Provided part %s already defined.',
|
||||
$part->getId()
|
||||
@@ -65,7 +77,7 @@ class Message
|
||||
*/
|
||||
public function isMultiPart()
|
||||
{
|
||||
return (count($this->parts) > 1);
|
||||
return count($this->parts) > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +86,6 @@ class Message
|
||||
* This can be used to set the boundary specifically or to use a subclass of
|
||||
* Laminas\Mime for generating the boundary.
|
||||
*
|
||||
* @param \Laminas\Mime\Mime $mime
|
||||
* @return self
|
||||
*/
|
||||
public function setMime(Mime $mime)
|
||||
@@ -89,7 +100,7 @@ class Message
|
||||
* If the object was not present, it is created and returned. Can be used to
|
||||
* determine the boundary used in this message.
|
||||
*
|
||||
* @return \Laminas\Mime\Mime
|
||||
* @return Mime
|
||||
*/
|
||||
public function getMime()
|
||||
{
|
||||
@@ -127,7 +138,7 @@ class Message
|
||||
$mime = $this->getMime();
|
||||
|
||||
$boundaryLine = $mime->boundaryLine($EOL);
|
||||
$body = 'This is a message in Mime Format. If you see this, '
|
||||
$body = 'This is a message in Mime Format. If you see this, '
|
||||
. "your mail reader does not support this format." . $EOL;
|
||||
|
||||
foreach (array_keys($this->parts) as $p) {
|
||||
@@ -188,16 +199,14 @@ class Message
|
||||
* @throws Exception\RuntimeException
|
||||
* @return array
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
protected static function _disassembleMime($body, $boundary)
|
||||
{
|
||||
// @codingStandardsIgnoreEnd
|
||||
$start = 0;
|
||||
$res = [];
|
||||
$start = 0;
|
||||
$res = [];
|
||||
// find every mime part limiter and cut out the
|
||||
// string before it.
|
||||
// the part before the first boundary string is discarded:
|
||||
$p = strpos($body, '--' . $boundary."\n", $start);
|
||||
$p = strpos($body, '--' . $boundary . "\n", $start);
|
||||
if ($p === false) {
|
||||
// no parts found!
|
||||
return [];
|
||||
@@ -239,10 +248,12 @@ class Message
|
||||
$parts = Decode::splitMessageStruct($message, $boundary, $EOL);
|
||||
} else {
|
||||
Decode::splitMessage($message, $headers, $body, $EOL);
|
||||
$parts = [[
|
||||
'header' => $headers,
|
||||
'body' => $body,
|
||||
]];
|
||||
$parts = [
|
||||
[
|
||||
'header' => $headers,
|
||||
'body' => $body,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$res = new static();
|
||||
@@ -250,7 +261,7 @@ class Message
|
||||
// now we build a new MimePart for the current Message Part:
|
||||
$properties = [];
|
||||
foreach ($part['header'] as $header) {
|
||||
/** @var \Laminas\Mail\Header\HeaderInterface $header */
|
||||
/** @var HeaderInterface $header */
|
||||
/**
|
||||
* @todo check for characterset and filename
|
||||
*/
|
||||
|
||||
@@ -1,86 +1,395 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-mime for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-mime/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-mime/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Mime;
|
||||
|
||||
use function base64_encode;
|
||||
use function chunk_split;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function max;
|
||||
use function md5;
|
||||
use function microtime;
|
||||
use function ord;
|
||||
use function preg_match;
|
||||
use function rtrim;
|
||||
use function sprintf;
|
||||
use function str_replace;
|
||||
use function strcspn;
|
||||
use function strlen;
|
||||
use function strpos;
|
||||
use function strrpos;
|
||||
use function strtoupper;
|
||||
use function substr;
|
||||
use function substr_replace;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* Support class for MultiPart Mime Messages
|
||||
*/
|
||||
class Mime
|
||||
{
|
||||
// @codingStandardsIgnoreStart
|
||||
const TYPE_OCTETSTREAM = 'application/octet-stream';
|
||||
const TYPE_TEXT = 'text/plain';
|
||||
const TYPE_HTML = 'text/html';
|
||||
const ENCODING_7BIT = '7bit';
|
||||
const ENCODING_8BIT = '8bit';
|
||||
const ENCODING_QUOTEDPRINTABLE = 'quoted-printable';
|
||||
const ENCODING_BASE64 = 'base64';
|
||||
const DISPOSITION_ATTACHMENT = 'attachment';
|
||||
const DISPOSITION_INLINE = 'inline';
|
||||
const LINELENGTH = 72;
|
||||
const LINEEND = "\n";
|
||||
const MULTIPART_ALTERNATIVE = 'multipart/alternative';
|
||||
const MULTIPART_MIXED = 'multipart/mixed';
|
||||
const MULTIPART_RELATED = 'multipart/related';
|
||||
const CHARSET_REGEX = '#=\?(?P<charset>[\x21\x23-\x26\x2a\x2b\x2d\x5e\5f\60\x7b-\x7ea-zA-Z0-9]+)\?(?P<encoding>[\x21\x23-\x26\x2a\x2b\x2d\x5e\5f\60\x7b-\x7ea-zA-Z0-9]+)\?(?P<text>[\x21-\x3e\x40-\x7e]+)#';
|
||||
// @codingStandardsIgnoreEnd
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
public const TYPE_OCTETSTREAM = 'application/octet-stream';
|
||||
public const TYPE_TEXT = 'text/plain';
|
||||
public const TYPE_HTML = 'text/html';
|
||||
public const TYPE_ENRICHED = 'text/enriched';
|
||||
public const TYPE_XML = 'text/xml';
|
||||
public const ENCODING_7BIT = '7bit';
|
||||
public const ENCODING_8BIT = '8bit';
|
||||
public const ENCODING_QUOTEDPRINTABLE = 'quoted-printable';
|
||||
public const ENCODING_BASE64 = 'base64';
|
||||
public const DISPOSITION_ATTACHMENT = 'attachment';
|
||||
public const DISPOSITION_INLINE = 'inline';
|
||||
public const LINELENGTH = 72;
|
||||
public const LINEEND = "\n";
|
||||
public const MULTIPART_ALTERNATIVE = 'multipart/alternative';
|
||||
public const MULTIPART_MIXED = 'multipart/mixed';
|
||||
public const MULTIPART_RELATED = 'multipart/related';
|
||||
public const MULTIPART_RELATIVE = 'multipart/relative';
|
||||
public const MULTIPART_REPORT = 'multipart/report';
|
||||
public const MESSAGE_RFC822 = 'message/rfc822';
|
||||
public const MESSAGE_DELIVERY_STATUS = 'message/delivery-status';
|
||||
public const CHARSET_REGEX = '#=\?(?P<charset>[\x21\x23-\x26\x2a\x2b\x2d\x5e\5f\60\x7b-\x7ea-zA-Z0-9]+)\?(?P<encoding>[\x21\x23-\x26\x2a\x2b\x2d\x5e\5f\60\x7b-\x7ea-zA-Z0-9]+)\?(?P<text>[\x21-\x3e\x40-\x7e]+)#';
|
||||
// phpcs:enable
|
||||
|
||||
/** @var null|string */
|
||||
protected $boundary;
|
||||
|
||||
/** @var int */
|
||||
protected static $makeUnique = 0;
|
||||
|
||||
// lookup-Tables for QuotedPrintable
|
||||
/**
|
||||
* Lookup-tables for QuotedPrintable
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $qpKeys = [
|
||||
"\x00","\x01","\x02","\x03","\x04","\x05","\x06","\x07",
|
||||
"\x08","\x09","\x0A","\x0B","\x0C","\x0D","\x0E","\x0F",
|
||||
"\x10","\x11","\x12","\x13","\x14","\x15","\x16","\x17",
|
||||
"\x18","\x19","\x1A","\x1B","\x1C","\x1D","\x1E","\x1F",
|
||||
"\x7F","\x80","\x81","\x82","\x83","\x84","\x85","\x86",
|
||||
"\x87","\x88","\x89","\x8A","\x8B","\x8C","\x8D","\x8E",
|
||||
"\x8F","\x90","\x91","\x92","\x93","\x94","\x95","\x96",
|
||||
"\x97","\x98","\x99","\x9A","\x9B","\x9C","\x9D","\x9E",
|
||||
"\x9F","\xA0","\xA1","\xA2","\xA3","\xA4","\xA5","\xA6",
|
||||
"\xA7","\xA8","\xA9","\xAA","\xAB","\xAC","\xAD","\xAE",
|
||||
"\xAF","\xB0","\xB1","\xB2","\xB3","\xB4","\xB5","\xB6",
|
||||
"\xB7","\xB8","\xB9","\xBA","\xBB","\xBC","\xBD","\xBE",
|
||||
"\xBF","\xC0","\xC1","\xC2","\xC3","\xC4","\xC5","\xC6",
|
||||
"\xC7","\xC8","\xC9","\xCA","\xCB","\xCC","\xCD","\xCE",
|
||||
"\xCF","\xD0","\xD1","\xD2","\xD3","\xD4","\xD5","\xD6",
|
||||
"\xD7","\xD8","\xD9","\xDA","\xDB","\xDC","\xDD","\xDE",
|
||||
"\xDF","\xE0","\xE1","\xE2","\xE3","\xE4","\xE5","\xE6",
|
||||
"\xE7","\xE8","\xE9","\xEA","\xEB","\xEC","\xED","\xEE",
|
||||
"\xEF","\xF0","\xF1","\xF2","\xF3","\xF4","\xF5","\xF6",
|
||||
"\xF7","\xF8","\xF9","\xFA","\xFB","\xFC","\xFD","\xFE",
|
||||
"\xFF"
|
||||
"\x00",
|
||||
"\x01",
|
||||
"\x02",
|
||||
"\x03",
|
||||
"\x04",
|
||||
"\x05",
|
||||
"\x06",
|
||||
"\x07",
|
||||
"\x08",
|
||||
"\x09",
|
||||
"\x0A",
|
||||
"\x0B",
|
||||
"\x0C",
|
||||
"\x0D",
|
||||
"\x0E",
|
||||
"\x0F",
|
||||
"\x10",
|
||||
"\x11",
|
||||
"\x12",
|
||||
"\x13",
|
||||
"\x14",
|
||||
"\x15",
|
||||
"\x16",
|
||||
"\x17",
|
||||
"\x18",
|
||||
"\x19",
|
||||
"\x1A",
|
||||
"\x1B",
|
||||
"\x1C",
|
||||
"\x1D",
|
||||
"\x1E",
|
||||
"\x1F",
|
||||
"\x7F",
|
||||
"\x80",
|
||||
"\x81",
|
||||
"\x82",
|
||||
"\x83",
|
||||
"\x84",
|
||||
"\x85",
|
||||
"\x86",
|
||||
"\x87",
|
||||
"\x88",
|
||||
"\x89",
|
||||
"\x8A",
|
||||
"\x8B",
|
||||
"\x8C",
|
||||
"\x8D",
|
||||
"\x8E",
|
||||
"\x8F",
|
||||
"\x90",
|
||||
"\x91",
|
||||
"\x92",
|
||||
"\x93",
|
||||
"\x94",
|
||||
"\x95",
|
||||
"\x96",
|
||||
"\x97",
|
||||
"\x98",
|
||||
"\x99",
|
||||
"\x9A",
|
||||
"\x9B",
|
||||
"\x9C",
|
||||
"\x9D",
|
||||
"\x9E",
|
||||
"\x9F",
|
||||
"\xA0",
|
||||
"\xA1",
|
||||
"\xA2",
|
||||
"\xA3",
|
||||
"\xA4",
|
||||
"\xA5",
|
||||
"\xA6",
|
||||
"\xA7",
|
||||
"\xA8",
|
||||
"\xA9",
|
||||
"\xAA",
|
||||
"\xAB",
|
||||
"\xAC",
|
||||
"\xAD",
|
||||
"\xAE",
|
||||
"\xAF",
|
||||
"\xB0",
|
||||
"\xB1",
|
||||
"\xB2",
|
||||
"\xB3",
|
||||
"\xB4",
|
||||
"\xB5",
|
||||
"\xB6",
|
||||
"\xB7",
|
||||
"\xB8",
|
||||
"\xB9",
|
||||
"\xBA",
|
||||
"\xBB",
|
||||
"\xBC",
|
||||
"\xBD",
|
||||
"\xBE",
|
||||
"\xBF",
|
||||
"\xC0",
|
||||
"\xC1",
|
||||
"\xC2",
|
||||
"\xC3",
|
||||
"\xC4",
|
||||
"\xC5",
|
||||
"\xC6",
|
||||
"\xC7",
|
||||
"\xC8",
|
||||
"\xC9",
|
||||
"\xCA",
|
||||
"\xCB",
|
||||
"\xCC",
|
||||
"\xCD",
|
||||
"\xCE",
|
||||
"\xCF",
|
||||
"\xD0",
|
||||
"\xD1",
|
||||
"\xD2",
|
||||
"\xD3",
|
||||
"\xD4",
|
||||
"\xD5",
|
||||
"\xD6",
|
||||
"\xD7",
|
||||
"\xD8",
|
||||
"\xD9",
|
||||
"\xDA",
|
||||
"\xDB",
|
||||
"\xDC",
|
||||
"\xDD",
|
||||
"\xDE",
|
||||
"\xDF",
|
||||
"\xE0",
|
||||
"\xE1",
|
||||
"\xE2",
|
||||
"\xE3",
|
||||
"\xE4",
|
||||
"\xE5",
|
||||
"\xE6",
|
||||
"\xE7",
|
||||
"\xE8",
|
||||
"\xE9",
|
||||
"\xEA",
|
||||
"\xEB",
|
||||
"\xEC",
|
||||
"\xED",
|
||||
"\xEE",
|
||||
"\xEF",
|
||||
"\xF0",
|
||||
"\xF1",
|
||||
"\xF2",
|
||||
"\xF3",
|
||||
"\xF4",
|
||||
"\xF5",
|
||||
"\xF6",
|
||||
"\xF7",
|
||||
"\xF8",
|
||||
"\xF9",
|
||||
"\xFA",
|
||||
"\xFB",
|
||||
"\xFC",
|
||||
"\xFD",
|
||||
"\xFE",
|
||||
"\xFF",
|
||||
];
|
||||
|
||||
/** @var string[] */
|
||||
public static $qpReplaceValues = [
|
||||
"=00","=01","=02","=03","=04","=05","=06","=07",
|
||||
"=08","=09","=0A","=0B","=0C","=0D","=0E","=0F",
|
||||
"=10","=11","=12","=13","=14","=15","=16","=17",
|
||||
"=18","=19","=1A","=1B","=1C","=1D","=1E","=1F",
|
||||
"=7F","=80","=81","=82","=83","=84","=85","=86",
|
||||
"=87","=88","=89","=8A","=8B","=8C","=8D","=8E",
|
||||
"=8F","=90","=91","=92","=93","=94","=95","=96",
|
||||
"=97","=98","=99","=9A","=9B","=9C","=9D","=9E",
|
||||
"=9F","=A0","=A1","=A2","=A3","=A4","=A5","=A6",
|
||||
"=A7","=A8","=A9","=AA","=AB","=AC","=AD","=AE",
|
||||
"=AF","=B0","=B1","=B2","=B3","=B4","=B5","=B6",
|
||||
"=B7","=B8","=B9","=BA","=BB","=BC","=BD","=BE",
|
||||
"=BF","=C0","=C1","=C2","=C3","=C4","=C5","=C6",
|
||||
"=C7","=C8","=C9","=CA","=CB","=CC","=CD","=CE",
|
||||
"=CF","=D0","=D1","=D2","=D3","=D4","=D5","=D6",
|
||||
"=D7","=D8","=D9","=DA","=DB","=DC","=DD","=DE",
|
||||
"=DF","=E0","=E1","=E2","=E3","=E4","=E5","=E6",
|
||||
"=E7","=E8","=E9","=EA","=EB","=EC","=ED","=EE",
|
||||
"=EF","=F0","=F1","=F2","=F3","=F4","=F5","=F6",
|
||||
"=F7","=F8","=F9","=FA","=FB","=FC","=FD","=FE",
|
||||
"=FF"
|
||||
"=00",
|
||||
"=01",
|
||||
"=02",
|
||||
"=03",
|
||||
"=04",
|
||||
"=05",
|
||||
"=06",
|
||||
"=07",
|
||||
"=08",
|
||||
"=09",
|
||||
"=0A",
|
||||
"=0B",
|
||||
"=0C",
|
||||
"=0D",
|
||||
"=0E",
|
||||
"=0F",
|
||||
"=10",
|
||||
"=11",
|
||||
"=12",
|
||||
"=13",
|
||||
"=14",
|
||||
"=15",
|
||||
"=16",
|
||||
"=17",
|
||||
"=18",
|
||||
"=19",
|
||||
"=1A",
|
||||
"=1B",
|
||||
"=1C",
|
||||
"=1D",
|
||||
"=1E",
|
||||
"=1F",
|
||||
"=7F",
|
||||
"=80",
|
||||
"=81",
|
||||
"=82",
|
||||
"=83",
|
||||
"=84",
|
||||
"=85",
|
||||
"=86",
|
||||
"=87",
|
||||
"=88",
|
||||
"=89",
|
||||
"=8A",
|
||||
"=8B",
|
||||
"=8C",
|
||||
"=8D",
|
||||
"=8E",
|
||||
"=8F",
|
||||
"=90",
|
||||
"=91",
|
||||
"=92",
|
||||
"=93",
|
||||
"=94",
|
||||
"=95",
|
||||
"=96",
|
||||
"=97",
|
||||
"=98",
|
||||
"=99",
|
||||
"=9A",
|
||||
"=9B",
|
||||
"=9C",
|
||||
"=9D",
|
||||
"=9E",
|
||||
"=9F",
|
||||
"=A0",
|
||||
"=A1",
|
||||
"=A2",
|
||||
"=A3",
|
||||
"=A4",
|
||||
"=A5",
|
||||
"=A6",
|
||||
"=A7",
|
||||
"=A8",
|
||||
"=A9",
|
||||
"=AA",
|
||||
"=AB",
|
||||
"=AC",
|
||||
"=AD",
|
||||
"=AE",
|
||||
"=AF",
|
||||
"=B0",
|
||||
"=B1",
|
||||
"=B2",
|
||||
"=B3",
|
||||
"=B4",
|
||||
"=B5",
|
||||
"=B6",
|
||||
"=B7",
|
||||
"=B8",
|
||||
"=B9",
|
||||
"=BA",
|
||||
"=BB",
|
||||
"=BC",
|
||||
"=BD",
|
||||
"=BE",
|
||||
"=BF",
|
||||
"=C0",
|
||||
"=C1",
|
||||
"=C2",
|
||||
"=C3",
|
||||
"=C4",
|
||||
"=C5",
|
||||
"=C6",
|
||||
"=C7",
|
||||
"=C8",
|
||||
"=C9",
|
||||
"=CA",
|
||||
"=CB",
|
||||
"=CC",
|
||||
"=CD",
|
||||
"=CE",
|
||||
"=CF",
|
||||
"=D0",
|
||||
"=D1",
|
||||
"=D2",
|
||||
"=D3",
|
||||
"=D4",
|
||||
"=D5",
|
||||
"=D6",
|
||||
"=D7",
|
||||
"=D8",
|
||||
"=D9",
|
||||
"=DA",
|
||||
"=DB",
|
||||
"=DC",
|
||||
"=DD",
|
||||
"=DE",
|
||||
"=DF",
|
||||
"=E0",
|
||||
"=E1",
|
||||
"=E2",
|
||||
"=E3",
|
||||
"=E4",
|
||||
"=E5",
|
||||
"=E6",
|
||||
"=E7",
|
||||
"=E8",
|
||||
"=E9",
|
||||
"=EA",
|
||||
"=EB",
|
||||
"=EC",
|
||||
"=ED",
|
||||
"=EE",
|
||||
"=EF",
|
||||
"=F0",
|
||||
"=F1",
|
||||
"=F2",
|
||||
"=F3",
|
||||
"=F4",
|
||||
"=F5",
|
||||
"=F6",
|
||||
"=F7",
|
||||
"=F8",
|
||||
"=F9",
|
||||
"=FA",
|
||||
"=FB",
|
||||
"=FC",
|
||||
"=FD",
|
||||
"=FE",
|
||||
"=FF",
|
||||
];
|
||||
// @codingStandardsIgnoreStart
|
||||
public static $qpKeysString =
|
||||
@@ -98,7 +407,7 @@ class Mime
|
||||
*/
|
||||
public static function isPrintable($str)
|
||||
{
|
||||
return (strcspn($str, static::$qpKeysString) == strlen($str));
|
||||
return strcspn($str, static::$qpKeysString) === strlen($str);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +428,7 @@ class Mime
|
||||
|
||||
// Split encoded text into separate lines
|
||||
$initialPtr = 0;
|
||||
$strLength = strlen($str);
|
||||
$strLength = strlen($str);
|
||||
while ($initialPtr < $strLength) {
|
||||
$continueAt = $strLength - $initialPtr;
|
||||
|
||||
@@ -132,11 +441,11 @@ class Mime
|
||||
// Ensure we are not splitting across an encoded character
|
||||
$endingMarkerPos = strrpos($chunk, '=');
|
||||
if ($endingMarkerPos !== false && $endingMarkerPos >= strlen($chunk) - 2) {
|
||||
$chunk = substr($chunk, 0, $endingMarkerPos);
|
||||
$chunk = substr($chunk, 0, $endingMarkerPos);
|
||||
$continueAt = $endingMarkerPos;
|
||||
}
|
||||
|
||||
if (ord($chunk[0]) == 0x2E) { // 0x2E is a dot
|
||||
if (ord($chunk[0]) === 0x2E) { // 0x2E is a dot
|
||||
$chunk = '=2E' . substr($chunk, 1);
|
||||
}
|
||||
|
||||
@@ -151,7 +460,7 @@ class Mime
|
||||
}
|
||||
|
||||
// Add string and continue
|
||||
$out .= $chunk . '=' . $lineEnd;
|
||||
$out .= $chunk . '=' . $lineEnd;
|
||||
$initialPtr += $continueAt;
|
||||
}
|
||||
|
||||
@@ -195,7 +504,7 @@ class Mime
|
||||
$lineEnd = self::LINEEND
|
||||
) {
|
||||
// Reduce line-length by the length of the required delimiter, charsets and encoding
|
||||
$prefix = sprintf('=?%s?Q?', $charset);
|
||||
$prefix = sprintf('=?%s?Q?', $charset);
|
||||
$lineLength = $lineLength - strlen($prefix) - 3;
|
||||
|
||||
$str = self::_encodeQuotedPrintable($str);
|
||||
@@ -212,16 +521,16 @@ class Mime
|
||||
$currentLine = max(count($lines) - 1, 0);
|
||||
$token = static::getNextQuotedPrintableToken($str);
|
||||
$substr = substr($str, strlen($token));
|
||||
$str = (false === $substr) ? '' : $substr;
|
||||
$str = false === $substr ? '' : $substr;
|
||||
|
||||
$tmp .= $token;
|
||||
if ($token === '=20') {
|
||||
// only if we have a single char token or space, we can append the
|
||||
// tempstring it to the current line or start a new line if necessary.
|
||||
$lineLimitReached = (strlen($lines[$currentLine] . $tmp) > $lineLength);
|
||||
$noCurrentLine = ($lines[$currentLine] === '');
|
||||
$lineLimitReached = strlen($lines[$currentLine] . $tmp) > $lineLength;
|
||||
$noCurrentLine = $lines[$currentLine] === '';
|
||||
if ($noCurrentLine && $lineLimitReached) {
|
||||
$lines[$currentLine] = $tmp;
|
||||
$lines[$currentLine] = $tmp;
|
||||
$lines[$currentLine + 1] = '';
|
||||
} elseif ($lineLimitReached) {
|
||||
$lines[$currentLine + 1] = $tmp;
|
||||
@@ -275,8 +584,8 @@ class Mime
|
||||
$lineLength = self::LINELENGTH,
|
||||
$lineEnd = self::LINEEND
|
||||
) {
|
||||
$prefix = '=?' . $charset . '?B?';
|
||||
$suffix = '?=';
|
||||
$prefix = '=?' . $charset . '?B?';
|
||||
$suffix = '?=';
|
||||
$remainingLength = $lineLength - strlen($prefix) - strlen($suffix);
|
||||
|
||||
$encodedValue = static::encodeBase64($str, $remainingLength, $lineEnd);
|
||||
@@ -319,6 +628,8 @@ class Mime
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:disable WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCaps
|
||||
|
||||
/**
|
||||
* Encode the given string with the given encoding.
|
||||
*
|
||||
|
||||
@@ -1,30 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-mime for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-mime/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-mime/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
namespace Laminas\Mime;
|
||||
|
||||
use function array_key_exists;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
use function is_resource;
|
||||
use function is_string;
|
||||
use function rewind;
|
||||
use function sprintf;
|
||||
use function stream_filter_append;
|
||||
use function stream_filter_remove;
|
||||
use function stream_get_contents;
|
||||
use function stream_get_meta_data;
|
||||
|
||||
use const STREAM_FILTER_READ;
|
||||
|
||||
/**
|
||||
* Class representing a MIME part.
|
||||
*/
|
||||
class Part
|
||||
{
|
||||
/** @var string */
|
||||
public $type = Mime::TYPE_OCTETSTREAM;
|
||||
|
||||
/** @var string */
|
||||
public $encoding = Mime::ENCODING_8BIT;
|
||||
|
||||
/** @var null|string */
|
||||
public $id;
|
||||
|
||||
/** @var null|string */
|
||||
public $disposition;
|
||||
|
||||
/** @var null|string */
|
||||
public $filename;
|
||||
|
||||
/** @var null|string */
|
||||
public $description;
|
||||
|
||||
/** @var null|string */
|
||||
public $charset;
|
||||
|
||||
/** @var null|string */
|
||||
public $boundary;
|
||||
|
||||
/** @var null|string */
|
||||
public $location;
|
||||
|
||||
/** @var null|string */
|
||||
public $language;
|
||||
|
||||
/**
|
||||
* String or stream containing the content
|
||||
*
|
||||
* @var string|resource
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/** @var bool */
|
||||
protected $isStream = false;
|
||||
|
||||
/** @var array<array-key, resource> */
|
||||
protected $filters = [];
|
||||
|
||||
/**
|
||||
@@ -47,6 +85,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set type
|
||||
*
|
||||
* @param string $type
|
||||
* @return self
|
||||
*/
|
||||
@@ -58,6 +97,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
@@ -67,6 +107,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set encoding
|
||||
*
|
||||
* @param string $encoding
|
||||
* @return self
|
||||
*/
|
||||
@@ -78,6 +119,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEncoding()
|
||||
@@ -87,6 +129,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set id
|
||||
*
|
||||
* @param string $id
|
||||
* @return self
|
||||
*/
|
||||
@@ -98,6 +141,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
@@ -107,6 +151,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set disposition
|
||||
*
|
||||
* @param string $disposition
|
||||
* @return self
|
||||
*/
|
||||
@@ -118,6 +163,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get disposition
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDisposition()
|
||||
@@ -127,6 +173,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set description
|
||||
*
|
||||
* @param string $description
|
||||
* @return self
|
||||
*/
|
||||
@@ -138,6 +185,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
@@ -147,6 +195,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set filename
|
||||
*
|
||||
* @param string $fileName
|
||||
* @return self
|
||||
*/
|
||||
@@ -158,6 +207,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName()
|
||||
@@ -167,7 +217,8 @@ class Part
|
||||
|
||||
/**
|
||||
* Set charset
|
||||
* @param string $type
|
||||
*
|
||||
* @param string $charset
|
||||
* @return self
|
||||
*/
|
||||
public function setCharset($charset)
|
||||
@@ -178,6 +229,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get charset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCharset()
|
||||
@@ -187,6 +239,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set boundary
|
||||
*
|
||||
* @param string $boundary
|
||||
* @return self
|
||||
*/
|
||||
@@ -198,6 +251,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get boundary
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBoundary()
|
||||
@@ -207,6 +261,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set location
|
||||
*
|
||||
* @param string $location
|
||||
* @return self
|
||||
*/
|
||||
@@ -218,6 +273,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get location
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocation()
|
||||
@@ -227,6 +283,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set language
|
||||
*
|
||||
* @param string $language
|
||||
* @return self
|
||||
*/
|
||||
@@ -238,6 +295,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLanguage()
|
||||
@@ -247,6 +305,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set content
|
||||
*
|
||||
* @param mixed $content String or Stream containing the content
|
||||
* @throws Exception\InvalidArgumentException
|
||||
* @return self
|
||||
@@ -269,6 +328,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Set isStream
|
||||
*
|
||||
* @param bool $isStream
|
||||
* @return self
|
||||
*/
|
||||
@@ -280,6 +340,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get isStream
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsStream()
|
||||
@@ -289,7 +350,8 @@ class Part
|
||||
|
||||
/**
|
||||
* Set filters
|
||||
* @param array $filters
|
||||
*
|
||||
* @param array<array-key, resource> $filters
|
||||
* @return self
|
||||
*/
|
||||
public function setFilters($filters = [])
|
||||
@@ -300,7 +362,8 @@ class Part
|
||||
|
||||
/**
|
||||
* Get Filters
|
||||
* @return array
|
||||
*
|
||||
* @return array<array-key, resource>
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
@@ -320,13 +383,15 @@ class Part
|
||||
return $this->isStream;
|
||||
}
|
||||
|
||||
// phpcs:disable WebimpressCodingStandard.NamingConventions.ValidVariableName.NotCamelCaps
|
||||
|
||||
/**
|
||||
* if this was created with a stream, return a filtered stream for
|
||||
* reading the content. very useful for large file attachments.
|
||||
*
|
||||
* @param string $EOL
|
||||
* @return resource
|
||||
* @throws Exception\RuntimeException if not a stream or unable to append filter
|
||||
* @throws Exception\RuntimeException If not a stream or unable to append filter.
|
||||
*/
|
||||
public function getEncodedStream($EOL = Mime::LINEEND)
|
||||
{
|
||||
@@ -340,13 +405,13 @@ class Part
|
||||
if (array_key_exists(Mime::ENCODING_QUOTEDPRINTABLE, $this->filters)) {
|
||||
stream_filter_remove($this->filters[Mime::ENCODING_QUOTEDPRINTABLE]);
|
||||
}
|
||||
$filter = stream_filter_append(
|
||||
$filter = stream_filter_append(
|
||||
$this->content,
|
||||
'convert.quoted-printable-encode',
|
||||
STREAM_FILTER_READ,
|
||||
[
|
||||
'line-length' => 76,
|
||||
'line-break-chars' => $EOL
|
||||
'line-break-chars' => $EOL,
|
||||
]
|
||||
);
|
||||
$this->filters[Mime::ENCODING_QUOTEDPRINTABLE] = $filter;
|
||||
@@ -358,13 +423,13 @@ class Part
|
||||
if (array_key_exists(Mime::ENCODING_BASE64, $this->filters)) {
|
||||
stream_filter_remove($this->filters[Mime::ENCODING_BASE64]);
|
||||
}
|
||||
$filter = stream_filter_append(
|
||||
$filter = stream_filter_append(
|
||||
$this->content,
|
||||
'convert.base64-encode',
|
||||
STREAM_FILTER_READ,
|
||||
[
|
||||
'line-length' => 76,
|
||||
'line-break-chars' => $EOL
|
||||
'line-break-chars' => $EOL,
|
||||
]
|
||||
);
|
||||
$this->filters[Mime::ENCODING_BASE64] = $filter;
|
||||
@@ -401,6 +466,7 @@ class Part
|
||||
|
||||
/**
|
||||
* Get the RAW unencoded content from this part
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawContent()
|
||||
@@ -439,7 +505,7 @@ class Part
|
||||
}
|
||||
|
||||
if ($this->id) {
|
||||
$headers[] = ['Content-ID', '<' . $this->id . '>'];
|
||||
$headers[] = ['Content-ID', '<' . $this->id . '>'];
|
||||
}
|
||||
|
||||
if ($this->disposition) {
|
||||
|
||||
Reference in New Issue
Block a user