ispDb = $ispDb; $this->mxRecord = $mxRecord; $this->connectivityTester = $connectivityTester; $this->hostValidator = $hostValidator; } /** * @param string $email * * @NoAdminRequired * @UserRateThrottle(limit=5, period=60) * * @return JsonResponse */ #[TrapError] #[UserRateLimit(limit: 5, period: 60)] public function queryIspdb(string $host, string $email): JsonResponse { $rfc822Address = new Horde_Mail_Rfc822_Address($email); if (!$rfc822Address->valid || !$this->hostValidator->isValid($host)) { return JsonResponse::fail('Invalid email address', Http::STATUS_UNPROCESSABLE_ENTITY) ->cacheFor(60 * 60, false, true); } $config = $this->ispDb->query($host, $rfc822Address); return JsonResponse::success($config)->cacheFor(5 * 60, false, true); } /** * @param string $email * * @NoAdminRequired * @UserRateThrottle(limit=5, period=60) * * @return JsonResponse */ #[TrapError] #[UserRateLimit(limit: 5, period: 60)] public function queryMx(string $email): JsonResponse { $rfc822Address = new Horde_Mail_Rfc822_Address($email); if (!$rfc822Address->valid || !$this->hostValidator->isValid($rfc822Address->host)) { return JsonResponse::fail('Invalid email address', Http::STATUS_UNPROCESSABLE_ENTITY) ->cacheFor(60 * 60, false, true); } return JsonResponse::success( $this->mxRecord->query($rfc822Address->host), )->cacheFor(5 * 60, false, true); } /** * @param string $host * @param int $port * * @NoAdminRequired * @UserRateThrottle(limit=30, period=60) * * @return JsonResponse */ #[TrapError] #[UserRateLimit(limit: 30, period: 60)] public function testConnectivity(string $host, int $port): JsonResponse { if (!in_array($port, [143, 993, 465, 587])) { return JsonResponse::fail('Port not allowed'); } if (!$this->hostValidator->isValid($host)) { return JsonResponse::success(false); } return JsonResponse::success( $this->connectivityTester->canConnect($host, $port), ); } }