mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Added: DKIM status
This commit is contained in:
parent
c6db99d53b
commit
9bc977cccf
10 changed files with 239 additions and 7 deletions
|
|
@ -32,6 +32,11 @@ class Email
|
|||
*/
|
||||
private $sRemark;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sDkimStatus;
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*
|
||||
|
|
@ -51,6 +56,8 @@ class Email
|
|||
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(\trim($sEmail), true);
|
||||
$this->sDisplayName = \trim($sDisplayName);
|
||||
$this->sRemark = \trim($sRemark);
|
||||
|
||||
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -223,6 +230,14 @@ class Email
|
|||
return $this->sRemark;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function GetDkimStatus()
|
||||
{
|
||||
return $this->sDkimStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -241,14 +256,22 @@ class Email
|
|||
return \MailSo\Base\Utils::GetDomainFromEmail($this->GetEmail($bIdn));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sDkimStatus
|
||||
*/
|
||||
public function SetDkimStatus($sDkimStatus)
|
||||
{
|
||||
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bIdn = false
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function ToArray($bIdn = false)
|
||||
{
|
||||
return array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark);
|
||||
return array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark, $this->sDkimStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of MailSo.
|
||||
*
|
||||
* (c) 2014 Usenko Timur
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace MailSo\Mime\Enumerations;
|
||||
|
||||
/**
|
||||
* @category MailSo
|
||||
* @package Mime
|
||||
* @subpackage Enumerations
|
||||
*/
|
||||
class DkimStatus
|
||||
{
|
||||
const NONE = 'none';
|
||||
const PASS = 'pass';
|
||||
const FAIL = 'fail';
|
||||
const POLICY = 'policy';
|
||||
const NEUTRAL = 'neutral';
|
||||
const TEMP_ERROR = 'temperror';
|
||||
const PREM_ERROR = 'permerror';
|
||||
|
||||
/**
|
||||
* @param string $sStatus
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function verifyValue($sStatus)
|
||||
{
|
||||
return \in_array($sStatus, array(
|
||||
self::NONE,
|
||||
self::PASS,
|
||||
self::FAIL,
|
||||
self::POLICY,
|
||||
self::NEUTRAL,
|
||||
self::TEMP_ERROR,
|
||||
self::PREM_ERROR,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sStatus
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function normalizeValue($sStatus)
|
||||
{
|
||||
$sStatus = \strtolower(\trim($sStatus));
|
||||
return self::verifyValue($sStatus) ? $sStatus : self::NONE;
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +147,8 @@ class HeaderCollection extends \MailSo\Base\Collection
|
|||
/**
|
||||
* @param string $sHeaderName
|
||||
* @param bool $bCharsetAutoDetect = false
|
||||
* @return string
|
||||
*
|
||||
* @return \MailSo\Mime\EmailCollection|null
|
||||
*/
|
||||
public function GetAsEmailCollection($sHeaderName, $bCharsetAutoDetect = false)
|
||||
{
|
||||
|
|
@ -163,7 +164,7 @@ class HeaderCollection extends \MailSo\Base\Collection
|
|||
|
||||
/**
|
||||
* @param string $sHeaderName
|
||||
* @return \MailSo\Mime\ParameterCollection | null
|
||||
* @return \MailSo\Mime\ParameterCollection|null
|
||||
*/
|
||||
public function ParametersByName($sHeaderName)
|
||||
{
|
||||
|
|
@ -327,7 +328,7 @@ class HeaderCollection extends \MailSo\Base\Collection
|
|||
{
|
||||
$this->Add($oHeader);
|
||||
}
|
||||
|
||||
|
||||
$sName = null;
|
||||
$sValue = null;
|
||||
}
|
||||
|
|
@ -355,6 +356,79 @@ class HeaderCollection extends \MailSo\Base\Collection
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function DkimStatuses()
|
||||
{
|
||||
$aResult = array();
|
||||
|
||||
$aHeaders = $this->ValuesByName(\MailSo\Mime\Enumerations\Header::AUTHENTICATION_RESULTS);
|
||||
if (\is_array($aHeaders) && 0 < \count($aHeaders))
|
||||
{
|
||||
foreach ($aHeaders as $sHeaderValue)
|
||||
{
|
||||
$sStatus = '';
|
||||
$sDomain = '';
|
||||
$sDkimLine = '';
|
||||
|
||||
$aMatch = array();
|
||||
|
||||
if (\preg_match('/dkim=[^\r\n;]+/i', $sHeaderValue, $aMatch) && !empty($aMatch[0]))
|
||||
{
|
||||
$sDkimLine = $aMatch[0];
|
||||
|
||||
$aMatch = array();
|
||||
if (\preg_match('/dkim=([a-zA-Z0-9]+)/i', $sDkimLine, $aMatch) && !empty($aMatch[1]))
|
||||
{
|
||||
$sStatus = $aMatch[1];
|
||||
}
|
||||
|
||||
$aMatch = array();
|
||||
if (\preg_match('/header\.(d|i|from)=([^\s]+)/i', $sDkimLine, $aMatch) && !empty($aMatch[2]))
|
||||
{
|
||||
$sDomain = \trim($aMatch[2]);
|
||||
$sDomain = \trim($sDomain, '@.');
|
||||
}
|
||||
|
||||
if (!empty($sStatus) && !empty($sDomain))
|
||||
{
|
||||
$aResult[] = array($sStatus, $sDomain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function PopulateEmailColectionByDkim($oEmails)
|
||||
{
|
||||
if ($oEmails && $oEmails instanceof \MailSo\Mime\EmailCollection)
|
||||
{
|
||||
$aDkimStatuses = $this->DkimStatuses();
|
||||
if (\is_array($aDkimStatuses) && 0 < \count($aDkimStatuses))
|
||||
{
|
||||
$oEmails->ForeachList(function (/* @var $oItem \MailSo\Mime\Email */ $oItem) use ($aDkimStatuses) {
|
||||
if ($oItem && $oItem instanceof \MailSo\Mime\Email)
|
||||
{
|
||||
$sEmailDomain = $oItem->GetDomain();
|
||||
foreach ($aDkimStatuses as $aDkimData)
|
||||
{
|
||||
if (isset($aDkimData[0], $aDkimData[1]) && $sEmailDomain === $aDkimData[1])
|
||||
{
|
||||
$oItem->SetDkimStatus($aDkimData[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue