1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace rdx\imap; |
4
|
|
|
|
5
|
|
|
use rdx\imap\IMAPMessage; |
6
|
|
|
use rdx\imap\IMAPMessageContent; |
7
|
|
|
|
8
|
|
|
class IMAPMessagePart extends IMAPMessageContent implements IMAPMessagePartInterface { |
9
|
|
|
|
10
|
|
|
protected $section = []; |
11
|
|
|
protected $subtype = ''; |
12
|
|
|
|
13
|
|
|
protected $message; // rdx\imap\IMAPMessage |
14
|
|
|
protected $skippedParts = []; // Array<stdClass> |
15
|
|
|
|
16
|
|
|
public function __construct( IMAPMessage $message, $structure, array $section ) { |
17
|
|
|
$this->message = $message; |
18
|
|
|
$this->structure = $structure; |
19
|
|
|
$this->section = $section; |
20
|
|
|
$this->subtype = strtoupper($structure->subtype); |
21
|
|
|
|
22
|
|
|
$this->parts(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function parts() { |
26
|
|
|
if ( empty($this->parts) && !empty($this->structure()->parts) ) { |
27
|
|
|
$parts = $this->structure()->parts; |
28
|
|
|
while ( count($parts) == 1 && empty($parts[0]->bytes) && !empty($parts[0]->parts) ) { |
29
|
|
|
$this->skippedParts[] = $parts[0]; |
30
|
|
|
$parts = $parts[0]->parts; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
foreach ( $parts as $n => $part ) { |
34
|
|
|
$this->parts[] = $this->message()->createMessagePart( |
35
|
|
|
$part, |
36
|
|
|
array_merge($this->section(), [$n+1]) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $this->parts; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function structure() { |
45
|
|
|
return $this->structure; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function content() { |
49
|
|
|
$body = $this->message()->mailbox()->imap()->fetchbody( |
50
|
|
|
$this->message()->msgNumber(), |
51
|
|
|
implode('.', $this->section()) |
52
|
|
|
); |
53
|
|
|
return $this->decode($body); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function decode( $content ) { |
57
|
|
|
return quoted_printable_decode($content); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function message() { |
61
|
|
|
return $this->message; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function mailbox() { |
65
|
|
|
return $this->message()->mailbox(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function section() { |
69
|
|
|
return $this->section; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function subtype() { |
73
|
|
|
return $this->subtype; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|