Completed
Branch master (0ca02e)
by Rudie
02:12
created

IMAPTransport::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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