? .svn
? mailhandler_node/.svn
? mailhandler_node/plugins/.svn
? plugins/.svn
? plugins/export_ui/.svn
? translations/.svn
Index: mailhandler.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/Attic/mailhandler.module,v
retrieving revision 1.96.2.3.2.5
diff -u -p -r1.96.2.3.2.5 mailhandler.module
--- mailhandler.module	21 Oct 2010 13:00:03 -0000	1.96.2.3.2.5
+++ mailhandler.module	22 Oct 2010 15:03:02 -0000
@@ -385,4 +385,4 @@ function mailhandler_mailbox_toggle_type
     drupal_set_message(t('%type is now the active mailbox type.', array('%type' => $title)));
     drupal_goto(drupal_get_destination());
   }
-}
\ No newline at end of file
+}
Index: mailhandler_node/plugins/MailhandlerNodeAuthenticate.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/mailhandler_node/plugins/Attic/MailhandlerNodeAuthenticate.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 MailhandlerNodeAuthenticate.inc
--- mailhandler_node/plugins/MailhandlerNodeAuthenticate.inc	21 Oct 2010 13:00:03 -0000	1.1.2.2
+++ mailhandler_node/plugins/MailhandlerNodeAuthenticate.inc	22 Oct 2010 15:03:02 -0000
@@ -10,6 +10,6 @@ abstract class MailhandlerNodeAuthentica
    * @param $node
    *   A node object.  May 
    */
-  abstract public function authenticate($mailbox, &$message);
+  abstract public function authenticate($value, &$target_node);
   
 }
\ No newline at end of file
Index: mailhandler_node/plugins/MailhandlerNodeAuthenticateDefault.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/mailhandler_node/plugins/Attic/MailhandlerNodeAuthenticateDefault.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 MailhandlerNodeAuthenticateDefault.inc
--- mailhandler_node/plugins/MailhandlerNodeAuthenticateDefault.inc	21 Oct 2010 13:00:03 -0000	1.1.2.2
+++ mailhandler_node/plugins/MailhandlerNodeAuthenticateDefault.inc	22 Oct 2010 15:03:02 -0000
@@ -2,18 +2,18 @@
   
 class MailhandlerNodeAuthenticateDefault extends MailhandlerNodeAuthenticate {
   
-  public function authenticate($mailbox, &$message) {
-    list($fromaddress, $fromname) = mailhandler_get_fromaddress($message['header'], $message['mailbox']);
-    if ($from_user = user_load(array('mail' => $mail))) {
-      $message['uid'] = $from_user->uid;
+  public function authenticate($value, &$target_node) {
+    list($fromaddress, $fromname) = mailhandler_get_fromaddress($value['message']['header'], $value['mailbox']);
+    if ($from_user = user_load(array('mail' => $fromaddress))) {
+      $target_node->uid = $from_user->uid;
     }
     // Try using mailalias email aliases
     else if (function_exists('mailalias_user') && $from_user = mailhandler_user_load_alias($fromaddress)) {
-      $message['uid'] = $from_user->uid;
+      $target_node->uid = $from_user->uid;
     }
     else {
       // Authentication failed.  Try as anonymous.
-      $message['uid'] = 0;
+      $target_node->uid = 0;
     }
   }
 
Index: mailhandler_node/plugins/MailhandlerNodeAuthenticateTokenauth.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/mailhandler_node/plugins/Attic/MailhandlerNodeAuthenticateTokenauth.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 MailhandlerNodeAuthenticateTokenauth.inc
--- mailhandler_node/plugins/MailhandlerNodeAuthenticateTokenauth.inc	21 Oct 2010 13:00:03 -0000	1.1.2.2
+++ mailhandler_node/plugins/MailhandlerNodeAuthenticateTokenauth.inc	22 Oct 2010 15:03:03 -0000
@@ -17,25 +17,22 @@
  */
 class MailhandlerNodeAuthenticateTokenauth extends MailhandlerNodeAuthenticate {
   
-  public function authenticate($item, &$object) {
+  public function authenticate($value, &$target_node) {
     if (module_exists('tokenauth')) {
-      list($fromaddress, $fromname) = mailhandler_get_fromaddress($item['header'], $item['mailbox']);
+      list($fromaddress, $fromname) = mailhandler_get_fromaddress($value['message']['header'], $value['mailbox']);
       // If user with given email address exists and their token is in the toaddress, allow.
       if (($from_user = user_load(array('mail' => $fromaddress)))
       && strpos($header->to[0]->mailbox, tokenauth_get_token($from_user->uid)) !== FALSE) {
-        $object->uid = $from_user->uid;
-        $object->name = $from_user->name;
+        $target_node->uid = $from_user->uid;
       }
       // Try using mailalias email aliases
-      else if (function_exists('mailalias_user') && ($from_user = mailhandler_user_load_alias($fromaddress, $object, $item['mailbox']'))
+      else if (function_exists('mailalias_user') && ($from_user = mailhandler_user_load_alias($fromaddress, $target_node, $item['mailbox']'))
       && strpos($header->to[0]->mailbox, tokenauth_get_token($from_user->uid)) !== FALSE) {
-        $object->uid = $from_user->uid;
-        $object->name = $from_user->name;
+        $target_node->uid = $from_user->uid;
       }
       else {
         // If token authentication fails, try as anonymous.
-        $object->uid = 0;
-        $object->name = $fromname;
+        $target_node->uid = 0;
       }
     }
   }
Index: mailhandler_node/plugins/MailhandlerNodeMailbox.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/mailhandler_node/plugins/Attic/MailhandlerNodeMailbox.inc,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 MailhandlerNodeMailbox.inc
--- mailhandler_node/plugins/MailhandlerNodeMailbox.inc	15 Aug 2010 21:45:32 -0000	1.1.2.3
+++ mailhandler_node/plugins/MailhandlerNodeMailbox.inc	22 Oct 2010 15:03:03 -0000
@@ -2,6 +2,35 @@
 
 class MailhandlerNodeMailbox extends MailhandlerMailbox {
   
+  public $security = 0;
+  public $replies = 0;
+  public $sigseparator = '';
+  public $commands;
+  public $commandplugin = '';
+  public $authenticateplugin = '';
+
+  /**
+   * Constructor
+   */
+  function __construct($mailbox = FALSE) {
+    parent::__construct($mailbox);
+    // TODO not sure how PHP 5.3 will treat get_class where I'm calling the 
+    // class name below explicitly.
+    
+    // Fetch settings from database, propagate object.
+    if ($mailbox) {
+      $this->settings = $mailbox->settings;
+      $this->mail = $mailbox->mail;
+      $this->mailbox_type = $mailbox->mailbox_type;
+      $this->security = $mailbox->settings['MailhandlerNodeMailbox']['security'];
+      $this->replies = $mailbox->settings['MailhandlerNodeMailbox']['replies'];
+      $this->sigseparator = $mailbox->settings['MailhandlerNodeMailbox']['sigseparator'];
+      $this->commands = $mailbox->settings['MailhandlerNodeMailbox']['commands'];
+      $this->commandplugin = $mailbox->settings['MailhandlerNodeMailbox']['commandplugin'];
+      $this->authenticateplugin = $mailbox->settings['MailhandlerNodeMailbox']['authenticateplugin'];
+    }
+  }
+  
   private function setInfo() {
     return array(
       'title' => 'Node Mailbox',
@@ -78,4 +107,4 @@ class MailhandlerNodeMailbox extends Mai
     // @TODO - validation.
   }
 
-}
\ No newline at end of file
+}
Index: mailhandler_node/plugins/MailhandlerNodeProcessor.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/mailhandler_node/plugins/Attic/MailhandlerNodeProcessor.inc,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 MailhandlerNodeProcessor.inc
--- mailhandler_node/plugins/MailhandlerNodeProcessor.inc	21 Oct 2010 13:00:03 -0000	1.1.2.4
+++ mailhandler_node/plugins/MailhandlerNodeProcessor.inc	22 Oct 2010 15:03:03 -0000
@@ -1,7 +1,43 @@
 <?php
 
 class MailhandlerNodeProcessor extends FeedsNodeProcessor {
-    
+
+  /**
+   * Override parent::configDefaults().
+   */
+  public function configDefaults() {
+    $defaults = parent::configDefaults();
+    $defaults['authenticate'] = FALSE;
+    $defaults['if_auth_fails'] = 'remove';
+    return $defaults;
+  }
+
+  /**
+   * Override parent::configForm().
+   */
+  public function configForm(&$form_state) {
+    $form = parent::configForm($form_state);
+    $form['authenticate'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Authenticate users'),
+      '#default_value' => $this->config['authenticate'],
+      '#description' => t("If checked, Mailhandler will check that the sender can create the post 
+      using the authentication plugin defined in the Mailbox settings. <strong>Be sure to include
+      'Authenticate' as source and target in the mapper settings.</strong>"),
+    );
+    $form['if_auth_fails'] = array(
+      '#type' => 'select',
+      '#title' => t('If authentication fails'),
+      '#options' => array(
+        'remove' => t('Do not create the node'),
+        'unpublish' => t('Create the node, leave it unpublished'),
+      ),
+      '#default_value' => $this->config['if_auth_fails'],
+      '#description' => t('If authentication is checked, here you can choose what to do if the incoming emails does not belongs to an authenticated user.'),
+    );
+    return $form;
+  }
+
   /**
    * Override setTargetElement
    */
@@ -10,16 +46,34 @@ class MailhandlerNodeProcessor extends F
       if (in_array($target_element, array('references', 'in_reply_to'))) {
         $target_node->mailhandler_node->$target_element = $value;
       }
-      // @TODO won't work.  gets overwritten in buildNode, first by
-      // node_object_prepare, then by $this->config['author'];
-      elseif (in_array($target_element, array('uid'))) {
-        $target_node->$target_element = $value;
-      }
       // Process commands
       elseif ($target_element == 'commands') {
         // $value is array with mailbox and message arrays.
         $this->commands($value, $target_node);
       }
+      // Apply uid based on authentication plugin
+      elseif ($target_element == 'authenticate' && $this->config['authenticate']) {
+        // $value is array with mailbox and message arrays.
+        $this->authenticate($value, $target_node);
+
+        // Check access
+        if (!$account = user_load($target_node->uid)) {
+          $account = drupal_anonymous_user();
+        }
+        if (!node_access('create', $target_node, $account)) {
+          if ($this->config['if_auth_fails'] == 'unpublish') {
+            $target_node->status = 0;
+          }
+          elseif ($this->config['if_auth_fails'] == 'remove') {
+            list($fromaddress, $fromname) = mailhandler_get_fromaddress($value['message']['header'], $value['mailbox']);
+            // FeedsNodeProcessor::process checks for an exception to cancel the creation of the node
+            throw new Exception(t('User: @name (@mail) cannot create @node_type nodes.', array('@node_type' => $target_node->type, '@name' => $fromname, '@mail' => $fromaddress)));
+          }
+        }
+        else {
+          $this->config['author'] = $account->uid;
+        }
+      }
   }
   
   /*
@@ -35,6 +89,18 @@ class MailhandlerNodeProcessor extends F
       }
     }
   }
+  
+  /*
+   * Authenticate the message and set $message->uid.
+   */
+  public function authenticate($value, &$target_node) {
+    // TODO: allow for multiple authenticate plugins to be weighted and implemented.
+    if (($plugin = $value['mailbox']->getSettings('authenticateplugin', $value['mailbox']))) {
+      if ($class = mailhandler_plugin_load_class('mailhandler_node', $plugin, 'authenticate_plugin', 'handler')) {
+        $class->authenticate($value, &$target_node);
+      }
+    }
+  }
 
 }
 
@@ -61,6 +127,10 @@ function mailhandler_node_feeds_node_pro
     'name' => t('Commands'),
     'description' => t('Map commands in order to run the mailbox command processor.'),
   );
+  $targets['authenticate'] = array(
+    'name' => t('Authenticate'),
+    'description' => t('Run authentication plugin on incoming messages.'),
+  );
 }
 
 /*
@@ -86,4 +156,4 @@ function _mailhandler_node_processor_tar
   // the mail is from.  Again, don't have needed info in this scope.
   // To deal w/ scope issues, could stuff something onto $node->mailhandler.
   $target_node->$target_element = $body;
-}
\ No newline at end of file
+}
Index: plugins/MailhandlerParser.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailhandler/plugins/Attic/MailhandlerParser.inc,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 MailhandlerParser.inc
--- plugins/MailhandlerParser.inc	22 Oct 2010 05:05:23 -0000	1.1.2.3
+++ plugins/MailhandlerParser.inc	22 Oct 2010 15:03:04 -0000
@@ -20,15 +20,12 @@ class MailhandlerParser extends FeedsPar
         foreach ($messages as &$message) {
           $this->parseAttachments($message);
           $this->parseExtensions($message);
-          // Outcome is to set $message->uid
-          // @TODO this will get overwritten by the FeedsNodeProcessor
-          $this->authenticate($fetched['mailbox'], $message);
           // Put mailbox and message into commands $value, which will make these 
           // available when map() is called.  mailbox contains information about 
           // which command plugin to use.  message is needed because it contains
           // the message body, from which commands are parsed and added to the
           // $this->commands property.
-          $message['commands'] = array('mailbox' => $fetched['mailbox'], 'message' => $message);
+          $message['commands'] = $message['authenticate'] = array('mailbox' => $fetched['mailbox'], 'message' => $message);
         }
         $batch->setItems($messages);
       }
@@ -92,19 +89,12 @@ class MailhandlerParser extends FeedsPar
       'title' => t('Commands'),
       'description' => t('Mailhandler commands'),
     );
+    $sources['authenticate'] = array(
+      'title' => t('Authenticate'),
+      'description' => t('Should be mapped to Authenticate target in order to run
+      authentication plugin.'),
+    );
     return $sources;
   }
-  
-  /*
-   * Authenticate the message and set $message->uid.
-   */
-  public function authenticate($mailbox, &$message) {
-    // TODO: allow for multiple authenticate plugins to be weighted and implemented.
-    if (($plugin = $mailbox->getSettings('authenticateplugin', $mailbox))) {
-      if ($class = mailhandler_plugin_load_class('mailhandler_node', $plugin, 'authenticate_plugin', 'handler')) {
-        $class->authenticate($mailbox, &$message);
-      }
-    }
-  }
 
 }
