|
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
|
|
|
|