|
@@ -12,6 +12,7 @@ class Mailbox {
|
|
|
private $password = NULL;
|
|
private $password = NULL;
|
|
|
private $mailbox = NULL;
|
|
private $mailbox = NULL;
|
|
|
private $folders = NULL;
|
|
private $folders = NULL;
|
|
|
|
|
+ private $connected = false;
|
|
|
|
|
|
|
|
public function __construct($id, $hostname, $port, $protocol, $useSsl, $noValidCert, $username, $password, $connect) {
|
|
public function __construct($id, $hostname, $port, $protocol, $useSsl, $noValidCert, $username, $password, $connect) {
|
|
|
$this->id = $id;
|
|
$this->id = $id;
|
|
@@ -22,11 +23,17 @@ class Mailbox {
|
|
|
$this->noValidCert = $noValidCert;
|
|
$this->noValidCert = $noValidCert;
|
|
|
$this->username = $username;
|
|
$this->username = $username;
|
|
|
$this->password = $password;
|
|
$this->password = $password;
|
|
|
- // '{' . $mailbox->server . ':' . $mailbox->port . '/' . $mailbox->protocol . $useSsl . $noValidCert . '}'
|
|
|
|
|
- $this->server = '{' . $this->hostname . ':' . $this->port . '/' . $this->protocol . $this->useSsl . $this->noValidCert . '}';
|
|
|
|
|
|
|
+ $this->server = '{' . $this->hostname . ':' . $this->port . '/' . $this->protocol . $this->useSsl . $this->noValidCert . '}';
|
|
|
|
|
|
|
|
if($connect) {
|
|
if($connect) {
|
|
|
- $this->mailbox = imap_open($this->server . 'INBOX', $this->username, $this->password) or error('Failed to connect to IMAP: ' . $this->username . '@' . $this->hostname);
|
|
|
|
|
|
|
+ $this->mailbox = imap_open($this->server . 'INBOX', $this->username, $this->password); // or error('Failed to connect to IMAP: ' . $this->username . '@' . $this->hostname)
|
|
|
|
|
+ imap_errors();
|
|
|
|
|
+ imap_alerts();
|
|
|
|
|
+ if($this->mailbox == false) {
|
|
|
|
|
+ $this->connected = false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $this->connected = true;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -85,6 +92,18 @@ class Mailbox {
|
|
|
return $this->username;
|
|
return $this->username;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function getConnected() {
|
|
|
|
|
+ return $this->connected;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function getStatus() {
|
|
|
|
|
+ return imap_status($this->mailbox, $this->server, SA_ALL);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function setConnected($connected) {
|
|
|
|
|
+ $this->connected = $connected;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Get all Mailboxes
|
|
* Get all Mailboxes
|
|
|
*
|
|
*
|
|
@@ -118,18 +137,51 @@ class Mailbox {
|
|
|
return $return;
|
|
return $return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Get Mailbox by ID
|
|
|
|
|
+ *
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param int $userId ID of Mailbox
|
|
|
|
|
+ * @param bool $connect Whether to connect or just to store data. Default: false
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return Mailbox Selected Mailboxes
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ public static function getMailboxById($mailboxId, $connect = false) {
|
|
|
|
|
+ global $db;
|
|
|
|
|
+
|
|
|
|
|
+ $return = array();
|
|
|
|
|
+ $mailboxes = $db->selectQuery("SELECT * FROM `mailboxes` WHERE `id` = " . $mailboxId . ";");
|
|
|
|
|
+
|
|
|
|
|
+ foreach($mailboxes as $mailbox) {
|
|
|
|
|
+ $useSsl = '';
|
|
|
|
|
+ $noValidCert = '';
|
|
|
|
|
+
|
|
|
|
|
+ if($mailbox->use_ssl) {
|
|
|
|
|
+ $useSsl = '/ssl';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!$mailbox->valid_ssl) {
|
|
|
|
|
+ $noValidCert = '/novalidate-cert';
|
|
|
|
|
+ }
|
|
|
|
|
+ $return[] = new Mailbox($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password, $connect); // TODO: Encrypt password
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $return[0];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Get Mailboxes by User ID
|
|
* Get Mailboxes by User ID
|
|
|
*
|
|
*
|
|
|
*
|
|
*
|
|
|
* @param int $userId ID of user
|
|
* @param int $userId ID of user
|
|
|
- * @param bool $connect Whether to connect or just to store data
|
|
|
|
|
*
|
|
*
|
|
|
* @return Array(Mailbox) Array with selected Mailboxes
|
|
* @return Array(Mailbox) Array with selected Mailboxes
|
|
|
*
|
|
*
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
- public static function getMailboxesByUserId($userId, $connect = true) {
|
|
|
|
|
|
|
+ public static function getMailboxesByUserId($userId) {
|
|
|
global $db;
|
|
global $db;
|
|
|
|
|
|
|
|
$return = array();
|
|
$return = array();
|
|
@@ -146,7 +198,7 @@ class Mailbox {
|
|
|
if(!$mailbox->valid_ssl) {
|
|
if(!$mailbox->valid_ssl) {
|
|
|
$noValidCert = '/novalidate-cert';
|
|
$noValidCert = '/novalidate-cert';
|
|
|
}
|
|
}
|
|
|
- $return[] = new Mailbox($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password, $connect); // TODO: Encrypt password
|
|
|
|
|
|
|
+ $return[] = new Mailbox($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password, false); // TODO: Encrypt password
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
return $return;
|