|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Xhelp; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* You may not change or alter any portion of this comment or credits |
|
7
|
|
|
* of supporting developers from this source code or any supporting source code |
|
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
17
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
|
18
|
|
|
* @author Nazar Aziz <[email protected]> |
|
19
|
|
|
* @author XOOPS Development Team |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
if (!\defined('XHELP_CLASS_PATH')) { |
|
23
|
|
|
exit(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
// require_once XHELP_CLASS_PATH . '/mailbox.php'; |
|
27
|
|
|
require_once \XHELP_PEAR_PATH . '/Net/POP3.php'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* MailBoxPop3 class |
|
31
|
|
|
* |
|
32
|
|
|
* Part of the email submission subsystem. Implements access to a POP3 Mailbox |
|
33
|
|
|
* |
|
34
|
|
|
*/ |
|
35
|
|
|
class MailBoxPOP3 extends MailBox |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Instances of PEAR::POP3 class |
|
39
|
|
|
*/ |
|
40
|
|
|
public $_pop3; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Class Constructor |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->_pop3 = new Net_POP3(); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Connect to mailbox |
|
52
|
|
|
* @param string $server |
|
53
|
|
|
* @param int $port |
|
54
|
|
|
* @return bool |
|
55
|
|
|
*/ |
|
56
|
|
|
public function connect(string $server, int $port = 110): bool |
|
57
|
|
|
{ |
|
58
|
|
|
if ($this->_pop3->connect($server, $port)) { |
|
59
|
|
|
return true; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Send Authentication Credentials to mail server |
|
67
|
|
|
* @param string $username |
|
68
|
|
|
* @param string $password |
|
69
|
|
|
* @return bool |
|
70
|
|
|
*/ |
|
71
|
|
|
public function login(string $username, string $password): bool |
|
72
|
|
|
{ |
|
73
|
|
|
if (!PEAR::isError($this->_pop3->login($username, $password, false))) { |
|
|
|
|
|
|
74
|
|
|
return true; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return false; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Number of messages on server |
|
82
|
|
|
* @return int Number of messages |
|
83
|
|
|
*/ |
|
84
|
|
|
public function messageCount(): int |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->_pop3->numMsg(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get Headers for message |
|
91
|
|
|
* @param int $i |
|
92
|
|
|
* @return bool|string|void |
|
93
|
|
|
* @internal param Message $msg_id number |
|
94
|
|
|
* Either raw headers or false on error |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getHeaders(int $i) |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->_pop3->getRawHeaders($i); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get Message Body |
|
103
|
|
|
* @param int $i |
|
104
|
|
|
* @return mixed Either message body or false on error |
|
105
|
|
|
* @internal param Message $msg_id number |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getBody(int $i) |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->_pop3->getBody($i); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Returns the entire message with given message number. |
|
114
|
|
|
* |
|
115
|
|
|
* @param int $i |
|
116
|
|
|
* @return mixed Either entire message or false on error |
|
117
|
|
|
* @internal param Message $msg_id number |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getMsg(int $i) |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->_pop3->getMsg($i); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Marks a message for deletion. Only will be deleted if the |
|
126
|
|
|
* disconnect() method is called. |
|
127
|
|
|
* |
|
128
|
|
|
* @param int $i |
|
129
|
|
|
* @return bool Success/Failure |
|
130
|
|
|
* @internal param Message $msg_id to delete |
|
131
|
|
|
*/ |
|
132
|
|
|
public function deleteMessage(int $i): bool |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->_pop3->deleteMsg($i); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Disconnect function. Sends the QUIT command |
|
139
|
|
|
* and closes the socket. |
|
140
|
|
|
* |
|
141
|
|
|
* @return bool Success/Failure |
|
142
|
|
|
*/ |
|
143
|
|
|
public function disconnect(): bool |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->_pop3->disconnect(); |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|