From f1097831cfe391f915300b0079ba19b35ce24140 Mon Sep 17 00:00:00 2001 From: ey-mailosaur Date: Thu, 26 Sep 2024 11:27:55 +0100 Subject: [PATCH] Introduced deliverability reporting request/models --- src/Models/BlockListResult.php | 31 ++++++++++ src/Models/Content.php | 73 ++++++++++++++++++++++++ src/Models/DeliverabilityReport.php | 63 ++++++++++++++++++++ src/Models/DnsRecords.php | 31 ++++++++++ src/Models/EmailAuthenticationResult.php | 44 ++++++++++++++ src/Models/ResultEnum.php | 12 ++++ src/Models/SpamAssassinResult.php | 33 +++++++++++ src/Operations/Analysis.php | 19 ++++++ tests/EmailsTests.php | 38 ++++++++++++ 9 files changed, 344 insertions(+) create mode 100644 src/Models/BlockListResult.php create mode 100644 src/Models/Content.php create mode 100644 src/Models/DeliverabilityReport.php create mode 100644 src/Models/DnsRecords.php create mode 100644 src/Models/EmailAuthenticationResult.php create mode 100644 src/Models/ResultEnum.php create mode 100644 src/Models/SpamAssassinResult.php diff --git a/src/Models/BlockListResult.php b/src/Models/BlockListResult.php new file mode 100644 index 0000000..56e72cd --- /dev/null +++ b/src/Models/BlockListResult.php @@ -0,0 +1,31 @@ +id = $data->id; + } + + if (property_exists($data, 'name')) { + $this->name = $data->name; + } + + if (property_exists($data, 'result')) { + $this->result = ResultEnum::from($data->result); + } + } +} \ No newline at end of file diff --git a/src/Models/Content.php b/src/Models/Content.php new file mode 100644 index 0000000..f3943ba --- /dev/null +++ b/src/Models/Content.php @@ -0,0 +1,73 @@ +embed = $data->embed; + } + + if (property_exists($data, 'iframe')) { + $this->iframe = $data->iframe; + } + + if (property_exists($data, 'object')) { + $this->object = $data->object; + } + + if (property_exists($data, 'script')) { + $this->script = $data->script; + } + + if (property_exists($data, 'shortUrls')) { + $this->shortUrls = $data->shortUrls; + } + + if (property_exists($data, 'textSize')) { + $this->textSize = $data->textSize; + } + + if (property_exists($data, 'totalSize')) { + $this->totalSize = $data->totalSize; + } + + if (property_exists($data, 'missingAlt')) { + $this->missingAlt = $data->missingAlt; + } + + if (property_exists($data, 'missingListUnsubscribe')) { + $this->missingListUnsubscribe = $data->missingListUnsubscribe; + } + } +} \ No newline at end of file diff --git a/src/Models/DeliverabilityReport.php b/src/Models/DeliverabilityReport.php new file mode 100644 index 0000000..ac4d609 --- /dev/null +++ b/src/Models/DeliverabilityReport.php @@ -0,0 +1,63 @@ +spf = new EmailAuthenticationResult($data->spf); + } + + if (property_exists($data, 'dkim') && is_array($data->dkim)) { + foreach ($data->dkim as $dkimResult) { + $this->dkim[] = new EmailAuthenticationResult($dkimResult); + } + } + + if (property_exists($data, 'dmarc')) { + $this->dmarc = new EmailAuthenticationResult($data->dmarc); + } + + if (property_exists($data, 'blockLists') && is_array($data->blockLists)) { + foreach ($data->blockLists as $blockList) { + $this->blockLists[] = new BlockListResult($blockList); + } + } + + if (property_exists($data, 'content')) { + $this->content = new Content($data->content); + } + + if (property_exists($data, 'dnsRecords')) { + $this->dnsRecords = new DnsRecords($data->dnsRecords); + } + + if (property_exists($data, 'spamAssassin')) { + $this->spamAssassin = new SpamAssassinResult($data->spamAssassin); + } + } +} \ No newline at end of file diff --git a/src/Models/DnsRecords.php b/src/Models/DnsRecords.php new file mode 100644 index 0000000..a0cc0b1 --- /dev/null +++ b/src/Models/DnsRecords.php @@ -0,0 +1,31 @@ +a)) { + $this->a = $data->a; + } + + if (property_exists($data, 'mx') && is_array($data->mx)) { + $this->mx = $data->mx; + } + + if (property_exists($data, 'ptr') && is_array($data->ptr)) { + $this->ptr = $data->ptr; + } + } +} \ No newline at end of file diff --git a/src/Models/EmailAuthenticationResult.php b/src/Models/EmailAuthenticationResult.php new file mode 100644 index 0000000..7e5259a --- /dev/null +++ b/src/Models/EmailAuthenticationResult.php @@ -0,0 +1,44 @@ +result = ResultEnum::from($data->result); + } + + if (property_exists($data, 'description')) { + $this->description = $data->description; + } + + if (property_exists($data, 'rawValue')) { + $this->rawValue = $data->rawValue; + } + + if (property_exists($data, 'tags') && is_array($data->tags)) { + foreach ($data->tags as $tag) { + if (is_object($tag)) { + foreach ($tag as $key => $value) { + $this->tags[$key] = $value; + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Models/ResultEnum.php b/src/Models/ResultEnum.php new file mode 100644 index 0000000..712d239 --- /dev/null +++ b/src/Models/ResultEnum.php @@ -0,0 +1,12 @@ +score = $data->score; + } + + if (property_exists($data, 'result')) { + $this->result = ResultEnum::from($data->result); + } + + if (property_exists($data, 'rules') && is_array($data->rules)) { + foreach ($data->rules as $rule) { + $this->rules[] = new SpamAssassinRule($rule); + } + } + } +} \ No newline at end of file diff --git a/src/Operations/Analysis.php b/src/Operations/Analysis.php index 0d6b5fe..64c2f55 100644 --- a/src/Operations/Analysis.php +++ b/src/Operations/Analysis.php @@ -10,6 +10,7 @@ use Mailosaur\Models\SpamAnalysisResult; +use Mailosaur\Models\DeliverabilityReport; class Analysis extends AOperation { @@ -31,4 +32,22 @@ public function spam($email) return new SpamAnalysisResult($response); } + + /** + * Perform a deliverability report + * + * @param string $email The identifier of the email to be analyzed. + * + * @return DeliverabilityReport + * @throws \Mailosaur\Models\MailosaurException + * @see https://mailosaur.com/docs/api/analysis Perform a deliverability test docs + * @example https://mailosaur.com/docs/api/analysis + */ + public function deliverability($email) + { + $response = $this->request('api/analysis/deliverability/' . urlencode($email)); + + $response = json_decode($response); + return new DeliverabilityReport($response); + } } \ No newline at end of file diff --git a/tests/EmailsTests.php b/tests/EmailsTests.php index ebad63b..8b0fa37 100644 --- a/tests/EmailsTests.php +++ b/tests/EmailsTests.php @@ -211,6 +211,44 @@ public function testSpamAnalysis() } } + public function testDeliverabilityReport() + { + $targetId = self::$emails[0]->id; + + $result = self::$client->analysis->deliverability($targetId); + + $this->assertNotNull($result); + + $this->assertNotNull($result->spf); + + $this->assertNotNull($result->dkim); + foreach ($result->dkim as $dkim) { + $this->assertNotNull($dkim); + } + + $this->assertNotNull($result->dmarc); + + $this->assertNotNull($result->blockLists); + foreach ($result->blockLists as $blockList) { + $this->assertNotNull($blockList); + $this->assertNotNull($blockList->id); + $this->assertNotNull($blockList->name); + } + + $this->assertNotNull($result->content); + + $this->assertNotNull($result->dnsRecords); + $this->assertNotNull($result->dnsRecords->a); + $this->assertNotNull($result->dnsRecords->mx); + $this->assertNotNull($result->dnsRecords->ptr); + + $this->assertNotNull($result->spamAssassin); + foreach ($result->spamAssassin->rules as $rule) { + $this->assertNotEmpty($rule->rule); + $this->assertNotEmpty($rule->description); + } + } + public function testDelete() { $targetEmailId = self::$emails[4]->id;