mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-09-20 15:45:55 +08:00
Added: DKIM status
This commit is contained in:
parent
c6db99d53b
commit
9bc977cccf
|
@ -10,13 +10,15 @@
|
|||
/**
|
||||
* @param {string=} sEmail
|
||||
* @param {string=} sName
|
||||
* @param {string=} sDkimStatus
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function EmailModel(sEmail, sName)
|
||||
function EmailModel(sEmail, sName, sDkimStatus)
|
||||
{
|
||||
this.email = sEmail || '';
|
||||
this.name = sName || '';
|
||||
this.dkimStatus = sDkimStatus || 'none';
|
||||
|
||||
this.clearDuplicateName();
|
||||
}
|
||||
|
@ -42,10 +44,16 @@
|
|||
*/
|
||||
EmailModel.prototype.email = '';
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
EmailModel.prototype.dkimStatus = 'none';
|
||||
|
||||
EmailModel.prototype.clear = function ()
|
||||
{
|
||||
this.email = '';
|
||||
this.name = '';
|
||||
this.dkimStatus = 'none';
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -121,6 +129,7 @@
|
|||
{
|
||||
this.name = Utils.trim(oJsonEmail.Name);
|
||||
this.email = Utils.trim(oJsonEmail.Email);
|
||||
this.dkimStatus = Utils.trim(oJsonEmail.DkimStatus || '');
|
||||
|
||||
bResult = '' !== this.email;
|
||||
this.clearDuplicateName();
|
||||
|
|
|
@ -563,6 +563,21 @@
|
|||
return MessageModel.emailsToLine(this.from, bFriendlyView, bWrapWithLink);
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
MessageModel.prototype.fromDkimData = function ()
|
||||
{
|
||||
var aResult = ['none', ''];
|
||||
if (Utils.isNonEmptyArray(this.from) && 1 === this.from.length &&
|
||||
this.from[0] && this.from[0].dkimStatus)
|
||||
{
|
||||
aResult = [this.from[0].dkimStatus, this.from[0].email];
|
||||
}
|
||||
|
||||
return aResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {boolean} bFriendlyView
|
||||
* @param {boolean=} bWrapWithLink = false
|
||||
|
|
|
@ -58,6 +58,26 @@
|
|||
}
|
||||
}
|
||||
|
||||
.iconcolor-display-none {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.iconcolor-green {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.iconcolor-red {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.iconcolor-white {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.iconcolor-grey {
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
.denied-by-browser {
|
||||
cursor: default;
|
||||
.icon-checkbox-checked, icon-checkbox-unchecked {
|
||||
|
|
|
@ -152,6 +152,7 @@
|
|||
this.viewHash = '';
|
||||
this.viewSubject = ko.observable('');
|
||||
this.viewFromShort = ko.observable('');
|
||||
this.viewFromDkimData = ko.observable(['none', '']);
|
||||
this.viewToShort = ko.observable('');
|
||||
this.viewFrom = ko.observable('');
|
||||
this.viewTo = ko.observable('');
|
||||
|
@ -176,6 +177,33 @@
|
|||
return this.message() ? this.message().pgpSignedVerifyUser() : '';
|
||||
}, this);
|
||||
|
||||
this.viewFromDkimStatusIconClass = ko.computed(function () {
|
||||
|
||||
// var sResult = 'icon-warning-alt iconcolor-grey';
|
||||
var sResult = 'icon-none iconcolor-display-none';
|
||||
switch (this.viewFromDkimData()[0])
|
||||
{
|
||||
case 'none':
|
||||
// sResult = 'icon-warning-alt iconcolor-grey';
|
||||
sResult = 'icon-none iconcolor-display-none';
|
||||
break;
|
||||
case 'pass':
|
||||
sResult = 'icon-ok iconcolor-green';
|
||||
break;
|
||||
default:
|
||||
sResult = 'icon-warning-alt iconcolor-red';
|
||||
break;
|
||||
}
|
||||
|
||||
return sResult;
|
||||
|
||||
}, this);
|
||||
|
||||
this.viewFromDkimStatusTitle = ko.computed(function () {
|
||||
var aStatus = this.viewFromDkimData();
|
||||
return Utils.isNonEmptyArray(aStatus) ? 'DKIM: ' + aStatus[0] + ' (' + aStatus[1] + ')' : '';
|
||||
}, this);
|
||||
|
||||
this.message.subscribe(function (oMessage) {
|
||||
|
||||
this.messageActiveDom(null);
|
||||
|
@ -192,6 +220,7 @@
|
|||
this.viewHash = oMessage.hash;
|
||||
this.viewSubject(oMessage.subject());
|
||||
this.viewFromShort(oMessage.fromToLine(true, true));
|
||||
this.viewFromDkimData(oMessage.fromDkimData());
|
||||
this.viewToShort(oMessage.toToLine(true, true));
|
||||
this.viewFrom(oMessage.fromToLine(false));
|
||||
this.viewTo(oMessage.toToLine(false));
|
||||
|
|
|
@ -657,6 +657,8 @@ class Message
|
|||
$this->oCc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::CC, $bCharsetAutoDetect);
|
||||
$this->oBcc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::BCC, $bCharsetAutoDetect);
|
||||
|
||||
$oHeaders->PopulateEmailColectionByDkim($this->oFrom);
|
||||
|
||||
$this->oSender = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::SENDER, $bCharsetAutoDetect);
|
||||
$this->oReplyTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::REPLY_TO, $bCharsetAutoDetect);
|
||||
$this->oDeliveredTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::DELIVERED_TO, $bCharsetAutoDetect);
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -8274,7 +8274,8 @@ class Actions
|
|||
{
|
||||
$mResult = \array_merge($this->objectData($mResponse, $sParent, $aParameters), array(
|
||||
'Name' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetDisplayName()),
|
||||
'Email' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetEmail(true))
|
||||
'Email' => \MailSo\Base\Utils::Utf8Clear($mResponse->GetEmail(true)),
|
||||
'DkimStatus' => $mResponse->GetDkimStatus()
|
||||
));
|
||||
}
|
||||
else if ('RainLoop\Providers\AddressBook\Classes\Contact' === $sClassName)
|
||||
|
|
|
@ -217,6 +217,8 @@
|
|||
<div class="informationShort" data-bind="event: { 'dblclick': toggleFullScreen }">
|
||||
<span data-bind="visible: !isDraftOrSentFolder()">
|
||||
<span class="from" data-bind="html: viewFromShort, title: viewFrom"></span>
|
||||
|
||||
<i data-bind="css: viewFromDkimStatusIconClass, title: viewFromDkimStatusTitle" />
|
||||
</span>
|
||||
<span data-bind="visible: isDraftOrSentFolder()">
|
||||
<span class="i18n uiLabel labelTo" data-i18n-text="MESSAGE/LABEL_TO"></span>:
|
||||
|
|
Loading…
Reference in a new issue