Index: mailhandler/mailhandler_fromaliasauthentication.module
===================================================================
--- mailhandler/mailhandler_fromaliasauthentication.module	(revision 0)
+++ mailhandler/mailhandler_fromaliasauthentication.module	(revision 1010)
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Determine who is the author of the upcoming node.
+ */
+function mailhandler_authenticate($node, $header, $origbody, $mailbox) {
+
+  // $fromaddress really refers to the mail header which is authoritative for authentication
+  list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox);
+  if ($from_user = mailhandler_user_load($fromaddress, $node->pass, $mailbox)) {
+    $node->uid = $from_user->uid; // success!
+    $node->name = $from_user->name;
+  }
+  else {
+    $result = db_query("SELECT mail FROM {users} WHERE data LIKE '%%%s%%'", $fromaddress);
+    while ($alias = db_result($result)) {
+      if ($from_user = mailhandler_user_load($alias, $node->pass, $mailbox)) {
+        $node->uid = $from_user->uid; // success!
+        $node->name = $from_user->name;
+        break;
+      }
+    }
+  }
+  if (!$from_user) {
+    // failed authentication. we will still try to submit anonymously.
+    $node->uid = 0;
+    $node->name = $fromname; // use the name supplied in email headers
+  }
+  return $node;
+}
Index: mailhandler/mailhandler_fromaliasauthentication.info
===================================================================
--- mailhandler/mailhandler_fromaliasauthentication.info	(revision 0)
+++ mailhandler/mailhandler_fromaliasauthentication.info	(revision 1010)
@@ -0,0 +1,6 @@
+; $Id $
+name = Mailhandler From Alias Authentication
+description = Authenticates users' emails using the From: address, possibly aliased
+core = 6.x
+dependencies[] = mailhandler
+dependencies[] = mailalias
\ No newline at end of file
Index: mailhandler/mailhandler_fromauthentication.module
===================================================================
--- mailhandler/mailhandler_fromauthentication.module	(revision 0)
+++ mailhandler/mailhandler_fromauthentication.module	(revision 1010)
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Determine who is the author of the upcoming node.
+ */
+function mailhandler_authenticate($node, $header, $origbody, $mailbox) {
+
+  // $fromaddress really refers to the mail header which is authoritative for authentication
+  list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox);
+  if ($from_user = mailhandler_user_load($fromaddress, $node->pass, $mailbox)) {
+    $node->uid = $from_user->uid; // success!
+    $node->name = $from_user->name;
+  }
+  else {
+    // failed authentication. we will still try to submit anonymously.
+    $node->uid = 0;
+    $node->name = $fromname; // use the name supplied in email headers
+  }
+  return $node;
+}
Index: mailhandler/mailhandler.retrieve.inc
===================================================================
--- mailhandler/mailhandler.retrieve.inc	(revision 1009)
+++ mailhandler/mailhandler.retrieve.inc	(revision 1010)
@@ -360,30 +360,14 @@
 /**
  * Determine who is the author of the upcoming node.
  */
-function mailhandler_authenticate($node, $header, $origbody, $mailbox) {
-
-  // $fromaddress really refers to the mail header which is authoritative for authentication
-  list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox);
-  if ($from_user = mailhandler_user_load($fromaddress, $node->pass, $mailbox)) {
-    $node->uid = $from_user->uid; // success!
-    $node->name = $from_user->name;
-  }
-  else if (function_exists('mailalias_user')) { // since $fromaddress failed, try e-mail aliases
-    $result = db_query("SELECT mail FROM {users} WHERE data LIKE '%%%s%%'", $fromaddress);
-    while ($alias = db_result($result)) {
-      if ($from_user = mailhandler_user_load($alias, $node->pass, $mailbox)) {
-        $node->uid = $from_user->uid; // success!
-        $node->name = $from_user->name;
-        break;
-      }
-    }
-  }
-  if (!$from_user) {
-    // failed authentication. we will still try to submit anonymously.
-    $node->uid = 0;
-    $node->name = $fromname; // use the name supplied in email headers
-  }
-  return $node;
+function _mailhandler_authenticate($node, $header, $origbody, $mailbox) {
+  $function = 'mailhandler_authenticate';
+  if (!function_exists($function)) {
+	watchdog("mailhandler","No module implements mailhandler_authenticate(), you need to activate one");
+	return FALSE;
+  } else {
+	return  $function($node, $header, $origbody, $mailbox); 	
+  }
 }
 
 
