-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathBodyPartDecoder.php
More file actions
47 lines (37 loc) · 1.12 KB
/
BodyPartDecoder.php
File metadata and controls
47 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace DirectoryTree\ImapEngine\Support;
use DirectoryTree\ImapEngine\BodyStructurePart;
use DirectoryTree\ImapEngine\MessageParser;
class BodyPartDecoder
{
/**
* Decode raw text/html content using the part's metadata.
*/
public static function text(BodyStructurePart $part, ?string $content): ?string
{
$content = rtrim($content ?? '', "\r\n");
if ($content === '') {
return null;
}
$parsed = MessageParser::parse(
MimeMessage::make($part, $content)
);
return $part->subtype() === 'html'
? $parsed->getHtmlContent()
: $parsed->getTextContent();
}
/**
* Decode raw binary content using the part's metadata.
*/
public static function binary(BodyStructurePart $part, ?string $content): ?string
{
$content = rtrim($content ?? '', "\r\n");
if ($content === '') {
return null;
}
$parsed = MessageParser::parse(
MimeMessage::make($part, $content)
);
return $parsed->getBinaryContentStream()?->getContents();
}
}