Index: spam/filters/spam_filter_bayesian/spam_filter_bayesian.module
===================================================================
--- spam/filters/spam_filter_bayesian/spam_filter_bayesian.module	(revision 5968)
+++ spam/filters/spam_filter_bayesian/spam_filter_bayesian.module	(working copy)
@@ -149,28 +148,28 @@
   if (!isset($tokens["$type-$id-$tag"])) {
     $string = spam_get_text($content, $type, $fields, $extra);
 
-    $URI = "(http://|https://|ftp://|mailto:)";
+    // Force all tokens to lowercase, again to aggregate tokens.  This both
+    // lowers the total token number of rows in the spam_tokens table and
+    // increases the strength of individual tokens by linking them to
+    // capitalized versions.
+    $sanitized = drupal_strtolower($tring);
+
     // strip out unwanted html/url noise
-    $sanitized = preg_replace("'(www\.)|(</a>)|(href=)|(target=)|(src=)'i", '', $string);
-    $sanitized = preg_replace($URI, '', $sanitized);
+    $sanitized = preg_replace("'(www\.)|(</a>)|(href=)|(target=)|(src=)'", '', $sanitized);
+    $sanitized = preg_replace("(http://|https://|ftp://|mailto:)", '', $sanitized);
 
     // Strip out values that should not be considered part of tokens, so
     // things like '{viagra}' and 'vi.agra' are counted as hits towards
     // 'viagra'
     $sanitized = preg_replace("/[()\{\}\[\]#.,]/", '', $sanitized);
 
-    // Force all tokens to lowercase, again to aggregate tokens.  This both
-    // lowers the total token number of rows in the spam_tokens table and
-    // increases the strength of individual tokens by linking them to
-    // capitalized versions.
-    $sanitized = drupal_strtolower($sanitized);
-
     // divide sanitized string into tokens
     $delimiters = " \t\n\r-_<>'\"`/|*%^&+=~:;?";
     $tok = strtok($sanitized, $delimiters);
+    $min_length = variable_get('spam_filter_bayesian_minimum_token_length', 3);
     while ($tok !== FALSE) {
       // Only inspect the token if over minimum length.
-      if (drupal_strlen($tok) >= variable_get('spam_filter_bayesian_minimum_token_length', 3)) {
+      if (drupal_strlen($tok) >= $min_length) {
         // If the token is longer than 255 characters, truncate it.
         $toks[] = htmlspecialchars(drupal_substr("$tag$tok", 0, 254));
       }
