/
Pop3.php
80 lines (73 loc) · 2.35 KB
/
Pop3.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
<?php
/**
* Copyright 2013 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2013 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
/**
* PHP stream connection to the POP3 server.
*
* NOTE: This class is NOT intended to be accessed outside of the package.
* There is NO guarantees that the API of this class will not change across
* versions.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2013 Horde LLC
* @internal
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Imap_Client
*/
class Horde_Imap_Client_Socket_Connection_Pop3 extends Horde\Socket\Client
{
/**
* Writes data to the POP3 output stream.
*
* @param string $data String data.
*
* @throws Horde_Imap_Client_Exception
*/
public function write($data)
{
if (fwrite($this->_stream, $data . "\r\n") === false) {
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::t("Server write error."),
Horde_Imap_Client_Exception::SERVER_WRITEERROR
);
}
$this->_params['debug']->client($data);
}
/**
* Read data from incoming POP3 stream.
*
* @return string Line of data.
*
* @throws Horde_Imap_Client_Exception
*/
public function read()
{
if (feof($this->_stream)) {
$this->close();
$this->_params['debug']->info("ERROR: Server closed the connection.");
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::t("Server closed the connection unexpectedly."),
Horde_Imap_Client_Exception::DISCONNECT
);
}
if (($read = fgets($this->_stream)) === false) {
$this->_params['debug']->info("ERROR: read/timeout error.");
throw new Horde_Imap_Client_Exception(
Horde_Imap_Client_Translation::t("Error when communicating with the mail server."),
Horde_Imap_Client_Exception::SERVER_READERROR
);
}
$this->_params['debug']->server(rtrim($read, "\r\n"));
return $read;
}
}