Completed
Push — master ( c1617c...820ca9 )
by Rudie
02:11
created

IMAPTransport::headers()   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 0
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 imap_headerinfo($this->resource, $msgNumber);
39
	}
40
41
	public function clearflag( $msgNumber, $flag ) {
42
		return imap_clearflag_full($this->resource, $msgNumber, $flag);
43
	}
44
45
	public function setflag( $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 imap_fetchbody($this->resource, $msgNumber, implode('.', $section), FT_PEEK);
55
	}
56
57
}
58