/
class.connectionimapbounce.php
148 lines (133 loc) · 3.15 KB
/
class.connectionimapbounce.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
require_once 'class.settingimapbounce.php';
/**
* ImapBounce - PHP parse bounced emails.
* PHP Version 5
* @package ConnectionImapBounce
* @link https://github.com/archieDeveloper/ImapBounce/ The ImapBounce GitHub project
* @author Arkady Kozhedub (archie) <arkadij.ok@gmail.com>
* @copyright 2015, Arkady Kozhedub
* @license GPL licensed
*/
class ConnectionImapBounce
{
/**
* Setting mailbox
* @var object
*/
public $setting;
/**
* Resource authorization
* @var resource
*/
private $_connection = null;
/**
* Information authorization
* @var object
*/
private $_connectionCheck = null;
function __construct()
{
$this->setting = new SettingImapBounce();
}
/**
* Authorization in Imap service
* @param array $options setting authorization
* @access public
* @return bool
* @throws Exception
*/
public function connect(array $options = array())
{
$this->setting->set($options);
if($this->_connection == null) {
$this->_connection = $this->_connect();
}
if($this->_connection) {
return true;
}
return false;
}
/**
* Get information about authorization
* @access public
* @return object|bool
*/
public function getImapCheck()
{
if($this->_connectionCheck != null) {
return $this->_connectionCheck;
}
if($this->isAuth()){
return imap_check($this->_connection);
}
return false;
}
/**
* Get resource
* @access public
* @return resourse|bool
*/
public function getResource()
{
if($this->_connection != null) {
return $this->_connection;
}
return false;
}
/**
* Is authorization?
* @access public
* @return boolean
*/
public function isAuth()
{
try {
if($this->connect()) {
return true;
}
} catch (Exception $e) {
echo 'Error: ', $e->getMessage(), self::CRLF;
return false;
}
}
/**
* Disconnect from Imap
* @access public
* @return void
*/
public function disconnect()
{
$this->_disconnect();
}
/********************
* Private methods *
********************/
/**
* Connect to a Imap server
* @access private
* @return resource
*/
private function _connect()
{
return imap_open(
'{'.$this->setting->getMailboxHost().':'.$this->setting->getMailboxPort().'/'.implode('/', $this->setting->getMailboxProtocols()).'}'.$this->setting->getMailboxType(),
$this->setting->getMailboxUser(),
$this->setting->getMailboxPassword()
);
}
/**
* Disconnect to Imap
* @access private
* @return boolean
*/
private function _disconnect()
{
if($this->isAuth()){
$resultDiconnect = imap_close($this->_connection);
$this->_connection = null;
return $resultDiconnect;
}
return false;
}
}