-
Notifications
You must be signed in to change notification settings - Fork 4
/
postieIMAP.php
176 lines (167 loc) · 4.35 KB
/
postieIMAP.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
/**
* @author Dirk Elmendorf
* @style Compliant
* @testframework Compliant
* @package Postie
* @copyright Copyright 2005 Dirk Elmendorf
*/
/**
* This class handles the details of an IMAP connection
*
* @author Dirk Elmendorf
* @package Postie
*/
class PostieIMAP {
var $_connected;
var $_protocol;
var $_ssl;
var $_self_cert;
var $_tls_on;
var $_connection;
function PostieIMAP($protocol = "imap",$ssl_on = false,$self_cert = true) {
$this->_connected = false;
$this->_tls_on = false;
$this->_protocol = strtolower($protocol);
$this->_ssl = $ssl_on;
$this->_self_cert = $self_cert;
}
/**
*call this to turn on TLS
*/
function TLSOn() {
$this->_tls_on = true;
}
/**
* call this if you want to verify the cert
*/
function RealCert() {
$this->self_cert = false;
}
/**
* Shows if the object is actually connected
*@return boolean
*/
function isConnected() {
return($this->_connected);
}
/**
*Opens a connection to the server
*@return boolean
*/
function connect($server,$port,$login,$password) {
$option = "/service=".$this->_protocol;
if ($this->_ssl) {
$option .= "/ssl";
}
if ($this->_tls_on) {
$option .= "/tls";
}
else {
$option .= "/notls";
}
if ($this->_self_cert) {
$option .= "/novalidate-cert";
}
if (eregi("google",$server) {
//Fix from Jim Hodgson http://www.jimhodgson.com/2006/07/19/postie/
$server_string = "{".$server.":".$port.$option."}INBOX";
}
else {
$server_string = "{".$server.":".$port.$option."}";
}
$this->_connection = imap_open($server_string,$login,$password);
if ($this->_connection) {
$this->_connected = true;
}
return($this->_connected);
}
/**
* Returns a count of the number of messages
* @return integer
*/
function getNumberOfMessages() {
return(imap_num_msg($this->_connection));
}
/**
* Gets the raw email message from the server
* @return string
*/
function fetchEmail($index){
if ($index < 1 || $index > ($this->getNumberOfMessages() + 1)) {
die("Invalid IMAP/POP3 message index!");
}
$email = imap_fetchheader($this->_connection,$index);
$email .= imap_body($this->_connection,$index);
return($email);
}
/**
* Marks a message for deletion
*/
function deleteMessage($index){
imap_delete($this->_connection,$index);
}
/**
* Handles purging any files that are marked for deletion
*/
function expungeMessages(){
imap_expunge($this->_connection);
}
/**
* Handles disconnecting from the server
*/
function disconnect(){
imap_close($this->_connection);
$this->_connection = false;
}
/**
*@return string
*/
function error() {
return(imap_last_error());
}
/**
* Handles returning the right kind of object
* @return PostieIMAP|PostieIMAPSSL|PostimePOP3SSL
* @static
*/
function &Factory($protocol) {
switch(strtolower($protocol)) {
case "imap":
$object = &new PostieIMAP();
break;
case "imap-ssl":
$object = &new PostieIMAPSSL();
break;
case "pop3-ssl":
$object = &new PostiePOP3SSL();
break;
default:
die("$protocol not supported");
}
return($object);
}
}
/**
* This class handles the details of an IMAP-SSL connection
*
* @author Dirk Elmendorf
* @package Postie
*/
class PostieIMAPSSL Extends PostieIMAP{
function PostieIMAPSSL($protocol = "imap",$ssl_on = true,$self_cert = true) {
PostieIMAP::PostieIMAP($protocol,$ssl_on,$self_cert);
}
}
/**
* This class handles the details of an POP3-SSL connection
*
* @author Dirk Elmendorf
* @package Postie
*/
class PostiePOP3SSL Extends PostieIMAP {
function PostiePOP3SSL($protocol = "pop3",$ssl_on = true,$self_cert = true) {
PostieIMAP::PostieIMAP($protocol,$ssl_on,$self_cert);
}
}
?>