1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the ZBateson\MailMimeParser project. |
4
|
|
|
* |
5
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
6
|
|
|
*/ |
7
|
|
|
namespace ZBateson\MailMimeParser; |
8
|
|
|
|
9
|
|
|
use GuzzleHttp\Psr7; |
10
|
|
|
use ZBateson\MailMimeParser\Message\Extension; |
|
|
|
|
11
|
|
|
use ZBateson\MailMimeParser\Message\ExtensionsManager; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Parses a MIME message into a \ZBateson\MailMimeParser\Message object. |
15
|
|
|
* |
16
|
|
|
* To invoke, call parse on a MailMimeParser object. |
17
|
|
|
* |
18
|
|
|
* $handle = fopen('path/to/file.txt'); |
19
|
|
|
* $parser = new MailMimeParser(); |
20
|
|
|
* $parser->parse($handle); |
21
|
|
|
* fclose($handle); |
22
|
|
|
* |
23
|
|
|
* @author Zaahid Bateson |
24
|
|
|
*/ |
25
|
|
|
class MailMimeParser |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var string the default charset used to encode strings (or string content |
29
|
|
|
* like streams) returned by MailMimeParser (for e.g. the string |
30
|
|
|
* returned by calling $message->getTextContent()). |
31
|
|
|
*/ |
32
|
|
|
const DEFAULT_CHARSET = 'UTF-8'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \ZBateson\MailMimeParser\Container dependency injection container |
36
|
|
|
*/ |
37
|
|
|
protected $di; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Extension[] Array of extensions. |
41
|
|
|
*/ |
42
|
|
|
private $extensions = []; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Sets up the parser. |
46
|
|
|
* |
47
|
|
|
* @param Container $di pass a Container object to use it for |
48
|
|
|
* initialization. |
49
|
|
|
*/ |
50
|
|
|
public function __construct(Container $di = null) |
51
|
|
|
{ |
52
|
|
|
if ($di === null) { |
53
|
|
|
$di = new Container(); |
54
|
|
|
} |
55
|
|
|
$this->di = $di; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Updates the array of extensions used when parsing a message. |
60
|
|
|
* |
61
|
|
|
* @param \ZBateson\MailMimeParser\Message\Extension[] $extensions |
62
|
|
|
*/ |
63
|
|
|
public function setExtensions(array $extensions) |
64
|
|
|
{ |
65
|
|
|
$this->extensions = $extensions; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Parses the passed stream handle into a ZBateson\MailMimeParser\Message |
70
|
|
|
* object and returns it. |
71
|
|
|
* |
72
|
|
|
* Internally, the message is first copied to a temp stream (with php://temp |
73
|
|
|
* which may keep it in memory or write it to disk) and its stream is used. |
74
|
|
|
* That way if the message is too large to hold in memory it can be written |
75
|
|
|
* to a temporary file if need be. |
76
|
|
|
* |
77
|
|
|
* @param resource|string $handleOrString the resource handle to the input |
78
|
|
|
* stream of the mime message, or a string containing a mime message |
79
|
|
|
* @return \ZBateson\MailMimeParser\Message |
80
|
|
|
*/ |
81
|
|
|
public function parse($handleOrString) |
82
|
|
|
{ |
83
|
|
|
$stream = Psr7\stream_for($handleOrString); |
|
|
|
|
84
|
|
|
$copy = Psr7\stream_for(fopen('php://temp', 'r+')); |
85
|
|
|
|
86
|
|
|
Psr7\copy_to_stream($stream, $copy); |
|
|
|
|
87
|
|
|
$copy->rewind(); |
88
|
|
|
|
89
|
|
|
// don't close it when $stream gets destroyed |
90
|
|
|
$stream->detach(); |
91
|
|
|
$parser = $this->di->newMessageParser(); |
92
|
|
|
return $parser->parse($copy, $this->extensions); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths