Completed
Push — master ( e3e1e6...8ca8f6 )
by Rudie
02:01
created

IMAPMessagePart   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 15
c 7
b 0
f 0
lcom 1
cbo 4
dl 0
loc 69
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B parts() 0 18 7
A structure() 0 3 1
A content() 0 7 1
A decode() 0 3 1
A message() 0 3 1
A mailbox() 0 3 1
A section() 0 3 1
A subtype() 0 3 1
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