Added SpamResult

This commit is contained in:
djmaze 2021-04-09 09:01:48 +02:00
parent 7fc279293c
commit 3d10bbface
3 changed files with 15 additions and 3 deletions

View file

@ -46,6 +46,7 @@ export class MessageModel extends AbstractModel {
subject: '', subject: '',
size: 0, size: 0,
spamScore: 0, spamScore: 0,
spamResult: '',
isSpam: false, isSpam: false,
dateTimeStampInUTC: 0, dateTimeStampInUTC: 0,
priority: MessagePriority.Normal, priority: MessagePriority.Normal,
@ -119,6 +120,7 @@ export class MessageModel extends AbstractModel {
this.subject(''); this.subject('');
this.size(0); this.size(0);
this.spamScore(0); this.spamScore(0);
this.spamResult('');
this.isSpam(false); this.isSpam(false);
this.dateTimeStampInUTC(0); this.dateTimeStampInUTC(0);
this.priority(MessagePriority.Normal); this.priority(MessagePriority.Normal);
@ -419,6 +421,7 @@ export class MessageModel extends AbstractModel {
this.size(message.size()); this.size(message.size());
this.spamScore(message.spamScore()); this.spamScore(message.spamScore());
this.spamResult(message.spamResult());
this.isSpam(message.isSpam()); this.isSpam(message.isSpam());
this.dateTimeStampInUTC(message.dateTimeStampInUTC()); this.dateTimeStampInUTC(message.dateTimeStampInUTC());
this.priority(message.priority()); this.priority(message.priority());

View file

@ -227,7 +227,7 @@ class MessageViewMailBoxUserView extends AbstractViewRight {
this.viewTimeStamp(message.dateTimeStampInUTC()); this.viewTimeStamp(message.dateTimeStampInUTC());
this.viewSize(message.friendlySize()); this.viewSize(message.friendlySize());
this.viewSpamScore(message.spamScore()); this.viewSpamScore(message.spamScore());
this.viewSpamStatus(i18n(message.isSpam() ? 'GLOBAL/SPAM' : 'GLOBAL/NOT_SPAM')); this.viewSpamStatus(i18n(message.isSpam() ? 'GLOBAL/SPAM' : 'GLOBAL/NOT_SPAM') + ': ' + message.spamResult());
this.viewLineAsCss(message.lineAsCss()); this.viewLineAsCss(message.lineAsCss());
this.viewViewLink(message.viewLink()); this.viewViewLink(message.viewLink());
this.viewUnsubscribeLink(message.getFirstUnsubsribeLink()); this.viewUnsubscribeLink(message.getFirstUnsubsribeLink());

View file

@ -25,6 +25,7 @@ class Message implements \JsonSerializable
$sContentType = '', $sContentType = '',
$iSize = 0, $iSize = 0,
$iSpamScore = 0, $iSpamScore = 0,
$sSpamResult = '',
$bIsSpam = false, $bIsSpam = false,
$iInternalTimeStampInUTC = 0, $iInternalTimeStampInUTC = 0,
$iHeaderTimeStampInUTC = 0, $iHeaderTimeStampInUTC = 0,
@ -248,6 +249,11 @@ class Message implements \JsonSerializable
return $this->iSpamScore; return $this->iSpamScore;
} }
public function SpamResult() : string
{
return $this->sSpamResult;
}
public function IsSpam() : bool public function IsSpam() : bool
{ {
return $this->bIsSpam; return $this->bIsSpam;
@ -530,14 +536,16 @@ class Message implements \JsonSerializable
if (\preg_match('/\\[([\\d\\.-]+)\\s*\\/\\s*([\\d\\.]+)\\];/', $spam, $match)) { if (\preg_match('/\\[([\\d\\.-]+)\\s*\\/\\s*([\\d\\.]+)\\];/', $spam, $match)) {
if ($threshold = \floatval($match[2])) { if ($threshold = \floatval($match[2])) {
$this->iSpamScore = \max(0, \min(100, 100 * \floatval($match[1]) / $threshold)); $this->iSpamScore = \max(0, \min(100, 100 * \floatval($match[1]) / $threshold));
$this->sSpamResult = "{$match[1]} / {$match[2]}";
} }
$this->bIsSpam = false !== \stripos($this->sSubject, '*** SPAM ***'); $this->bIsSpam = false !== \stripos($this->sSubject, '*** SPAM ***');
} else { } else {
$spam = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_SPAM_STATUS); $spam = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_SPAM_STATUS);
if (\preg_match('/(?:hits|score)=([\\d\\.-]+)/', $spam, $value) if (\preg_match('/(?:hits|score)=([\\d\\.-]+)/', $spam, $value)
&& \preg_match('/required=([\\d\\.-]+)/', $spam, $threshold)) { && \preg_match('/required=([\\d\\.-]+)/', $spam, $required)) {
if ($threshold = \floatval($threshold[1])) { if ($threshold = \floatval($required[1])) {
$this->iSpamScore = \max(0, \min(100, 100 * \floatval($value[1]) / $threshold)); $this->iSpamScore = \max(0, \min(100, 100 * \floatval($value[1]) / $threshold));
$this->sSpamResult = "{$value[1]} / {$required[1]}";
} }
} }
$spam = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_SPAM_FLAG); $spam = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_SPAM_FLAG);
@ -723,6 +731,7 @@ class Message implements \JsonSerializable
'MessageId' => $this->MessageId(), 'MessageId' => $this->MessageId(),
'Size' => $this->Size(), 'Size' => $this->Size(),
'SpamScore' => $this->SpamScore(), 'SpamScore' => $this->SpamScore(),
'SpamResult' => $this->SpamResult(),
'IsSpam' => $this->IsSpam(), 'IsSpam' => $this->IsSpam(),
'DateTimeStampInUTC' => $this->InternalTimeStampInUTC(), 'DateTimeStampInUTC' => $this->InternalTimeStampInUTC(),