function SpamAction($message, $bIsSPAM, $bDelete = false) { global $DB; global $BX_MAIL_SPAM_CNT; if(!is_set($BX_MAIL_SPAM_CNT, "G")) { $strSql = "SELECT MAX(GOOD_CNT) as G, MAX(BAD_CNT) as B FROM b_mail_spam_weight"; if($res = $DB->Query($strSql)) $BX_MAIL_SPAM_CNT = $res->Fetch(); if(intval($BX_MAIL_SPAM_CNT["G"])<=0) $BX_MAIL_SPAM_CNT["G"] = 1; if(intval($BX_MAIL_SPAM_CNT["B"])<=0) $BX_MAIL_SPAM_CNT["B"] = 1; } if($bDelete && $bIsSPAM) $BX_MAIL_SPAM_CNT["B"]--; elseif($bDelete && !$bIsSPAM) $BX_MAIL_SPAM_CNT["G"]--; elseif(!$bDelete && $bIsSPAM) $BX_MAIL_SPAM_CNT["B"]++; elseif(!$bDelete && !$bIsSPAM) $BX_MAIL_SPAM_CNT["G"]++; @set_time_limit(30); // split to words $arWords = CMailFilter::getWords($message, 1000); // for every word find Si $strWords = "''"; foreach($arWords as $word) { $word_md5 = md5($word); // change weight $strSql = "INSERT INTO b_mail_spam_weight(WORD_ID, WORD_REAL, GOOD_CNT, BAD_CNT, TOTAL_CNT) ". "VALUES('".$word_md5."', '".$DB->ForSql($word, 40)."', ".($bIsSPAM?0:1).", ".($bIsSPAM?1:0).", 1)"; if($bDelete || (!$DB->Query($strSql, true))) { if($bDelete) { $strSql = "UPDATE b_mail_spam_weight SET ". " GOOD_CNT = GOOD_CNT - ".($bIsSPAM?0:1).", ". " BAD_CNT = BAD_CNT - ".($bIsSPAM?1:0).", ". " TOTAL_CNT = TOTAL_CNT - 1 ". "WHERE WORD_ID = '".$word_md5."' ". " AND ".($bIsSPAM?"BAD_CNT>0":"GOOD_CNT>0");// AND WORD_REAL = '".$DB->ForSql($word, 40)."'"; } else { $strSql = "UPDATE b_mail_spam_weight SET ". " GOOD_CNT = GOOD_CNT + ".($bIsSPAM?0:1).", ". " BAD_CNT = BAD_CNT + ".($bIsSPAM?1:0).", ". " TOTAL_CNT = TOTAL_CNT + 1 ". "WHERE WORD_ID='".$word_md5."'";// AND WORD_REAL = '".$DB->ForSql($word, 40)."'"; } $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); } } if(COption::GetOptionString("mail", "reset_all_spam_result", "N") == "Y") $DB->Query("UPDATE b_mail_message SET SPAM_LAST_RESULT='N'"); }