-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImapServer.class.php
More file actions
54 lines (52 loc) · 2.03 KB
/
Copy pathImapServer.class.php
File metadata and controls
54 lines (52 loc) · 2.03 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
<?php
namespace ImapServer;
require_once( $_SERVER[ "DOCUMENT_ROOT" ] . "/MailBox.class.php" );
class ImapServer{
protected $host;
protected $port = 993;
protected $param = '/imap/ssl/novalidate-cert/readonly';
protected $request;
protected $connection;
public function __construct( $host, $login, $pass ){
$this->host = $host;
$this->request = "{"."{$this->host}:{$this->port}{$this->param}"."}";
$this->connect( $login, $pass );
}
public function connect( $login, $pass ){
$this->connection = @imap_open( $this->request, $login, $pass );
}
public function getError(){
return imap_last_error();
}
public function getMailboxNameList(){
$mailBoxList = array();
$list = imap_list( $this->connection, $this->request, "*" );
if( is_array( $list ) ){
foreach( $list as $rawMailboxName ){
$mailBoxList[] = $this->extractMailboxName( $rawMailboxName );
}
}
else{
throw new Exception( "imap_list failed: " . imap_last_error() );
}
return $mailBoxList;
}
private function extractMailboxName( $rawMailboxName ){
return str_replace( $this->request, '', mb_convert_encoding( $rawMailboxName, "UTF-8", "UTF7-IMAP" ) );
}
public function openMailbox( $mailboxName, $criteria ){
imap_reopen( $this->connection, $this->request . $mailboxName );
return new Mailbox( $this->connection, $mailboxName, $criteria );
}
public function closeConnection(){
imap_close( $this->connection );
}
public function isConnected(){
$result = true;
if( $this->connection === false ){
$result = false;
}
return $result;
}
}
// eof