Index: spam/spam.module
===================================================================
--- spam/spam.module	(revision 6030)
+++ spam/spam.module	(working copy)
@@ -906,14 +906,28 @@
   static $initialized = FALSE;
 
   if (!$initialized) {
+    $initialized = TRUE;
+    $result = db_query("SELECT name, module FROM {spam_filters}");
+    while($row = db_fetch_array($result)) {
+      $spam_filter[$row['module']][$row['name']] = 0;
+    }
     $modules = spam_invoke_api('filter_module');
     foreach ($modules as $module) {
       $filter = spam_invoke_module($module, 'filter_info');
-      $fid = db_result(db_query_range("SELECT fid FROM {spam_filters} WHERE name = '%s' AND module = '%s'", $filter['name'], $filter['module'], 0, 1));
-      if (!$fid) {
+      if (!isset($spam_filter[$filter['module']][$filter['name']])) {
         spam_install_filter($filter);
       }
+      $spam_filter[$filter['module']][$filter['name']] = 1;
     }
+    // go through all the filters, if the status is still 0, then it was uninstalled
+    // (unfortunately there are no hooks that signals everyone about disabling/uninstalling modules)
+    foreach ($spam_filter as $module => $names) {
+      foreach ($names as $name => $status) {
+        if ($status == 0) {
+          db_query("DELETE FROM {spam_filters} WHERE name = '%s' AND module = '%s'", $name, $module);
+        }
+      }
+    }
   }
 }
 
