Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2022-07-04 21:29:53 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2022-07-07 16:24:05 +0300
commit799ee0028d553d46af475bc0499cb1db44864e61 (patch)
tree007f17e8bbd35a822709a658695210891b3353b2 /lib/Controller/AutoConfigController.php
parent77544d3fe16dec880092e143d2b65eeafdc9fbc6 (diff)
Split auto config and account creation
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Controller/AutoConfigController.php')
-rw-r--r--lib/Controller/AutoConfigController.php89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/Controller/AutoConfigController.php b/lib/Controller/AutoConfigController.php
new file mode 100644
index 000000000..796f7a42a
--- /dev/null
+++ b/lib/Controller/AutoConfigController.php
@@ -0,0 +1,89 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * @copyright 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\Mail\Controller;
+
+use Horde_Mail_Rfc822_Address;
+use OCA\Mail\AppInfo\Application;
+use OCA\Mail\Http\JsonResponse;
+use OCA\Mail\Service\AutoConfig\ConnectivityTester;
+use OCA\Mail\Service\AutoConfig\IspDb;
+use OCA\Mail\Service\AutoConfig\MxRecord;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\IRequest;
+use function in_array;
+
+class AutoConfigController extends Controller {
+ private IspDb $ispDb;
+ private MxRecord $mxRecord;
+ private ConnectivityTester $connectivityTester;
+
+ public function __construct(IRequest $request,
+ IspDb $ispDb,
+ MxRecord $mxRecord,
+ ConnectivityTester $connectivityTester) {
+ parent::__construct(Application::APP_ID, $request);
+ $this->ispDb = $ispDb;
+ $this->mxRecord = $mxRecord;
+ $this->connectivityTester = $connectivityTester;
+ }
+
+ /**
+ * @param string $email
+ *
+ * @NoAdminRequired
+ * @TrapError
+ *
+ * @return JsonResponse
+ */
+ public function queryIspdb(string $email): JsonResponse {
+ $rfc822Address = new Horde_Mail_Rfc822_Address($email);
+ if (!$rfc822Address->valid) {
+ return JsonResponse::fail('Invalid email address', Http::STATUS_UNPROCESSABLE_ENTITY);
+ }
+ $config = $this->ispDb->query($rfc822Address->host, $rfc822Address);
+ return JsonResponse::success($config);
+ }
+
+ public function queryMx(string $email): JsonResponse {
+ $rfc822Address = new Horde_Mail_Rfc822_Address($email);
+ if (!$rfc822Address->valid) {
+ return JsonResponse::fail('Invalid email address', Http::STATUS_UNPROCESSABLE_ENTITY);
+ }
+ return JsonResponse::success(
+ $this->mxRecord->query($rfc822Address->host),
+ );
+ }
+
+ public function testConnectivity(string $host, int $port): JsonResponse {
+ if (!in_array($port, [143, 993, 465, 587])) {
+ return JsonResponse::fail('Port not allowed');
+ }
+ return JsonResponse::success(
+ $this->connectivityTester->canConnect($host, $port),
+ );
+ }
+}