').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 @@
+
+
+