You are here

function surbl_spam_filter in Spam 5.3

Search for known spam urls in content.

1 call to surbl_spam_filter()
surbl_spamapi in filters/surbl/surbl.module
Spam hook_spamapi implementation.

File

filters/surbl/surbl.module, line 95

Code

function surbl_spam_filter($content, $type, $fields, $extra = array(), $filter_test = FALSE) {
  $action = array();
  $id = spam_invoke_module($type, 'content_id', $content, $extra);
  $spam = FALSE;
  $urls = _surbl_url_extract($content, $type, $fields, $extra);
  if (is_array($urls) && !empty($urls)) {
    foreach ($urls as $url) {
      $lookup = "{$url}.multi.surbl.org";
      $ip = gethostbyname($lookup);
      if ($ip != $lookup) {

        // this domain was in a SURBL, process accordingly
        preg_match("/[^\\.\\/]+\$/", $ip, $code);
        if ($code[0] & SURBL_SC) {
          spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array(
            '@url' => $url,
            '@surbl' => t('SpamCop message-body URI domains'),
          )), $type, $id);
        }
        if ($code[0] & SURBL_WS) {
          spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array(
            '@url' => $url,
            '@surbl' => t('sa-blacklist domains'),
          )), $type, $id);
        }
        if ($code[0] & SURBL_PH) {
          spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array(
            '@url' => $url,
            '@surbl' => t('Phishing data source'),
          )), $type, $id);
        }
        if ($code[0] & SURBL_OB) {
          spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array(
            '@url' => $url,
            '@surbl' => t('Outblaze URI blacklist'),
          )), $type, $id);
        }
        if ($code[0] & SURBL_AB) {
          spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array(
            '@url' => $url,
            '@surbl' => t('AbuseButler spamvertised sites'),
          )), $type, $id);
        }
        if ($code[0] & SURBL_JP) {
          spam_log(SPAM_IMPORTANT, 'surbl_spam_filter', t('found spam url(@url) @surbl', array(
            '@url' => $url,
            '@surbl' => t('jwSpamSpy + Prolocation data source'),
          )), $type, $id);
        }
        $action['surbl'][] = array(
          'url' => $url,
          'probability' => 99,
        );
        $spam = TRUE;
      }
      else {
        spam_log(SPAM_DEBUG, 'surbl_spam_filter', t('not spam url(@url)', array(
          '@url' => $url,
        )), $type, $id);
      }
    }
  }
  if ($spam) {
    $action['total'] = 99;
  }
  else {
    $action['total'] = 0;
  }
  return $action;
}