Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended TXT parsing #112

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
prepare and parse spf
antedebaas committed Jul 11, 2024
commit 0a303ac64d683fdf861bac64eaf6456b2c9b1cd0
4 changes: 2 additions & 2 deletions src/TXTRecords/BIMI1.php
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ function castL(string $value): string
if(count($matches) < 2){
return "";
}
return str_replace(";", "",$matches[1]);
return str_replace(";", "",$this->prepareText($matches[1]));
}

function castA(string $value): string
@@ -30,6 +30,6 @@ function castA(string $value): string
if(count($matches) < 2){
return "";
}
return str_replace(";", "",$matches[1]);
return str_replace(";", "",$this->prepareText($matches[1]));
}
}
4 changes: 2 additions & 2 deletions src/TXTRecords/DKIM1.php
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ function castK(string $value): string
if(count($matches) < 2){
return "";
}
return str_replace(";", "",$matches[1]);
return str_replace(";", "",$this->prepareText($matches[1]));
}

function castP(string $value): string
@@ -30,6 +30,6 @@ function castP(string $value): string
if(count($matches) < 2){
return "";
}
return str_replace(";", "",$matches[1]);
return str_replace(";", "",$this->prepareText($matches[1]));
}
}
16 changes: 11 additions & 5 deletions src/TXTRecords/DMARC1.php
Original file line number Diff line number Diff line change
@@ -29,14 +29,17 @@ function castP(string $value): string
if(count($matches) < 2){
return "";
}
return str_replace(";", "",$matches[1]);
return str_replace(";", "",$this->prepareText($matches[1]));
}

function castRua(string $value): array
{
preg_match("/rua=([^;]*)(?:;|$)/i", $value, $matches);
if (isset($matches[1])) {
$emails = preg_split("/\s*,/", $matches[1]);
foreach ($emails as $key => $email) {
$emails[$key] = $this->prepareText($email);
}
}
else {
return "";
@@ -49,6 +52,9 @@ function castRuf(string $value): array
preg_match("/ruf=([^;]*)(?:;|$)/i", $value, $matches);
if (isset($matches[1])) {
$emails = preg_split("/\s*,/", $matches[1]);
foreach ($emails as $key => $email) {
$emails[$key] = $this->prepareText($email);
}
}
else {
return "";
@@ -62,16 +68,16 @@ function castSp(string $value): string
if(count($matches) < 2){
return "";
}
return str_replace(";", "",$matches[1]);
return str_replace(";", "",$this->prepareText($matches[1]));
}

function castPct(string $value): int
{
preg_match('/pct=([0-9]{1-3}+)/', $value, $matches);
if(count($matches) < 2){
return "";
return 100;
}
return str_replace(";", "",$matches[1]);
return str_replace(";", "",$this->prepareInt($matches[1]));
}

function castFo(string $value): string
@@ -80,6 +86,6 @@ function castFo(string $value): string
if(count($matches) < 2){
return "";
}
return str_replace(";", "",$matches[1]);
return str_replace(";", "",$this->prepareText($matches[1]));
}
}
14 changes: 13 additions & 1 deletion src/TXTRecords/SPF1.php
Original file line number Diff line number Diff line change
@@ -4,12 +4,24 @@

class SPF1 extends V {

public string $value;
public array $value;

function __construct(string $value)
{
$this->type = 'SPF';
$this->version = 1;
$this->value = $this->cast('value',$value);
}

function castValue(string $value): array
{
preg_match_all('/([a-zA-Z0-9:\.-~?]+)+/', $value, $matches);
if(count($matches) < 1){
return array();
}
foreach ($matches[1] as $key => $match) {
$matches[1][$key] = $this->prepareText($match);
}
return str_replace(";", "",$matches[1]);
}
}
2 changes: 1 addition & 1 deletion src/TXTRecords/STSV1.php
Original file line number Diff line number Diff line change
@@ -16,6 +16,6 @@ function __construct(string $value)
function castId(string $value): int
{
preg_match('/id=([0-9]+)/', $value, $matches);
return $matches[1];
return $this->prepareInt($matches[1]);
}
}
3 changes: 3 additions & 0 deletions src/TXTRecords/TLSRPTV1.php
Original file line number Diff line number Diff line change
@@ -18,6 +18,9 @@ function castRua(string $value): array
preg_match("/rua=([^;]*)(?:;|$)/i", $value, $matches);
if (isset($matches[1])) {
$emails = preg_split("/\s*,/", $matches[1]);
foreach ($emails as $key => $email) {
$emails[$key] = $this->prepareText($email);
}
}
else {
return "";
8 changes: 7 additions & 1 deletion src/TXTRecords/V.php
Original file line number Diff line number Diff line change
@@ -2,10 +2,15 @@

namespace Spatie\Dns\TXTRecords;

class V {
abstract class V {
public string $type;
public string $version;

protected function prepareInt($value): int
{
return intval($value);
}

protected function prepareText(string $value): string
{
if (str_starts_with($value, '"') && str_ends_with($value, '"')) {
@@ -27,4 +32,5 @@ protected function cast(string $attribute, $value)

return $value;
}

}