ImapMailReader.php
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Created by PhpStorm.
* User: Tsurkanov
* Date: 02.11.2015
* Time: 16:56
*/
namespace common\components\mail;
class ImapMailReader extends MailReader {
function __construct( $hostname, $username, $password )
{
parent::__construct($hostname, $username, $password);
$this->connection = imap_open($hostname, $username, $password);
if ($this->connection === false)
throw new \Exception('Cannot connect to mail: ' . imap_last_error());
}
public function getEmails( $flag )
{
return imap_search( $this->connection, $flag );
}
public function getEmailBody( $email_number, $section )
{
return imap_fetchbody($this->connection, $email_number, $section );
}
/**
* @return mixed
*/
public function getListMailboxes()
{
return imap_list($this->connection, $this->hostname, "*");
}
public function getCurrentEmailStructure( $email_number )
{
return imap_fetchstructure($this->connection, $email_number);
}
public function reOpen( $hostname )
{
imap_reopen( $this->connection, $hostname );
}
function __destruct()
{
/* close the connection */
imap_close( $this->connection );
}
}