function spam_custom_filter in Spam 5
1 call to spam_custom_filter()
- spam_content_filter in ./
spam.module - Determine whether or not provided text is spam.
File
- ./
spam.module, line 1251
Code
function spam_custom_filter($header, $body, &$action) {
$weight = 0;
$matches = 0;
$text = $header . ' ' . $body;
$result = db_query('SELECT scid, filter, style, effect, action FROM {spam_custom} WHERE effect != %d', SPAM_CUSTOM_DISABLED);
while ($filter = db_fetch_object($result)) {
// determine which portion of the content we are scanning
if ($filter->action & SPAM_CUSTOM_ACTION_HEADER) {
$text = $header;
}
else {
if ($filter->action & SPAM_CUSTOM_ACTION_HEADER) {
$text = $body;
}
else {
$text = $header . ' ' . $body;
}
}
// scan the content
switch ($filter->style) {
case SPAM_CUSTOM_PLAIN:
case SPAM_CUSTOM_URL:
$match = preg_match_all("/{$filter->filter}/", $text, $temporary);
$matches += $match;
break;
case SPAM_CUSTOM_REGEX:
$match = preg_match_all($filter->filter, $text, $temporary);
$matches += $match;
break;
}
// if matching, perform actions and apply weights
if ($match) {
db_query('UPDATE {spam_custom} SET matches = matches + %d, last = %d WHERE scid = %d', $match, time(), $filter->scid);
if ($filter->action & SPAM_CUSTOM_ACTION_DELETE) {
$action[SPAM_CUSTOM_ACTION_DELETE]++;
}
if ($filter->action & SPAM_CUSTOM_ACTION_NOMAIL) {
$action[SPAM_CUSTOM_ACTION_NOMAIL]++;
}
// add or subtract appropriate weight for each match
switch ($filter->effect) {
case SPAM_CUSTOM_ALWAYS_SPAM:
$weight += $match * WEIGHT_ALWAYS_SPAM;
spam_log(SPAM_DEBUG, t("custom filters: matched 'always spam' filter @num times, added @weight weight, matched filter '%filter'", array(
'@num' => $match,
'@weight' => $match * WEIGHT_ALWAYS_SPAM,
'%filter' => $filter->filter,
)));
break;
case SPAM_CUSTOM_USUALLY_SPAM:
$weight += $match * WEIGHT_USUALLY_SPAM;
spam_log(SPAM_DEBUG, t("custom filters: matched 'usually spam' filter @num times, added @weight weight, matched filter '%filter'", array(
'@num' => $match,
'@weight' => $match * WEIGHT_USUALLY_SPAM,
'%filter' => $filter->filter,
)));
break;
case SPAM_CUSTOM_MAYBE_SPAM:
$weight += $match * WEIGHT_MAYBE_SPAM;
spam_log(SPAM_DEBUG, t("custom filters: matched 'maybe spam' filter @num times, added @weight weight, matched filter '%filter'", array(
'@num' => $match,
'@weight' => $match * WEIGHT_MAYBE_SPAM,
'%filter' => $filter->filter,
)));
break;
case SPAM_CUSTOM_MAYBE_NOTSPAM:
$weight += $match * WEIGHT_MAYBE_NOTSPAM;
spam_log(SPAM_DEBUG, t("custom filters: matched 'maybe spam' filter @num times, added @weight weight, matched filter '%filter'", array(
'@num' => $match,
'@weight' => $match * WEIGHT_MAYBE_NOTSPAM,
'%filter' => $filter->filter,
)));
break;
case SPAM_CUSTOM_USUALLY_NOTSPAM:
$weight += $match * WEIGHT_RARELY_SPAM;
spam_log(SPAM_DEBUG, t("custom filters: matched 'rarely spam' filter @num times, added @weight weight, matched filter '%filter'", array(
'@num' => $match,
'@weight' => $match * WEIGHT_RARELY_SPAM,
'%filter' => $filter->filter,
)));
break;
case SPAM_CUSTOM_NEVER_SPAM:
$weight += $match * WEIGHT_NEVER_SPAM;
spam_log(SPAM_DEBUG, t("custom filters: matched 'never spam' filter @num times, added @weight weight, matched filter '%filter'", array(
'@num' => $match,
'@weight' => $match * WEIGHT_NEVER_SPAM,
'%filter' => $filter->filter,
)));
break;
}
}
}
if ($matches != 0) {
spam_log(SPAM_LOG, t("custom filters: matched @num times, adding weight of @weight", array(
'@num' => $matches,
'@weight' => $weight,
)));
}
return $weight;
}