@@ -651,45 +635,50 @@
       $node = mailhandler_process_message($header, $origbody, $mailbox);
 
       // check if mail originates from an authenticated user
-      $node = mailhandler_authenticate($node, $header, $origbody, $mailbox);
-
-      // Put $mimeparts on the node
-      $node->mimeparts = $mimeparts;
-
-      // we need to change the current user
-      // this has to be done here to allow modules
-      // to create users
-      mailhandler_switch_user($node->uid);
-
-      // modules may override node elements before submitting. they do so by returning the node.
-      foreach (module_list() as $name) {
-        if (module_hook($name, 'mailhandler')) {
-          $function = $name .'_mailhandler';
-          if (!($node = $function($node, $result, $i, $header, $mailbox))) {
-            // Exit if a module has handled the submitted data.
-            break;
-          }
-        }
+      $node = _mailhandler_authenticate($node, $header, $origbody, $mailbox);
+
+      if (!$node) {
+      	// could not authenticate the user because of module configuration issue => ignore that email
+      	// but do not delete it
+      } else {
+	      // Put $mimeparts on the node
+	      $node->mimeparts = $mimeparts;
+	
+	      // we need to change the current user
+	      // this has to be done here to allow modules
+	      // to create users
+	      mailhandler_switch_user($node->uid);
+	
+	      // modules may override node elements before submitting. they do so by returning the node.
+	      foreach (module_list() as $name) {
+	        if (module_hook($name, 'mailhandler')) {
+	          $function = $name .'_mailhandler';
+	          if (!($node = $function($node, $result, $i, $header, $mailbox))) {
+	            // Exit if a module has handled the submitted data.
+	            break;
+	          }
+	        }
+	      }
+	
+	      if ($node) {
+	        if ($node->type == 'comment') {
+	          mailhandler_comment_submit($node, $header, $mailbox, $origbody);
+	        }
+	        else {
+	          mailhandler_node_submit($node, $header, $mailbox, $origbody);
+	        }
+	      }
+      
+	      // don't delete while we're only getting new messages
+	      if ($mailbox['delete_after_read']) {
+	        imap_delete($result, $i, FT_UID);
+	      }
       }
-
-      if ($node) {
-        if ($node->type == 'comment') {
-          mailhandler_comment_submit($node, $header, $mailbox, $origbody);
-        }
-        else {
-          mailhandler_node_submit($node, $header, $mailbox, $origbody);
-        }
-      }
-      // don't delete while we're only getting new messages
-      if ($mailbox['delete_after_read']) {
-        imap_delete($result, $i, FT_UID);
-      }
-
       // switch back to original user
       mailhandler_switch_user();
 
       // Put something in the results array for the counter in the batch finished callback
-      $context['results'][] = $mailbox['mail'];
+      $context['results'][] = $mailbox['mail'];
     }
 
     imap_close($result, CL_EXPUNGE);
Index: mailhandler/mailhandler_fromauthentication.info
===================================================================
--- mailhandler/mailhandler_fromauthentication.info	(revision 0)
+++ mailhandler/mailhandler_fromauthentication.info	(revision 1010)
@@ -0,0 +1,5 @@
+; $Id $
+name = Mailhandler From Authentication
+description = Authenticates users' emails using the From: address (default for mailhandler)
+core = 6.x
+dependencies[] = mailhandler
