Add SPF check API method to backend [MAILPOET-2295]

This commit is contained in:
wxa
2019-09-02 09:46:48 +03:00
committed by Jack Kitterhing
parent e72ea01f68
commit f67e356202
4 changed files with 103 additions and 0 deletions

View File

@ -8,12 +8,17 @@ use MailPoet\API\JSON\Error as APIError;
use MailPoet\Config\AccessControl;
use MailPoet\Config\Installer;
use MailPoet\Services\Bridge;
use MailPoet\Services\SPFCheck;
use MailPoet\Settings\SettingsController;
use MailPoet\WP\DateTime;
use MailPoet\WP\Functions as WPFunctions;
class Services extends APIEndpoint {
public $bridge;
public $date_time;
public $settings;
public $spf_check;
public $permissions = [
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS,
];
@ -21,6 +26,24 @@ class Services extends APIEndpoint {
function __construct() {
$this->bridge = new Bridge();
$this->date_time = new DateTime();
$this->settings = new SettingsController();
$this->spf_check = new SPFCheck();
}
function checkSPFRecord($data = []) {
$sender_address = $this->settings->get('sender.address');
$domain_name = mb_substr($sender_address, mb_strpos($sender_address, '@') + 1);
$result = $this->spf_check->checkSPFRecord($domain_name);
if (!$result) {
return $this->errorResponse(
[APIError::BAD_REQUEST => WPFunctions::get()->__('SPF check has failed.', 'mailpoet')],
['sender_address' => $sender_address, 'domain_name' => $domain_name]
);
}
return $this->successResponse();
}
function checkMSSKey($data = []) {