Issues (36)

lib/Controller/RemoteController.php (4 issues)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
4
/**
5
 * Files_FromMail - Recover your email attachments from your cloud.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2017
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 *  You should have received a copy of the GNU Affero General Public License
25
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Files_FromMail\Controller;
31
32
use Exception;
33
use OCA\Files_FromMail\AppInfo\Application;
34
use OCA\Files_FromMail\Service\MailService;
35
use OCA\Files_FromMail\Service\MiscService;
36
use OCP\AppFramework\Controller;
0 ignored issues
show
The type OCP\AppFramework\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
use OCP\AppFramework\Http;
0 ignored issues
show
The type OCP\AppFramework\Http was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
use OCP\AppFramework\Http\DataResponse;
0 ignored issues
show
The type OCP\AppFramework\Http\DataResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
use OCP\IRequest;
0 ignored issues
show
The type OCP\IRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
41
42
/**
43
 * Class RemoteController
44
 *
45
 * @package OCA\Files_FromMail\Controller
46
 */
47
class RemoteController extends Controller {
48
49
	/** @var string */
50
	private $userId;
51
52
	/** @var MailService */
53
	private $mailService;
54
55
	/** @var MiscService */
56
	private $miscService;
57
58
59
	/**
60
	 * RemoteController constructor.
61
	 *
62
	 * @param IRequest $request
63
	 * @param string $userId
64
	 * @param MailService $mailService
65
	 * @param MiscService $miscService
66
	 */
67
	function __construct(IRequest $request, $userId, MailService $mailService, MiscService $miscService) {
68
		parent::__construct(Application::APP_NAME, $request);
69
		$this->userId = $userId;
70
71
		$this->mailService = $mailService;
72
		$this->miscService = $miscService;
73
	}
74
75
76
	/**
77
	 * endpoint that will receive mail content from NextcloudMailCatcher.php
78
	 *
79
	 * @NoAdminRequired
80
	 * @NoCSRFRequired
81
	 *
82
	 * @param $content
83
	 *
84
	 * @return DataResponse
85
	 */
86
	public function getContent($content): DataResponse {
87
		try {
88
			if ($content !== 'null') {
89
				$content = base64_decode(rawurldecode($content));
90
				$this->mailService->parseMail($content, $this->userId);
91
			}
92
93
			return new DataResponse(['ok'], Http::STATUS_CREATED);
94
		} catch (Exception $e) {
95
			$this->miscService->log('issue while getContent() : ' . $e->getMessage());
96
97
			return new DataResponse(['error' => $e->getMessage()], Http::STATUS_CREATED);
98
		}
99
	}
100
101
}
102
103