Completed
Push — master ( 820ca9...637b42 )
by Rudie
02:13
created

IMAPMessagePart::content()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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
29
			while ( count($parts) == 1 && empty($parts[0]->bytes) && !empty($parts[0]->parts) ) {
30
				$this->skippedParts[] = $parts[0];
31
				$parts = $parts[0]->parts;
32
			}
33
34
			foreach ( $parts as $n => $part ) {
35
				$this->parts[] = $this->message()->createMessagePart(
36
					$part,
37
					array_merge($this->section(), [$n+1])
38
				);
39
			}
40
		}
41
42
		return $this->parts;
43
	}
44
45
	public function structure() {
46
		return $this->structure;
47
	}
48
49
	public function content() {
50
		$body = $this->message()->mailbox()->imap()->fetchbody(
51
			$this->message()->msgNumber(),
52
			implode('.', $this->section())
53
		);
54
		return $this->decode($body);
55
	}
56
57
	public function decode( $content ) {
58
		return quoted_printable_decode($content);
59
	}
60
61
	public function message() {
62
		return $this->message;
63
	}
64
65
	public function section() {
66
		return $this->section;
67
	}
68
69
	public function subtype() {
70
		return $this->subtype;
71
	}
72
73
}
74