1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00
phorge-phorge/externals/mimemailparser/MimePart.php
Andre Klapper a76444a8e2 Update mimemailparser from May 2011 version to 8.0.4
Summary:
Bump to version 8.0.4 from 2024-09-11 per https://github.com/php-mime-mail-parser/php-mime-mail-parser/releases before this ancient code copy falls apart.
`scripts/mail/mail_handler.php` (used for incoming (!) mail) is the only consumer.

Closes T15940

Test Plan: Feed `mail_handler.php` with various test emails (formats: plain text, HTML, multipart; encodings: UTF-8, ASCII, ISO-8859-something) by manually replacing `php://stdin` with corresponding text files and adding some `phlog`s for output checking as I don't have mail server glue handy. Get only expected errors for broken emails.

Reviewers: O1 Blessed Committers, 20after4

Reviewed By: O1 Blessed Committers, 20after4

Subscribers: 20after4, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15940

Differential Revision: https://we.phorge.it/D25829
2024-11-01 08:59:05 +01:00

119 lines
2.1 KiB
PHP

<?php
namespace PhpMimeMailParser;
/**
* Mime Part
* Represents the results of mailparse_msg_get_part_data()
*
* Note ArrayAccess::offsetSet() cannot modify deeply nestated arrays.
* When modifying use getPart() and setPart() for deep nested data modification
*
* @example
*
* $MimePart['headers']['from'] = 'modified@example.com' // fails
*
* // correct
* $part = $MimePart->getPart();
* $part['headers']['from'] = 'modified@example.com';
* $MimePart->setPart($part);
*/
class MimePart implements \ArrayAccess
{
/**
* Internal mime part
*
* @var array
*/
protected $part = array();
/**
* Immutable Part Id
*
* @var string
*/
private $id;
/**
* Create a mime part
*
* @param array $part
* @param string $id
*/
public function __construct($id, array $part)
{
$this->part = $part;
$this->id = $id;
}
/**
* Retrieve the part Id
*
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Retrieve the part data
*
* @return array
*/
public function getPart()
{
return $this->part;
}
/**
* Set the mime part data
*
* @param array $part
* @return void
*/
public function setPart(array $part)
{
$this->part = $part;
}
/**
* ArrayAccess
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (is_null($offset)) {
$this->part[] = $value;
return;
}
$this->part[$offset] = $value;
}
/**
* ArrayAccess
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->part[$offset]);
}
/**
* ArrayAccess
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->part[$offset]);
}
/**
* ArrayAccess
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return isset($this->part[$offset]) ? $this->part[$offset] : null;
}
}