mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-11-08 06:11:37 +08: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 = '';
|
||||
if (Enumerations\DkimStatus::PASS == $this->GetDkimStatus()) {
|
||||
if ($values = \dns_get_record($this->GetDomain(), \DNS_TXT)) {
|
||||
foreach ($values as $value) {
|
||||
if (\str_starts_with($value['txt'], 'v=BIMI1')) {
|
||||
$BIMI = \preg_replace('/^.+l=([^;]+)(;.*)?$/', '$1', $value['txt']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$BIMI = \SnappyMail\DNS\BIMI($this->GetDomain());
|
||||
}
|
||||
*/
|
||||
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
Reference in a new issue