Skip to content

Commit

Permalink
Added spam score result for Bogosity
Browse files Browse the repository at this point in the history
  • Loading branch information
djmaze committed Apr 9, 2021
1 parent 478ba00 commit 6217d1c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private function getEnvelopeOrHeadersRequestString()
// SPAM
\MailSo\Mime\Enumerations\Header::X_SPAM_STATUS,
\MailSo\Mime\Enumerations\Header::X_SPAMD_RESULT,
\MailSo\Mime\Enumerations\Header::X_BOGOSITY
), true);
//
// return \MailSo\Imap\Enumerations\FetchType::ENVELOPE;
Expand Down
20 changes: 13 additions & 7 deletions snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,15 +532,21 @@ function ($link) {
);
}

$spam = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_SPAMD_RESULT);
if (\preg_match('/\\[([\\d\\.-]+)\\s*\\/\\s*([\\d\\.]+)\\];/', $spam, $match)) {
if ($threshold = \floatval($match[2])) {
$this->iSpamScore = \max(0, \min(100, 100 * \floatval($match[1]) / $threshold));
$this->sSpamResult = "{$match[1]} / {$match[2]}";
if ($spam = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_SPAMD_RESULT)) {
if (\preg_match('/\\[([\\d\\.-]+)\\s*\\/\\s*([\\d\\.]+)\\];/', $spam, $match)) {
if ($threshold = \floatval($match[2])) {
$this->iSpamScore = \max(0, \min(100, 100 * \floatval($match[1]) / $threshold));
$this->sSpamResult = "{$match[1]} / {$match[2]}";
}
}
$this->bIsSpam = false !== \stripos($this->sSubject, '*** SPAM ***');
} else {
$spam = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_SPAM_STATUS);
} else if ($spam = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_BOGOSITY)) {
$this->sSpamResult = $spam;
$this->bIsSpam = !!\preg_match('/yes|spam/', $spam);
if (\preg_match('/spamicity=([\\d\\.]+)/', $spam, $spamicity)) {
$this->iSpamScore = \max(0, \min(100, \floatval($spamicity[1])));
}
} else if ($spam = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_SPAM_STATUS)) {
if (\preg_match('/(?:hits|score)=([\\d\\.-]+)/', $spam, $value)
&& \preg_match('/required=([\\d\\.-]+)/', $spam, $required)) {
if ($threshold = \floatval($required[1])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ abstract class Header
// Rspamd
const X_SPAMD_RESULT = 'X-Spamd-Result'; // default: False [7.13 / 9.00];
const X_SPAMD_BAR = 'X-Spamd-Bar'; // +++++++
// Bogofilter
const X_BOGOSITY = 'X-Bogosity';
// Unknown
const X_SPAM_CATEGORY = 'X-Spam-Category'; // SPAM|LEGIT
const X_SPAM_SCORE = 'X-Spam-Score'; // 0
Expand Down

0 comments on commit 6217d1c

Please sign in to comment.