IMAPTransport::fetchstructure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace rdx\imap;
4
5
class IMAPTransport implements IMAPTransportInterface {
6
7
	protected $resource; // imap_open() resource
8
9
	/** @return IMAPTransport */
10
	public function open( $server, $username, $password, $mailbox, array $flags ) {
11
		if ( !empty($flags) ) {
12
			$server .= '/' . implode('/', $flags);
13
		}
14
15
		$mailbox = '{' . $server . '}' . $mailbox;
16
		$this->resource = @imap_open($mailbox, $username, $password);
17
		if ( !$this->resource ) {
18
			$error = imap_last_error();
19
			imap_errors();
20
			imap_alerts();
21
			throw new IMAPException($error);
22
		}
23
24
		return $this;
25
	}
26
27
	/** @return string[] */
28
	public function headers() {
29
		return imap_headers($this->resource);
30
	}
31
32
	/** @return string */
33
	public function utf8( $string ) {
34
		return imap_utf8($string);
35
	}
36
37
	/** @return string[] */
38
	public function headerinfo( $msgNumber ) {
39
		return $this->iteratorToLowercaseArray(imap_headerinfo($this->resource, $msgNumber));
40
	}
41
42
	/** @return bool */
43
	public function unflag( $msgNumber, $flag ) {
44
		return imap_clearflag_full($this->resource, $msgNumber, $flag);
45
	}
46
47
	/** @return bool */
48
	public function flag( $msgNumber, $flag ) {
49
		return imap_setflag_full($this->resource, $msgNumber, $flag);
50
	}
51
52
	/** @return object */
53
	public function fetchstructure( $msgNumber ) {
54
		return imap_fetchstructure($this->resource, $msgNumber);
55
	}
56
57
	/** @return string */
58
	public function fetchbody( $msgNumber, $section ) {
59
		return imap_fetchbody($this->resource, $msgNumber, $section, FT_PEEK);
60
	}
61
62
	/** @return string */
63
	public function fetchheader( $msgNumber ) {
64
		return imap_fetchheader($this->resource, $msgNumber);
65
	}
66
67
	/** @return bool */
68
	public function expunge() {
69
		return imap_expunge($this->resource);
70
	}
71
72
	/** @return bool */
73
	public function delete( $msgNumber ) {
74
		return imap_delete($this->resource, $msgNumber);
75
	}
76
77
	/** @return object */
78
	public function mailboxmsginfo() {
79
		return (object) $this->iteratorToLowercaseArray(imap_mailboxmsginfo($this->resource));
80
	}
81
82
	/** @return array */
83
	protected function iteratorToLowercaseArray( $iterator ) {
84
		$data = [];
85
		foreach ( $iterator as $name => $value ) {
86
			$data[ strtolower($name) ] = $value;
87
		}
88
89
		return $data;
90
	}
91
92
}
93