diff --git a/README.md b/README.md index 6951932..27c69c8 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ remove lines 34-37: $ ./configure --with-php-config=/usr/bin/php-config $ make $ sudo make install -$ sudo echo "extension=mailparse.so" > /etc/php/7.0/mods-available/mailparse.ini -$ sudo ln -s /etc/php/7.0/mods-available/mailparse.ini /etc/php/7.0/apache2/conf.d/20-mailparse.ini +$ sudo echo "extension=mailparse.so" > /etc/php/7.3/mods-available/mailparse.ini +$ sudo ln -s /etc/php/7.3/mods-available/mailparse.ini /etc/php/7.3/apache2/conf.d/20-mailparse.ini $ sudo apachectl restart ``` @@ -59,7 +59,7 @@ Recreate the aliases db: $ sudo newaliases ``` -_Edit **NextcloudMailCatcher.php** and edit the few settings: +Edit **NextcloudMailCatcher.php** and edit the few settings: > $config = [ @@ -69,6 +69,7 @@ _Edit **NextcloudMailCatcher.php** and edit the few settings: > 'debug' => false > ]; +_Note: the password needs to be a token generated from the webclient in **Settings** / **Security** / **Devices & session**_ You can test your setup by running: diff --git a/appinfo/app.php b/appinfo/app.php index f23c3ca..872965d 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -1,4 +1,6 @@ - - 0.3.0 + 0.4.0 agpl Maxence Lange Files_FromMail @@ -27,9 +27,13 @@ https://raw.githubusercontent.com/nextcloud/files_frommail/master/screenshots/v0.1.0.png - + + + OCA\Files_FromMail\Settings\Admin + + OCA\Files_FromMail\Command\Addresses diff --git a/appinfo/routes.php b/appinfo/routes.php index b6fcb99..e67bc69 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -1,4 +1,6 @@ - [ - ['name' => 'Remote#getContent', 'url' => '/remote', 'verb' => 'PUT'] + ['name' => 'Remote#getContent', 'url' => '/remote', 'verb' => 'PUT'], + ['name' => 'Navigation#getMailbox', 'url' => '/admin/mailbox', 'verb' => 'GET'], + ['name' => 'Navigation#newMailbox', 'url' => '/admin/mailbox', 'verb' => 'POST'], + ['name' => 'Navigation#deleteMailbox', 'url' => '/admin/mailbox', 'verb' => 'DELETE'] ] ]; + diff --git a/composer.json b/composer.json index c153aad..048ba4c 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,6 @@ } ], "require": { - "php-mime-mail-parser/php-mime-mail-parser": "3.0.4" + "php-mime-mail-parser/php-mime-mail-parser": "5.0.5" } } diff --git a/composer.lock b/composer.lock index ad37105..3b71435 100644 --- a/composer.lock +++ b/composer.lock @@ -4,35 +4,35 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "766789d2d56090178ef7dc3605fc278d", + "content-hash": "e9533db4e8fd90548a9b3c70859ad53c", "packages": [ { "name": "php-mime-mail-parser/php-mime-mail-parser", - "version": "3.0.4", + "version": "5.0.5", "source": { "type": "git", "url": "https://github.com/php-mime-mail-parser/php-mime-mail-parser.git", - "reference": "b1319a9899dd6f27edf425ef1e90cb6c1d7d2a0d" + "reference": "27983433aabeccee832573c3c56e6a4855e57745" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-mime-mail-parser/php-mime-mail-parser/zipball/b1319a9899dd6f27edf425ef1e90cb6c1d7d2a0d", - "reference": "b1319a9899dd6f27edf425ef1e90cb6c1d7d2a0d", + "url": "https://api.github.com/repos/php-mime-mail-parser/php-mime-mail-parser/zipball/27983433aabeccee832573c3c56e6a4855e57745", + "reference": "27983433aabeccee832573c3c56e6a4855e57745", "shasum": "" }, "require": { "ext-mailparse": "*", - "php": "^5.6.0 || ^7.0" + "php": "^7.1" }, "replace": { "exorus/php-mime-mail-parser": "*", "messaged/php-mime-mail-parser": "*" }, "require-dev": { - "php-coveralls/php-coveralls": "0.*", - "phpunit/php-token-stream": "^1.3.0", - "phpunit/phpunit": "^5.7", - "squizlabs/php_codesniffer": "2.*" + "php-coveralls/php-coveralls": "^2.1", + "phpunit/php-token-stream": "^3.0", + "phpunit/phpunit": "^7.0", + "squizlabs/php_codesniffer": "^3.4" }, "type": "library", "autoload": { @@ -45,12 +45,6 @@ "MIT" ], "authors": [ - { - "name": "bucabay", - "email": "gabe@fijiwebdesign.com", - "homepage": "http://www.fijiwebdesign.com", - "role": "Developer" - }, { "name": "eXorus", "email": "exorus.spam@gmail.com", @@ -74,17 +68,25 @@ "email": "alkne@gmail.com", "homepage": "https://code.google.com/p/php-mime-mail-parser", "role": "Developer" + }, + { + "name": "bucabay", + "email": "gabe@fijiwebdesign.com", + "homepage": "http://www.fijiwebdesign.com", + "role": "Developer" } ], - "description": "Fully Tested Mailparse Extension Wrapper for PHP 5.6+", + "description": "A fully tested email parser for PHP 7.1+ (mailparse extension wrapper).", "homepage": "https://github.com/php-mime-mail-parser/php-mime-mail-parser", "keywords": [ "MimeMailParser", "mail", "mailparse", - "mime" + "mime", + "parser", + "php" ], - "time": "2019-03-19T05:24:58+00:00" + "time": "2019-09-23T11:57:58+00:00" } ], "packages-dev": [], diff --git a/css/admin.css b/css/admin.css new file mode 100644 index 0000000..aa107a7 --- /dev/null +++ b/css/admin.css @@ -0,0 +1,3 @@ +.frommail-input { + padding: 10px; +} diff --git a/js/admin.js b/js/admin.js new file mode 100644 index 0000000..a97e271 --- /dev/null +++ b/js/admin.js @@ -0,0 +1,136 @@ +/** + * Files_FromMail - Recover your email attachments from your cloud. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange + * @copyright 2020 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +(function() { + if (!OCA.FromMail) { + /** + * @namespace + */ + OCA.FromMail = {}; + } + + OCA.FromMail.Admin = { + + collection: [], + + init: function() { + var self = this; + + self.getMailbox(); + + var create = $('#frommail_create'); + create.on('click', function() { + var address = $('#frommail_address').val(); + var password = $('#frommail_password').val(); + + $('#frommail_address').val('') + $('#frommail_password').val('') + if (address === '') { + return; + } + + self.createMailbox(address, password); + }); + }, + + + getMailbox: function() { + var self = this; + $.ajax({ + method: 'GET', + url: OC.generateUrl('/apps/files_frommail/admin/mailbox') + }).done(function(res) { + self.collection = res; + self.displayMailbox(); + }); + }, + + + displayMailbox: function() { + if (this.collection === []) { + return; + } + + var self = this; + var list = $('#frommail_list'); + list.empty(); + + this.collection.forEach(function(item) { + var mailbox = item.address + if (item.password !== undefined && item.password !== '') { + mailbox += ' :' + item.password; + } + + var entry = $('
', {class: 'frommail-input'}); + entry.text(mailbox + ' '); + var button = $('', { + id: 'frommail_submit', + class: 'button', + 'data-mailbox': item.address + }).append($('').text('Delete')); + button.on('click', function() { + self.deleteMailbox(item.address); + }); + entry.append(button); + list.prepend(entry); + }); + + }, + + + createMailbox: function(mailbox, password) { + var self = this; + $.ajax({ + method: 'POST', + url: OC.generateUrl('/apps/files_frommail/admin/mailbox'), + data: { + address: mailbox, + password: password + } + }).done(function(res) { + self.getMailbox(); + }); + + }, + + + deleteMailbox: function(mailbox) { + var self = this; + $.ajax({ + method: 'DELETE', + url: OC.generateUrl('/apps/files_frommail/admin/mailbox'), + data: {address: mailbox} + }).done(function(res) { + self.getMailbox(); + }); + } + + }; +})(); + +$(document).ready(function() { + OCA.FromMail.Admin.init(); +}); + diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 79dd5f0..7038f3e 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -1,4 +1,6 @@ -addArgument('address', InputArgument::OPTIONAL, 'mail address') - ->addArgument('password', InputArgument::OPTIONAL, 'password'); + ->addArgument('password', InputArgument::OPTIONAL, 'password', ''); } @@ -85,10 +94,10 @@ protected function configure() { * @param InputInterface $input * @param OutputInterface $output * - * @return int|null|void + * @return int * @throws Exception */ - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { try { $this->listMailAddresses($input, $output); @@ -101,6 +110,8 @@ protected function execute(InputInterface $input, OutputInterface $output) { } catch (Exception $e) { throw $e; } + + return 0; } @@ -110,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { * * @throws FakeException */ - private function listMailAddresses(InputInterface $input, OutputInterface $output) { + private function listMailAddresses(InputInterface $input, OutputInterface $output): void { if ($input->getOption('list') !== true) { return; } @@ -138,7 +149,7 @@ private function listMailAddresses(InputInterface $input, OutputInterface $outpu * @throws AddressAlreadyExistException * @throws InvalidAddressException */ - private function addMailAddress(InputInterface $input) { + private function addMailAddress(InputInterface $input): void { if ($input->getOption('add') !== true) { return; } @@ -157,7 +168,7 @@ private function addMailAddress(InputInterface $input) { * @throws MissingArgumentException * @throws UnknownAddressException */ - private function removeMailAddress(InputInterface $input) { + private function removeMailAddress(InputInterface $input): void { if ($input->getOption('remove') !== true) { return; } @@ -177,7 +188,7 @@ private function removeMailAddress(InputInterface $input) { * @throws MissingArgumentException * @throws UnknownAddressException */ - private function setMailAddressPassword(InputInterface $input, OutputInterface $output) { + private function setMailAddressPassword(InputInterface $input, OutputInterface $output): void { if ($input->getOption('password') !== true) { return; } @@ -186,7 +197,7 @@ private function setMailAddressPassword(InputInterface $input, OutputInterface $ $password = $input->getArgument('password'); $this->mailService->setMailPassword($mail, $password); - if ($password === null) { + if ($password === '') { $output->writeln('Password for ' . $mail . ' is now UNSET'); throw new FakeException(); } @@ -199,17 +210,16 @@ private function setMailAddressPassword(InputInterface $input, OutputInterface $ /** * @param InputInterface $input * - * @return string|string[]|null + * @return string * @throws MissingArgumentException */ - private function checkMailAddress(InputInterface $input) { + private function checkMailAddress(InputInterface $input): string { $mail = $input->getArgument('address'); if ($mail === null) { throw new MissingArgumentException('missing email address'); } return $mail; - } @@ -218,7 +228,7 @@ private function checkMailAddress(InputInterface $input) { * * @return string */ - private function formatMailAddress($entry) { + private function formatMailAddress($entry): string { $line = '- ' . $entry['address']; if (array_key_exists('password', $entry) && $entry['password'] !== '') { $line .= ' [:' . $entry['password'] . ']'; diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php new file mode 100644 index 0000000..4090e17 --- /dev/null +++ b/lib/Controller/NavigationController.php @@ -0,0 +1,121 @@ + + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Files_FromMail\Controller; + +use Exception; +use OCA\Files_FromMail\AppInfo\Application; +use OCA\Files_FromMail\Service\MailService; +use OCA\Files_FromMail\Service\MiscService; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; +use OCP\IRequest; + + +/** + * Class NavigationController + * + * @package OCA\Files_FromMail\Controller + */ +class NavigationController extends Controller { + + + /** @var MailService */ + private $mailService; + + /** @var MiscService */ + private $miscService; + + + /** + * RemoteController constructor. + * + * @param IRequest $request + * @param string $userId + * @param MailService $mailService + * @param MiscService $miscService + */ + function __construct(IRequest $request, MailService $mailService, MiscService $miscService) { + parent::__construct(Application::APP_NAME, $request); + + $this->mailService = $mailService; + $this->miscService = $miscService; + } + + + /** + * @return DataResponse + */ + public function getMailbox(): DataResponse { + try { + $mailbox = $this->mailService->getMailAddresses(); + + return new DataResponse($mailbox, Http::STATUS_CREATED); + } catch (Exception $e) { + return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); + } + } + + + /** + * @param string $address + * @param string $password + * + * @return DataResponse + */ + public function newMailbox(string $address, string $password): DataResponse { + try { + $this->mailService->addMailAddress($address, $password); + + return new DataResponse(['ok'], Http::STATUS_CREATED); + } catch (Exception $e) { + return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); + } + } + + + /** + * @param string $address + * + * @return DataResponse + */ + public function deleteMailbox(string $address): DataResponse { + try { + $this->mailService->removeMailAddress($address); + + return new DataResponse(['ok'], Http::STATUS_CREATED); + } catch (Exception $e) { + return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); + } + } + + +} + diff --git a/lib/Controller/RemoteController.php b/lib/Controller/RemoteController.php index 3d11639..9260d12 100644 --- a/lib/Controller/RemoteController.php +++ b/lib/Controller/RemoteController.php @@ -1,4 +1,6 @@ -userId = $userId; @@ -76,8 +83,7 @@ function __construct( * * @return DataResponse */ - public function getContent($content) { - + public function getContent($content): DataResponse { try { if ($content !== 'null') { $content = base64_decode(rawurldecode($content)); @@ -92,5 +98,5 @@ public function getContent($content) { } } - } + diff --git a/lib/Exceptions/AddressAlreadyExistException.php b/lib/Exceptions/AddressAlreadyExistException.php index c088eb8..54c9335 100644 --- a/lib/Exceptions/AddressAlreadyExistException.php +++ b/lib/Exceptions/AddressAlreadyExistException.php @@ -1,4 +1,6 @@ -content = $content; return $this; @@ -75,7 +77,7 @@ public function setContent($content) { /** * @return string */ - public function getContent() { + public function getContent(): string { return $this->content; } @@ -83,8 +85,7 @@ public function getContent() { /** * */ - public function sendToNextcloud() { - + public function sendToNextcloud(): void { $content = rawurlencode(base64_encode($this->getContent())); $curl = $this->generateAuthedCurl(); @@ -99,7 +100,7 @@ public function sendToNextcloud() { /** * */ - public function test() { + public function test(): void { $this->config['debug'] = true; $this->debug('testing!'); @@ -126,7 +127,7 @@ public function test() { * @param resource $curl * @param string|array $result */ - private function debugCurl($curl, $result) { + private function debugCurl($curl, $result): void { if ($result === false) { $this->debug('Mail NOT forwarded: ' . curl_error($curl)); @@ -201,7 +202,7 @@ private function generateAuthedCurl() { * @param resource $curl * @param string $put */ - private function fillCurlWithContent(&$curl, $put) { + private function fillCurlWithContent(&$curl, string $put): void { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($curl, CURLOPT_POSTFIELDS, $put); @@ -223,7 +224,7 @@ private function fillCurlWithContent(&$curl, $put) { /** * @param string $string */ - private function debug($string) { + private function debug(string $string): void { if (!array_key_exists('debug', $this->config) || $this->config['debug'] !== true) { return; } diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 1a7d0c7..462dda4 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -1,4 +1,6 @@ - '', + self::FROMMAIL_ADDRESSES => '', self::FROMMAIL_FILENAMEID => 'Y-m-d H:i:s', ]; + /** @var string */ private $appName; @@ -54,6 +64,7 @@ class ConfigService { /** @var MiscService */ private $miscService; + /** * ConfigService constructor. * @@ -81,7 +92,7 @@ public function __construct( * * @return string */ - public function getAppValue($key) { + public function getAppValue(string $key): string { $defaultValue = null; if (array_key_exists($key, $this->defaults)) { @@ -97,10 +108,8 @@ public function getAppValue($key) { * * @param string $key * @param string $value - * - * @return void */ - public function setAppValue($key, $value) { + public function setAppValue(string $key, string $value): void { $this->config->setAppValue($this->appName, $key, $value); } @@ -112,8 +121,9 @@ public function setAppValue($key, $value) { * * @return string */ - public function deleteAppValue($key) { + public function deleteAppValue(string $key): string { return $this->config->deleteAppValue($this->appName, $key); } } + diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index fdee9be..50ecc02 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -1,4 +1,6 @@ -setText($content); @@ -116,10 +127,15 @@ public function parseMail($content, $userId) { * @throws NotAFolderException * @throws NotFoundException * @throws NotPermittedException + * @throws LockedException */ - private function generateLocalContentFromMail(Parser $mail, $to, $data) { - + private function generateLocalContentFromMail(Parser $mail, string $to, array $data): void { $toInfo = $this->getMailAddressInfo($to); + $this->miscService->log($to . ' ' . json_encode($toInfo)); + if (empty($toInfo)) { + return; + } + $text = $data['text']; $subject = $data['subject']; $from = $data['from']; @@ -136,13 +152,12 @@ private function generateLocalContentFromMail(Parser $mail, $to, $data) { /** - * @param $content - * @param $toInfo + * @param string $content + * @param array $toInfo * * @throws AddressInfoException */ - private function verifyInfoAndPassword($content, $toInfo) { - + private function verifyInfoAndPassword(string $content, array $toInfo): void { if ($toInfo === null) { throw new AddressInfoException('address is not known'); } @@ -169,9 +184,8 @@ private function verifyInfoAndPassword($content, $toInfo) { * @throws NotFoundException * @throws NotPermittedException */ - private function getMailFolder($userId, $to, $from) { - - $node = \OC::$server->getUserFolder($userId); + private function getMailFolder(string $userId, string $to, string $from): Folder { + $node = OC::$server->getUserFolder($userId); $folderPath = 'Mails sent to ' . $to . '/From ' . $from . '/'; if (!$node->nodeExists($folderPath)) { @@ -193,7 +207,7 @@ private function getMailFolder($userId, $to, $from) { * * @return array */ - private function parseMailHeaders(Parser $mail) { + private function parseMailHeaders(Parser $mail): array { $from = $mail->getAddresses('from')[0]['address']; $subject = $mail->getHeader('subject'); $text = $mail->getHeadersRaw() . $mail->getMessageBody('text'); @@ -214,15 +228,15 @@ private function parseMailHeaders(Parser $mail) { * * @throws GenericFileException * @throws NotPermittedException + * @throws LockedException */ - private function createLocalFileFromAttachments($id, $folder, $attachments) { + private function createLocalFileFromAttachments(string $id, Folder $folder, array $attachments): void { foreach ($attachments as $attachment) { $this->createLocalFile( $folder, $id, 'attachment-' . $attachment->getFilename(), $attachment->getContent() ); } - } @@ -234,8 +248,9 @@ private function createLocalFileFromAttachments($id, $folder, $attachments) { * * @throws NotPermittedException * @throws GenericFileException + * @throws LockedException */ - private function createLocalFile($folder, $id, $filename, $content) { + private function createLocalFile(Folder $folder, string $id, string $filename, string $content): void { $new = $folder->newFile($id . '-' . $this->count . '_' . $filename); $new->putContent($content); @@ -244,18 +259,15 @@ private function createLocalFile($folder, $id, $filename, $content) { /** - * @param $address - * @param $password + * @param string $address + * @param string $password * * @throws UnknownAddressException */ - public function setMailPassword($address, $password) { + public function setMailPassword(string $address, string $password): void { if (!$this->mailAddressExist($address)) { throw new UnknownAddressException('address is not known'); } - if ($password === null) { - $password = ''; - } $addresses = $this->getMailAddresses(); $new = []; @@ -271,11 +283,11 @@ public function setMailPassword($address, $password) { /** - * @param $address + * @param string $address * * @throws UnknownAddressException */ - public function removeMailAddress($address) { + public function removeMailAddress(string $address): void { $addresses = $this->getMailAddresses(); if (!$this->mailAddressExist($address)) { throw new UnknownAddressException('address is not known'); @@ -293,19 +305,20 @@ public function removeMailAddress($address) { /** - * @param $address + * @param string $address + * @param string $password * * @throws AddressAlreadyExistException * @throws InvalidAddressException */ - public function addMailAddress($address) { + public function addMailAddress(string $address, string $password = ''): void { $this->hasToBeAValidMailAddress($address); if ($this->mailAddressExist($address)) { throw new AddressAlreadyExistException('address already exist'); } $addresses = $this->getMailAddresses(); - array_push($addresses, ['address' => $address]); + array_push($addresses, ['address' => $address, 'password' => $password]); $this->saveMailAddresses($addresses); } @@ -315,17 +328,17 @@ public function addMailAddress($address) { * * @return bool */ - private function mailAddressExist($address) { - return ($this->getMailAddressInfo($address) !== null); + private function mailAddressExist(string $address): bool { + return !empty($this->getMailAddressInfo($address)); } /** - * @param $address + * @param string $address * - * @return array|null + * @return array */ - private function getMailAddressInfo($address) { + private function getMailAddressInfo(string $address): array { $addresses = $this->getMailAddresses(); foreach ($addresses as $entry) { if ($entry['address'] === $address) { @@ -333,16 +346,16 @@ private function getMailAddressInfo($address) { } } - return null; + return []; } /** - * @param $address + * @param string $address * * @throws InvalidAddressException */ - private function hasToBeAValidMailAddress($address) { + private function hasToBeAValidMailAddress(string $address): void { if (filter_var($address, FILTER_VALIDATE_EMAIL)) { return; } @@ -354,7 +367,7 @@ private function hasToBeAValidMailAddress($address) { /** * @return array */ - public function getMailAddresses() { + public function getMailAddresses(): array { $curr = json_decode($this->configService->getAppValue(ConfigService::FROMMAIL_ADDRESSES), true); if ($curr === null) { return []; @@ -363,12 +376,13 @@ public function getMailAddresses() { return $curr; } + /** - * @param $addresses + * @param array $addresses */ - private function saveMailAddresses($addresses) { + private function saveMailAddresses(array $addresses): void { $this->configService->setAppValue(ConfigService::FROMMAIL_ADDRESSES, json_encode($addresses)); } - } + diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php index 82338d4..062efad 100644 --- a/lib/Service/MiscService.php +++ b/lib/Service/MiscService.php @@ -1,4 +1,6 @@ -logger = $logger; } - public function log($message, $level = 2) { + + /** + * @param string $message + * @param int $level + */ + public function log(string $message, int $level = 2): void { $data = array( 'app' => Application::APP_NAME, 'level' => $level @@ -47,21 +63,5 @@ public function log($message, $level = 2) { $this->logger->log($level, $message, $data); } - /** - * @param $arr - * @param $k - * - * @param string $default - * - * @return array|string|integer - */ - public static function get($arr, $k, $default = '') { - if (!key_exists($k, $arr)) { - return $default; - } - - return $arr[$k]; - } - } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php new file mode 100644 index 0000000..193f31f --- /dev/null +++ b/lib/Settings/Admin.php @@ -0,0 +1,73 @@ + + * @copyright 2017 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Files_FromMail\Settings; + + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\Settings\ISettings; + + +/** + * Class Admin + * + * @package OCA\Files_FromMail\Settings + */ +class Admin implements ISettings { + + + /** + * @return TemplateResponse + */ + public function getForm() { + return new TemplateResponse('files_frommail', 'settings.admin', [], ''); + } + + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'additional'; + } + + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + * + * E.g.: 70 + */ + public function getPriority() { + return 80; + } + +} + diff --git a/templates/settings.admin.php b/templates/settings.admin.php new file mode 100644 index 0000000..928c7f0 --- /dev/null +++ b/templates/settings.admin.php @@ -0,0 +1,34 @@ + + +
+

t('Drop mailbox')); ?>

+

t( + 'Files FromMail allows you to configure drop mailbox to store mails and attachments into your Files.' + ) + ); ?>

+ +
+

t('Current mailbox')); ?>

+
+
+
+ +

t('Configure a new mailbox')); ?>

+ +
+ +