mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-05 23:47:03 +03:00
Improved BIMI detection code #115
This commit is contained in:
parent
40e2375b3e
commit
69fb887e63
2 changed files with 45 additions and 8 deletions
|
|
@ -260,14 +260,7 @@ class Email implements \JsonSerializable
|
||||||
/*
|
/*
|
||||||
$BIMI = '';
|
$BIMI = '';
|
||||||
if (Enumerations\DkimStatus::PASS == $this->GetDkimStatus()) {
|
if (Enumerations\DkimStatus::PASS == $this->GetDkimStatus()) {
|
||||||
if ($values = \dns_get_record($this->GetDomain(), \DNS_TXT)) {
|
$BIMI = \SnappyMail\DNS\BIMI($this->GetDomain());
|
||||||
foreach ($values as $value) {
|
|
||||||
if (\str_starts_with($value['txt'], 'v=BIMI1')) {
|
|
||||||
$BIMI = \preg_replace('/^.+l=([^;]+)(;.*)?$/', '$1', $value['txt']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return array(
|
return array(
|
||||||
|
|
|
||||||
44
snappymail/v/0.0.0/app/libraries/snappymail/dns.php
Normal file
44
snappymail/v/0.0.0/app/libraries/snappymail/dns.php
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SnappyMail;
|
||||||
|
|
||||||
|
abstract class DNS
|
||||||
|
{
|
||||||
|
public static function BIMI(string $domain) : string
|
||||||
|
{
|
||||||
|
$oCache = \RainLoop\Api::Actions()->Cacher();
|
||||||
|
$BIMI = $oCache->Get("dns-bimi-{$domain}") ?: null;
|
||||||
|
if ($BIMI) {
|
||||||
|
$BIMI = \json_decode($BIMI);
|
||||||
|
if ($BIMI[1] < \time()) {
|
||||||
|
$BIMI = null;
|
||||||
|
} else {
|
||||||
|
$BIMI = $BIMI[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null === $BIMI) {
|
||||||
|
$BIMI = '';
|
||||||
|
$values = \dns_get_record($domain, \DNS_TXT);
|
||||||
|
if ($values) {
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if (\str_starts_with($value['txt'], 'v=BIMI1')) {
|
||||||
|
$BIMI = \preg_replace('/^.+l=([^;]+)(;.*)?$/D', '$1', $value['txt']);
|
||||||
|
$oCache->Set("dns-bimi-{$domain}", \json_encode([
|
||||||
|
$BIMI,
|
||||||
|
time() + $value['ttl']
|
||||||
|
]));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$BIMI) {
|
||||||
|
// Don't lookup for 24 hours
|
||||||
|
$oCache->Set("dns-bimi-{$domain}", \json_encode([
|
||||||
|
$BIMI,
|
||||||
|
time() + 86400
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $BIMI;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue