--- ingo/lib/Script/maildrop.php	22 Oct 2007 21:41:34 -0000	1.16
+++ ingo/lib/Script/maildrop.php	26 Oct 2007 20:39:53 -0000
@@ -48,7 +48,8 @@
         INGO_STORAGE_ACTION_BLACKLIST,
         INGO_STORAGE_ACTION_WHITELIST,
         INGO_STORAGE_ACTION_VACATION,
-        INGO_STORAGE_ACTION_FORWARD
+        INGO_STORAGE_ACTION_FORWARD,
+        INGO_STORAGE_ACTION_SPAM
     );
 
     /**
@@ -155,6 +156,10 @@
                 $this->generateVacation(!empty($filter['disable']));
                 break;
 
+            case INGO_STORAGE_ACTION_SPAM:
+                $this->generateSpamfilter(!empty($filter['disable']));
+                break;
+
             default:
                 if (in_array($filter['action'], $this->_actions)) {
                     /* Create filter if using AND. */
@@ -286,6 +291,41 @@
         $this->_recipes[] = $item;
     }
 
+    /**
+     * Generates the maildrop script to handle spam as identified by SpamAssassin
+     *
+     * @param boolean $disable  Disable the spam-filter?
+     */
+    function generateSpamfilter($disable = false)
+    {
+        $spam = &$GLOBALS['ingo_storage']->retrieve(INGO_STORAGE_ACTION_SPAM);
+        if ($spam == false) {
+            return;
+        }
+
+        $spam_folder = $spam->getSpamFolder();
+
+        $spam_action = (empty($spam_folder)) ? INGO_STORAGE_ACTION_DISCARD : INGO_STORAGE_ACTION_MOVE;
+
+        $this->addItem(new Maildrop_Comment(_("Spam Filter"), $disable, true));+
+        $params = array('action-value' => $spam_folder,
+                        'action' => $spam_action,
+                        'disable' => $disable);
+
+        $recipe = new Maildrop_Recipe($params, $this->_params);
+        if ($GLOBALS['conf']['spam']['compare'] == 'numeric') {
+            /* here be dragons */
+        } elseif ($GLOBALS['conf']['spam']['compare'] == 'string') {
+            $spam_level = str_repeat($GLOBALS['conf']['spam']['char'],
+                                     $spam->getSpamLevel()+2);
+            $recipe->addCondition(array('match' => 'contains',
+                                        'field' => $GLOBALS['conf']['spam']['header'],
+                                        'value' => $spam_level));
+        }
+        $this->addItem($recipe);
+    }
+
 }
 
 /**
