mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-04 12:42:43 +01:00
a76444a8e2
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
89 lines
2.1 KiB
PHP
89 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace PhpMimeMailParser;
|
|
|
|
use PhpMimeMailParser\Contracts\MiddleWare as MiddleWareContracts;
|
|
|
|
/**
|
|
* A stack of middleware chained together by (MiddlewareStack $next)
|
|
*/
|
|
class MiddlewareStack
|
|
{
|
|
/**
|
|
* Next MiddlewareStack in chain
|
|
*
|
|
* @var MiddlewareStack
|
|
*/
|
|
protected $next;
|
|
|
|
/**
|
|
* Middleware in this MiddlewareStack
|
|
*
|
|
* @var Middleware
|
|
*/
|
|
protected $middleware;
|
|
|
|
/**
|
|
* Construct the first middleware in this MiddlewareStack
|
|
* The next middleware is chained through $MiddlewareStack->add($Middleware)
|
|
*
|
|
* @param Middleware $middleware
|
|
*/
|
|
public function __construct(MiddleWareContracts $middleware = null)
|
|
{
|
|
$this->middleware = $middleware;
|
|
}
|
|
|
|
/**
|
|
* Creates a chained middleware in MiddlewareStack
|
|
*
|
|
* @param Middleware $middleware
|
|
* @return MiddlewareStack Immutable MiddlewareStack
|
|
*/
|
|
public function add(MiddleWareContracts $middleware)
|
|
{
|
|
$stack = new static($middleware);
|
|
$stack->next = $this;
|
|
return $stack;
|
|
}
|
|
|
|
/**
|
|
* Parses the MimePart by passing it through the Middleware
|
|
* @param MimePart $part
|
|
* @return MimePart
|
|
*/
|
|
public function parse(MimePart $part)
|
|
{
|
|
if (!$this->middleware) {
|
|
return $part;
|
|
}
|
|
$part = call_user_func(array($this->middleware, 'parse'), $part, $this->next);
|
|
return $part;
|
|
}
|
|
|
|
/**
|
|
* Creates a MiddlewareStack based on an array of middleware
|
|
*
|
|
* @param Middleware[] $middlewares
|
|
* @return MiddlewareStack
|
|
*/
|
|
public static function factory(array $middlewares = array())
|
|
{
|
|
$stack = new static;
|
|
foreach ($middlewares as $middleware) {
|
|
$stack = $stack->add($middleware);
|
|
}
|
|
return $stack;
|
|
}
|
|
|
|
/**
|
|
* Allow calling MiddlewareStack instance directly to invoke parse()
|
|
*
|
|
* @param MimePart $part
|
|
* @return MimePart
|
|
*/
|
|
public function __invoke(MimePart $part)
|
|
{
|
|
return $this->parse($part);
|
|
}
|
|
}
|