Index: site/sites/all/modules/mollom/mollom.module
===================================================================
--- site/sites/all/modules/mollom/mollom.module	(revision 1703)
+++ site/sites/all/modules/mollom/mollom.module	(working copy)
@@ -270,7 +270,8 @@
  * by the contact module.
  */
 function mollom_mail_alter(&$message) {
-  if (isset($GLOBALS['mollom_response']) && isset($GLOBALS['mollom_response']['session_id'])) {
+  // Hack: $message['body'] is sometimes a string? So ignore it then.
+  if (isset($GLOBALS['mollom_response']) && isset($GLOBALS['mollom_response']['session_id']) && is_array($message['body'])) {
     $message['body'][] = t('Report as inappropriate: @link', array('@link' => url('mollom/contact/'. $GLOBALS['mollom_response']['session_id'], array('absolute' => TRUE))));
   }
 }
@@ -546,6 +547,11 @@
  * analysis with smart CAPTCHA support).
  */
 function _mollom_get_mode($form_id) {
+  $ret = module_invoke_all('mollom_form', $form_id);
+  if (isset($ret['mode'])) {
+  	return $ret['mode'];
+  }
+  
   if (variable_get('mollom_'. $form_id, MOLLOM_MODE_DISABLED)) {
     $forms = _mollom_protectable_forms();
     return $forms[$form_id]['mode'];
@@ -748,22 +754,21 @@
 
   _mollom_debug("mollom_validate_analysis for '". $form_state['values']['form_id'] ."'");
 
-  $data = array();
-
   $form_id = $form_state['values']['form_id'];
 
-  $pos = strpos($form_id, '_node_form');
-  if ($pos !== FALSE) {
-    // The node forms use dynamic form IDs so we had to create a special
-    // case for these.
-    $data = mollom_data_node_form($form_state['values']);
+  $data = module_invoke_all('mollom_data', $form, $form_state, $form_id);
+  if (count($data) == 0) {
+	if (strpos($form_id, '_node_form') !== FALSE) {
+		// The node forms use dynamic form IDs so we had to create a special
+		// case for these.
+		$data = mollom_data_node_form($form_state['values']);
+	} else {
+		$function = 'mollom_data_'. $form_id;
+		if (function_exists($function)) {
+		$data = $function($form_state['values']);
+		}
+	}
   }
-  else {
-    $function = 'mollom_data_'. $form_id;
-    if (function_exists($function)) {
-      $data = $function($form_state['values']);
-    }
-  }
 
   if (isset($form_state['values']['op'])) {
     $mollom = isset($form_state['values']['session_id']) ? array('session_id' => $form_state['values']['session_id']) : array();
@@ -899,6 +904,18 @@
   }
 }
 
+/** What operation is being done? Valid results are 'preview' or 'submit' */
+function _mollom_form_op($form_id, &$form_state) {
+  $ret = module_invoke_all('mollom_form_op', $form_id, $form_state);
+  if (isset($ret['op'])) {
+    return $ret['op'];
+  } elseif ($form_state['clicked_button']['#value'] == t('Preview')) {
+    return 'preview';
+  } else {
+    return 'submit';
+  }
+}
+
 /**
  * This is a helper function that registers the form data so that on
  * the next page, we can insert the CAPTCHA on the form.  We store
@@ -918,7 +935,7 @@
   $form_state['mollom']['captcha'] = $captcha;  // Whether to add or remove the CAPTCHA ...
 
   $mode = _mollom_get_mode($form_id);
-  if ($mode == MOLLOM_MODE_ANALYSIS) {
+  if ($mode == MOLLOM_MODE_ANALYSIS && ($captcha || _mollom_form_op($form_id, $form_state) == 'preview')) {
     $form_state['rebuild'] = TRUE;
   }
 }
