| 1 |
<?php |
| 2 |
|
| 3 |
abstract class pConnection { |
| 4 |
|
| 5 |
protected $username; |
| 6 |
protected $host; |
| 7 |
protected $password; |
| 8 |
protected $port; |
| 9 |
protected $secure; |
| 10 |
protected $timeout; |
| 11 |
protected $mailbox; |
| 12 |
protected $type; |
| 13 |
|
| 14 |
public function __construct($type, $host, $username, $password, $port, $secure = FALSE, $timeout = NULL) { |
| 15 |
|
| 16 |
$valid_types = array('imap', 'pop3'); |
| 17 |
if (!in_array($type, $valid_types)) { |
| 18 |
throw new fProgrammerException('The mailbox type specified, %1$s, in invalid. Must be one of: %2$s.', $type, join(', ', $valid_types)); |
| 19 |
} |
| 20 |
|
| 21 |
if ($secure && !extension_loaded('openssl')) { |
| 22 |
throw new fEnvironmentException('A secure connection was requested, but the %s extension is not installed', 'openssl'); |
| 23 |
} |
| 24 |
|
| 25 |
if ($timeout === NULL) { |
| 26 |
$timeout = ini_get('default_socket_timeout'); |
| 27 |
} |
| 28 |
|
| 29 |
$this->type = $type; |
| 30 |
$this->host = $host; |
| 31 |
$this->username = $username; |
| 32 |
if (($i = strpos($username, '/')) !== false) { |
| 33 |
$this->username = substr($username, 0, $i); |
| 34 |
$this->mailbox = substr($username, $i + 1); |
| 35 |
} else { |
| 36 |
$this->username = $username; |
| 37 |
$this->mailbox = 'INBOX'; |
| 38 |
} |
| 39 |
//DebugEcho('USERNAME: ' . $this->username); |
| 40 |
DebugEcho('pConnection: mailbox: ' . $this->mailbox); |
| 41 |
|
| 42 |
$this->password = $password; |
| 43 |
$this->port = $port; |
| 44 |
$this->secure = $secure; |
| 45 |
$this->timeout = $timeout; |
| 46 |
} |
| 47 |
|
| 48 |
abstract function read($expect = NULL); |
| 49 |
|
| 50 |
abstract function write($command, $expected = null); |
| 51 |
|
| 52 |
abstract function close(); |
| 53 |
|
| 54 |
abstract function open(); |
| 55 |
|
| 56 |
abstract function isPersistant(); |
| 57 |
|
| 58 |
public function getMailbox() { |
| 59 |
return $this->mailbox; |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|