'; print_r($array); echo ''; } 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 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 getMailboxes() { 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); // 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[] = new Imap($mailbox->id, $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 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->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); } function searchNewFiles($scanDir) { global $db; global $CONFIG; $oldDocuments = getDocumentsByPath($scanDir); $files = scandir($CONFIG['documentPath'] . $scanDir); foreach($files as $file) { $existed = false; if($file === '.' || $file === '..') { continue; } foreach($oldDocuments as $oldDocument) { if($oldDocument->getFileName() === $file) { // TODO: Check update-date, maybe removed files $existed = true; break; } } if($existed) { continue; } 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); // TODO: Get really unique ID, not folder-id $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); } } } } } } function getEditableLink($elementId, $type, $pk, $title, $value) { if($type == 'text' || $type == 'password') { $class = 'editable-element-text'; } else if($type == 'select' && $elementId == 'protocol') { $class = 'editable-element-select-protocol'; } else if($type == 'select' && $elementId == 'use-ssl') { $class = 'editable-element-select-use-ssl'; if($value == '/ssl') { $value = 'On'; } else { $value = 'Off'; } } else if($type == 'select' && $elementId == 'no-valid-cert') { $class = 'editable-element-select-no-valid-cert'; if($value == '/novalidate-cert') { $value = 'On'; } else { $value = 'Off'; } } $link = '' . $value . ''; return $link; } ?>