|
|
@@ -1,7 +1,5 @@
|
|
|
<?php
|
|
|
|
|
|
-// Label functions
|
|
|
-
|
|
|
function pa($array) {
|
|
|
echo '<pre>';
|
|
|
print_r($array);
|
|
|
@@ -12,178 +10,11 @@ function error($message) {
|
|
|
echo $message;
|
|
|
}
|
|
|
|
|
|
-function getLabels() {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $return = array();
|
|
|
- $labels = $db->selectQuery("SELECT * FROM `labels`;");
|
|
|
-
|
|
|
- foreach($labels as $label) {
|
|
|
- $return[] = new Label($label->id, $label->name);
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
-}
|
|
|
-
|
|
|
-function getLabelById($labelId) {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $return = array();
|
|
|
- $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `id` = " . $labelId . ";");
|
|
|
-
|
|
|
- foreach($labels as $label) {
|
|
|
- $return[] = new Label($label->id, $label->name);
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
-}
|
|
|
-
|
|
|
-function getLabelByPath($path) {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $return = array();
|
|
|
- $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `path` = '" . $path . "';");
|
|
|
-
|
|
|
- foreach($labels as $label) {
|
|
|
- $return[] = new Label($label->id, $label->name);
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
-}
|
|
|
-
|
|
|
-function getDocumentsByLabelId($labelId) {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $return = array();
|
|
|
- $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, $document->type, $document->mail_uid);
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
-}
|
|
|
-
|
|
|
-function getDocumentsByPath($path) {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $return = array();
|
|
|
- $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, $document->type, $document->mail_uid);
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
-}
|
|
|
-
|
|
|
-function getDocumentsByMailUidLabelIdMailAccId($mailUid, $labelId, $mailAcc) {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $return = array();
|
|
|
- $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `mail_uid` = " . $mailUid . " AND `label_id` = " . $labelId . " AND `mail_acc` = " . $mailAcc . ";");
|
|
|
-
|
|
|
- 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 getMailboxes($connect = true) {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $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->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password, $connect); // TODO: Encrypt password
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
-}
|
|
|
-
|
|
|
-function getMailboxesByUserId($userId, $connect = true) {
|
|
|
- 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[] = new Imap($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password, $connect); // 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->id, $folder->folder_name, $folder->mailbox_id, $folder->label_id);
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-function getMailboxFolderByLabelId($labelId) {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $return = array();
|
|
|
- $folders = $db->selectQuery("SELECT * FROM `mailbox-folders` WHERE `label_id` = '" . $labelId . "';");
|
|
|
-
|
|
|
- if(!$folders) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- foreach($folders as $folder) {
|
|
|
- $return[] = new MailboxFolder($folder->id, $folder->folder_name, $folder->mailbox_id, $folder->label_id);
|
|
|
- }
|
|
|
-
|
|
|
- return $return;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange, $mailUid, $mailAcc = -1) {
|
|
|
- global $db;
|
|
|
- $query = "INSERT INTO `documents`(`type`, `filename`, `path`, `label_id`, `draft`, `created`, `last_change`, `mail_uid`, `mail_acc`) VALUES ('" . $type . "', '" . $fileName . "', '" . $path . "', " . $labelId . ", '" . $draft . "', " . $created . ", " . $lastChange . ", " . $mailUid . ", " . $mailAcc . ");";
|
|
|
- $db->insertQuery($query);
|
|
|
-}
|
|
|
-
|
|
|
function searchNewFiles($scanDir) {
|
|
|
global $db;
|
|
|
global $CONFIG;
|
|
|
|
|
|
- $oldDocuments = getDocumentsByPath($scanDir);
|
|
|
+ $oldDocuments = Document::getDocumentsByPath($scanDir);
|
|
|
$files = scandir($CONFIG['documentPath'] . $scanDir);
|
|
|
|
|
|
foreach($files as $file) {
|
|
|
@@ -203,7 +34,7 @@ function searchNewFiles($scanDir) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- addDocument('file', $file, '/', getLabelByPath($scanDir)[0]->getId(), '', 'NOW()', 'NOW()', 0); // TODO: get dates by filesystem
|
|
|
+ Document::addDocument('file', $file, '/', Label::getLabelByPath($scanDir)->getId(), '', 'NOW()', 'NOW()', 0); // TODO: get dates by filesystem
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -213,7 +44,7 @@ function searchMails() {
|
|
|
global $user;
|
|
|
//$imap = new Imap('{mail.mmnx.de:993/imap/ssl/novalidate-cert}', 'mobi@mmnx.de', 'msmoro');
|
|
|
//$imap->listFolders();
|
|
|
- $mailboxes = getMailBoxes();
|
|
|
+ $mailboxes = Imap::getMailBoxes();
|
|
|
//pa($mailboxes);
|
|
|
|
|
|
foreach($mailboxes as $mailbox) {
|
|
|
@@ -223,9 +54,9 @@ function searchMails() {
|
|
|
|
|
|
foreach($mailboxes as $mailbox) {
|
|
|
foreach($mailbox->getFolders() as $folder) {
|
|
|
- $mbFolder = getMailboxFolderByName($folder);
|
|
|
- if($mbFolder[0] != false) {
|
|
|
- $mailbox->changeFolder($mbFolder[0]->getFolderName());
|
|
|
+ $mbFolder = MailboxFolder::getMailboxFolderByName($folder);
|
|
|
+ if($mbFolder != false) {
|
|
|
+ $mailbox->changeFolder($mbFolder->getFolderName());
|
|
|
|
|
|
$messageCount = imap_num_msg($mailbox->getMailbox());
|
|
|
|
|
|
@@ -236,10 +67,10 @@ function searchMails() {
|
|
|
//echo $uid;
|
|
|
$uid = imap_uid($mailbox->getMailbox(), $i);
|
|
|
|
|
|
- $documents = getDocumentsByMailUidLabelIdMailAccId($uid, $mbFolder[0]->getLabelId());
|
|
|
+ $documents = getDocumentsByMailInfo($mailbox->getId(), $uid, $mbFolder->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, $mailbox->getId());
|
|
|
+ Document::addDocument('mail', $headers->subject, $headers->from[0]->mailbox . '@' . $headers->from[0]->host, $mbFolder->getLabelId(), '', '\'' . $headers->date . '\'', '\'' . $headers->date . '\'', $uid, $mailbox->getId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -274,17 +105,4 @@ function getEditableLink($elementId, $type, $pk, $title, $value, $class = '') {
|
|
|
return $link;
|
|
|
}
|
|
|
|
|
|
-function getMailboxNameFromMailaccountId($mId) {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $mailbox = $db->selectStringQuery("SELECT `username` FROM `mailboxes` WHERE id=" . $mId);
|
|
|
- return $mailbox;
|
|
|
-}
|
|
|
-
|
|
|
-function getMailboxFolderNameFromId($mId) {
|
|
|
- global $db;
|
|
|
-
|
|
|
- $mailbox = $db->selectStringQuery("SELECT `folder_name` FROM `mailbox-folders` WHERE id=" . $mId);
|
|
|
- return $mailbox;
|
|
|
-}
|
|
|
?>
|