|
|
@@ -8,6 +8,10 @@ function pa($array) {
|
|
|
echo '</pre>';
|
|
|
}
|
|
|
|
|
|
+function error($message) {
|
|
|
+ echo $message;
|
|
|
+}
|
|
|
+
|
|
|
function getLabels() {
|
|
|
global $db;
|
|
|
|
|
|
@@ -54,7 +58,7 @@ function getDocumentsByLabelId($labelId) {
|
|
|
$documents = $db->selectQuery("SELECT * FROM `documents` WHERE `label_id` = " . $labelId . ";");
|
|
|
|
|
|
foreach($documents as $document) {
|
|
|
- $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change);
|
|
|
+ $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
|
|
|
}
|
|
|
|
|
|
return $return;
|
|
|
@@ -67,15 +71,92 @@ function getDocumentsByPath($path) {
|
|
|
$documents = $db->selectQuery("SELECT documents.* FROM `documents` JOIN `labels` ON labels.id = documents.label_id WHERE labels.path = '" . $path . "';");
|
|
|
|
|
|
foreach($documents as $document) {
|
|
|
- $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change);
|
|
|
+ $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $return;
|
|
|
+}
|
|
|
+
|
|
|
+function getDocumentsByMailUidLabelId($mailUid, $labelId) {
|
|
|
+ global $db;
|
|
|
+
|
|
|
+ $return = array();
|
|
|
+ $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `mail_uid` = " . $mailUid . " AND `label_id` = " . $labelId . ";");
|
|
|
+
|
|
|
+ foreach($documents as $document) {
|
|
|
+ $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
|
|
|
}
|
|
|
|
|
|
return $return;
|
|
|
}
|
|
|
|
|
|
-function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange) {
|
|
|
+function getMailboxes() {
|
|
|
global $db;
|
|
|
- $query = "INSERT INTO `documents`(`type`, `filename`, `path`, `label_id`, `draft`, `created`, `last_change`) VALUES ('" . $type . "', '" . $fileName . "', '" . $path . "', " . $labelId . ", '" . $draft . "', " . $created . ", " . $lastChange . ");";
|
|
|
+
|
|
|
+ $return = array();
|
|
|
+ $mailboxes = $db->selectQuery("SELECT * FROM `mailboxes`;");
|
|
|
+
|
|
|
+ foreach($mailboxes as $mailbox) {
|
|
|
+ $useSsl = '';
|
|
|
+ $noValidCert = '';
|
|
|
+
|
|
|
+ if($mailbox->use_ssl) {
|
|
|
+ $useSsl = '/ssl';
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$mailbox->valid_ssl) {
|
|
|
+ $noValidCert = '/novalidate-cert';
|
|
|
+ }
|
|
|
+ $return[] = new Imap('{' . $mailbox->server . ':' . $mailbox->port . '/' . $mailbox->protocol . $useSsl . $noValidCert . '}', $mailbox->username, $mailbox->password); // TODO: Encrypt password
|
|
|
+ }
|
|
|
+
|
|
|
+ return $return;
|
|
|
+}
|
|
|
+
|
|
|
+function getMailboxesByUserId($userId) {
|
|
|
+ global $db;
|
|
|
+
|
|
|
+ $return = array();
|
|
|
+ $mailboxes = $db->selectQuery("SELECT * FROM `mailboxes` WHERE `user_id` = " . $userId . ";");
|
|
|
+
|
|
|
+ foreach($mailboxes as $mailbox) {
|
|
|
+ $useSsl = '';
|
|
|
+ $noValidCert = '';
|
|
|
+
|
|
|
+ if($mailbox->use_ssl) {
|
|
|
+ $useSsl = '/ssl';
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$mailbox->valid_ssl) {
|
|
|
+ $noValidCert = '/novalidate-cert';
|
|
|
+ }
|
|
|
+ $return[] = new Imap('{' . $mailbox->server . ':' . $mailbox->port . '/' . $mailbox->protocol . $useSsl . $noValidCert . '}', $mailbox->username, $mailbox->password); // TODO: Encrypt password
|
|
|
+ }
|
|
|
+
|
|
|
+ return $return;
|
|
|
+}
|
|
|
+
|
|
|
+function getMailboxFolderByName($folderName) {
|
|
|
+ global $db;
|
|
|
+
|
|
|
+ $return = array();
|
|
|
+ $folders = $db->selectQuery("SELECT * FROM `mailbox-folders` WHERE `folder_name` = '" . $folderName . "';");
|
|
|
+
|
|
|
+ if(!$folders) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($folders as $folder) {
|
|
|
+ $return[] = new MailboxFolder($folder->folder_name, $folder->mailbox_id, $folder->label_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $return;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange, $mailUid) {
|
|
|
+ global $db;
|
|
|
+ $query = "INSERT INTO `documents`(`type`, `filename`, `path`, `label_id`, `draft`, `created`, `last_change`, `mail_uid`) VALUES ('" . $type . "', '" . $fileName . "', '" . $path . "', " . $labelId . ", '" . $draft . "', " . $created . ", " . $lastChange . ", " . $mailUid . ");";
|
|
|
$db->insertQuery($query);
|
|
|
}
|
|
|
|
|
|
@@ -103,10 +184,43 @@ function searchNewFiles($scanDir) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- addDocument('file', $file, '/', getLabelByPath($scanDir)[0]->getId(), '', 'NOW()', 'NOW()'); // TODO: get dates by filesystem
|
|
|
+ addDocument('file', $file, '/', getLabelByPath($scanDir)[0]->getId(), '', 'NOW()', 'NOW()', 0); // TODO: get dates by filesystem
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+function searchMails() {
|
|
|
+ global $user;
|
|
|
+ //$imap = new Imap('{mail.mmnx.de:993/imap/ssl/novalidate-cert}', 'mobi@mmnx.de', 'msmoro');
|
|
|
+ //$imap->listFolders();
|
|
|
+ $mailboxes = getMailBoxes();
|
|
|
+ //pa($mailboxes);
|
|
|
+
|
|
|
+ foreach($mailboxes as $mailbox) {
|
|
|
+ $mailbox->listFolders();
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($mailboxes as $mailbox) {
|
|
|
+ foreach($mailbox->getFolders() as $folder) {
|
|
|
+ $mbFolder = getMailboxFolderByName($folder);
|
|
|
+ if($mbFolder[0] != false) {
|
|
|
+ $mailbox->changeFolder($mbFolder[0]->getFolderName());
|
|
|
+
|
|
|
+ $messageCount = imap_num_msg($mailbox->getMailbox());
|
|
|
+
|
|
|
+ for($i = 1; $i <= $messageCount; ++$i) {
|
|
|
+ $headers = imap_header($mailbox->getMailbox(), $i);
|
|
|
+ $uid = imap_uid($mailbox->getMailbox(), $i);
|
|
|
+
|
|
|
+ $documents = getDocumentsByMailUidLabelId($uid, $mbFolder[0]->getLabelId());
|
|
|
+
|
|
|
+ if(sizeof($documents) < 1) {
|
|
|
+ addDocument('mail', $headers->subject, $headers->from[0]->mailbox . '@' . $headers->from[0]->host, $mbFolder[0]->getLabelId(), '', '\'' . $headers->date . '\'', '\'' . $headers->date . '\'', $uid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
?>
|