From 34d022468cada8ad689854ec2a5b13f6ecd56c02 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Tue, 13 Nov 2012 20:32:58 +0100
Subject: [PATCH] - #1834860 by jazzslider, sun: Allow to accept 'unsure'
 posts as ham without CAPTCHA or further validation (binary
 mode).

---
 mollom.admin.inc                |  2 +-
 mollom.module                   |  3 +++
 tests/mollom.test               | 47 +++++++++++++++++++++++++++++++++++++++++
 tests/mollom_test_server.module | 11 ++++++++--
 4 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/mollom.admin.inc b/mollom.admin.inc
index 0d0eab0..8d54877 100644
--- a/mollom.admin.inc
+++ b/mollom.admin.inc
@@ -290,10 +290,10 @@ function mollom_admin_configure_form(&$form_state, $mollom_form = NULL) {
         '#type' => 'radios',
         '#title' => t('When text analysis is unsure'),
         '#default_value' => $mollom_form['unsure'],
-        // @todo Add 'accept' and 'discard' actions for unsure posts.
         '#options' => array(
           'captcha' => t('Show a CAPTCHA'),
           'moderate' => t('Retain the post for manual moderation'),
+          'binary' => t('Accept the post'),
         ),
         '#required' => $mollom_form['mode'] == MOLLOM_MODE_ANALYSIS,
       );
diff --git a/mollom.module b/mollom.module
index 9f00db0..6af48ed 100644
--- a/mollom.module
+++ b/mollom.module
@@ -1822,6 +1822,9 @@ function mollom_validate_analysis(&$form, &$form_state) {
   }
   $data['checks'] = $form_state['mollom']['checks'];
   $data['strictness'] = $form_state['mollom']['strictness'];
+  if (in_array('spam', $data['checks']) && $form_state['mollom']['unsure'] == 'binary') {
+    $data['unsure'] = 0;
+  }
   $result = $form_state['mollom']['class']->checkContent($data);
 
   // Use all available data properties for log messages below.
diff --git a/tests/mollom.test b/tests/mollom.test
index 1dedaaa..5597fda 100644
--- a/tests/mollom.test
+++ b/tests/mollom.test
@@ -3586,6 +3586,53 @@ class MollomAnalysisTestCase extends MollomWebTestCase {
   }
 
   /**
+   * Tests binary unsure mode.
+   */
+  function testUnsureBinary() {
+    $this->drupalLogin($this->admin_user);
+    $this->setProtection('mollom_test_form', MOLLOM_MODE_ANALYSIS, NULL, array(
+      'mollom[unsure]' => 'binary',
+    ));
+    $this->drupalLogout();
+
+    // Verify that an unsure post is ham.
+    // Note: The actual binary mode of Mollom's production API is more granular.
+    $edit = array(
+      'title' => $this->randomString(),
+      'body' => 'unsure',
+    );
+    $this->assertHamSubmit('mollom-test/form', array(), $edit, 'Submit');
+    $mid = $this->assertTestSubmitData();
+    $data = $this->assertMollomData('mollom_test', $mid);
+    $record = mollom_test_load($mid);
+    $this->assertEqual($record->status, 1, t('Published test post found.'));
+    $this->assertSame('spamScore', $data->spamScore, 0);
+    $this->assertSame('spamClassification', $data->spamClassification, 'ham');
+    $this->assertSame('moderate', $data->moderate, 0);
+
+    // Verify that a ham post is accepted.
+    $edit = array(
+      'title' => $this->randomString(),
+      'body' => 'ham',
+    );
+    $this->assertHamSubmit('mollom-test/form', array(), $edit, 'Submit');
+    $mid = $this->assertTestSubmitData();
+    $data = $this->assertMollomData('mollom_test', $mid);
+    $record = mollom_test_load($mid);
+    $this->assertEqual($record->status, 1, t('Published test post found.'));
+    $this->assertSame('spamScore', $data->spamScore, 0);
+    $this->assertSame('spamClassification', $data->spamClassification, 'ham');
+    $this->assertSame('moderate', $data->moderate, 0);
+
+    // Verify that a spam post is blocked.
+    $edit = array(
+      'title' => $this->randomString(),
+      'body' => 'spam',
+    );
+    $this->assertSpamSubmit('mollom-test/form', array(), $edit, 'Submit');
+  }
+
+  /**
    * Tests retaining unsure posts and moderating them.
    */
   function testRetainUnsure() {
diff --git a/tests/mollom_test_server.module b/tests/mollom_test_server.module
index ced6e75..4fe86c8 100644
--- a/tests/mollom_test_server.module
+++ b/tests/mollom_test_server.module
@@ -481,8 +481,15 @@ function mollom_test_server_check_content($data) {
     }
     // Lastly, take a forced 'unsure' into account.
     elseif (strpos($post, 'unsure') !== FALSE) {
-      $spam = TRUE;
-      $ham = TRUE;
+      // Differentiate between binary unsure mode.
+      if (!isset($data['unsure']) || $data['unsure']) {
+        $spam = TRUE;
+        $ham = TRUE;
+      }
+      else {
+        $spam = TRUE;
+        $ham = FALSE;
+      }
     }
     // Check blacklist.
     if ($matches = mollom_test_server_check_content_blacklist($post, $blacklist, 'spam')) {
-- 
1.7.11.msysgit.1

