 .../mailhandler_default.feeds_importer_default.inc |    4 --
 .../mailhandler_extended/mailhandler_extended.info |    7 ++++
 .../mailhandler_extended.module                    |   12 +++++++
 .../MailhandlerCommandsExtendedHeaders.class.php   |   34 ++++++++++++++++++++
 .../MailhandlerCommandsExtendedHeaders.inc         |   16 +++++++++
 plugins/feeds/plugins/MailhandlerParser.class.php  |   33 ++++++-------------
 .../MailhandlerCommandsExtendedHeaders.class.php   |   34 --------------------
 .../MailhandlerCommandsExtendedHeaders.inc         |   16 ---------
 tests/mailhandler.test                             |    1 -
 9 files changed, 80 insertions(+), 77 deletions(-)

diff --git a/modules/mailhandler_default/mailhandler_default.feeds_importer_default.inc b/modules/mailhandler_default/mailhandler_default.feeds_importer_default.inc
index 7bf5943..5125e6a 100644
--- a/modules/mailhandler_default/mailhandler_default.feeds_importer_default.inc
+++ b/modules/mailhandler_default/mailhandler_default.feeds_importer_default.inc
@@ -28,10 +28,6 @@ function mailhandler_default_feeds_importer_default() {
       'config' => array(
         'default_commands' => 'status: 1',
         'commands_failed_auth' => 'status: 0',
-        'command_plugin' => array(
-          'MailhandlerCommandsDefault' => 'MailhandlerCommandsDefault',
-          'MailhandlerCommandsHeaders' => 'MailhandlerCommandsHeaders',
-        ),
         'authenticate_plugin' => 'MailhandlerAuthenticateDefault',
         'available_commands' => 'status',
       ),
diff --git a/modules/mailhandler_extended/mailhandler_extended.info b/modules/mailhandler_extended/mailhandler_extended.info
new file mode 100644
index 0000000..437d01b
--- /dev/null
+++ b/modules/mailhandler_extended/mailhandler_extended.info
@@ -0,0 +1,7 @@
+name = Mailhandler Extended Headers
+description = Allows arbitrary headers to be mapped in Mailhandler
+core = 7.x
+dependencies[] = "mailhandler"
+package = "Mailhandler extras"
+
+files[] = plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.class.php
diff --git a/modules/mailhandler_extended/mailhandler_extended.module b/modules/mailhandler_extended/mailhandler_extended.module
new file mode 100644
index 0000000..a850786
--- /dev/null
+++ b/modules/mailhandler_extended/mailhandler_extended.module
@@ -0,0 +1,12 @@
+<?php
+/**
+ * @file
+ * Adds extended headers to Mailhandler.
+ */
+
+/**
+ * Implements hook_ctools_plugin_directory().
+ */
+function mailhandler_extended_ctools_plugin_directory($owner, $plugin_type) {
+  return 'plugins/' . $owner . '/' . $plugin_type;
+}
diff --git a/modules/mailhandler_extended/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.class.php b/modules/mailhandler_extended/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.class.php
new file mode 100644
index 0000000..26aeb01
--- /dev/null
+++ b/modules/mailhandler_extended/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.class.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * @file
+ * MailhandlerCommandsExtendedHeaders class.
+ */
+
+class MailhandlerCommandsExtendedHeaders extends MailhandlerCommandsHeaders {
+
+  /**
+   * Build configuration form.
+   */
+  public function configForm(&$form, &$form_state, $config) {
+    $form['extended_headers'] = array(
+      '#type' => 'textarea',
+      '#title' => t('Extended headers'),
+      '#description' => t('Additional headers that can be mapped to Feeds processor targets.'),
+      '#default_value' => $config['extended_headers'],
+    );
+  }
+
+  function getMappingSources($config) {
+    $sources = array();
+    $extended_headers = explode("\n", $config['extended_headers']);
+    foreach ($extended_headers as $header) {
+      $header = trim($header);
+      $sources[$header] = array(
+        'name' => $header,
+        'description' => $header . ' (extended header)',
+      );
+    }
+    return $sources;
+  }
+
+}
diff --git a/modules/mailhandler_extended/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.inc b/modules/mailhandler_extended/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.inc
new file mode 100644
index 0000000..65cf723
--- /dev/null
+++ b/modules/mailhandler_extended/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.inc
@@ -0,0 +1,16 @@
+<?php
+/**
+ * @file
+ * MailhandlerCommandsExtendedHeaders class.
+ */
+
+$plugin = array(
+  'name' => 'Extended headers processor',
+  'description' => 'Provides arbitrary IMAP headers as mapping sources.',
+  'handler' => array(
+    'class' => 'MailhandlerCommandsExtendedHeaders',
+    'parent' => 'MailhandlerCommandsHeaders',
+  ),
+  'file' => 'MailhandlerCommandsExtendedHeaders.class.php',
+  'weight' => 0,
+);
diff --git a/plugins/feeds/plugins/MailhandlerParser.class.php b/plugins/feeds/plugins/MailhandlerParser.class.php
index c5c8d57..2cc250a 100644
--- a/plugins/feeds/plugins/MailhandlerParser.class.php
+++ b/plugins/feeds/plugins/MailhandlerParser.class.php
@@ -17,7 +17,6 @@ class MailhandlerParser extends FeedsParser {
       'default_commands' => 'status: 1',
       'commands_failed_auth' => 'status: 0',
       'available_commands' => 'status',
-      'command_plugin' => array('MailhandlerCommandsDefault', 'MailhandlerCommandsFiles', 'MailhandlerCommandsHeaders'),
       'authenticate_plugin' => 'MailhandlerAuthenticateDefault',
     );
   }
@@ -38,14 +37,6 @@ class MailhandlerParser extends FeedsParser {
   public function configForm(&$form_state) {
     $form = array();
     ctools_include('plugins');
-    $form['command_plugin'] = array(
-      '#type' => 'select',
-      '#title' => t('Command plugins'),
-      '#description' => t('Choose the command plugins to use'),
-      '#options' => _mailhandler_build_options(mailhandler_get_plugins('mailhandler', 'commands')),
-      '#multiple' => TRUE,
-      '#default_value' => $this->config['command_plugin'],
-    );
     $form['authenticate_plugin'] = array(
       '#type' => 'select',
       '#title' => t('Authentication plugin'),
@@ -54,11 +45,10 @@ class MailhandlerParser extends FeedsParser {
       '#default_value' => $this->config['authenticate_plugin'],
       '#required' => FALSE,
     );
-    if (($plugins = $this->config['command_plugin']) && is_array($plugins) && !empty($plugins)) {
-      foreach ($plugins as $plugin) {
-        if ($class = mailhandler_plugin_load_class('mailhandler', $plugin, 'commands', 'handler')) {
-          $class->configForm($form, $form_state, $this->config);
-        }
+    $plugins = mailhandler_get_plugins('mailhandler', 'commands');
+    foreach ($plugins as $plugin_name => $plugin) {
+      if ($class = mailhandler_plugin_load_class('mailhandler', $plugin_name, 'commands', 'handler')) {
+        $class->configForm($form, $form_state, $this->config);
       }
     }
     return $form;
@@ -101,8 +91,8 @@ class MailhandlerParser extends FeedsParser {
       'name' => t('User ID'),
       'description' => t('The authenticated Drupal user ID'),
     );
-    $plugins = $this->config['command_plugin'];
-    foreach ($plugins as $plugin_name) {
+    $plugins = mailhandler_get_plugins('mailhandler', 'commands');
+    foreach ($plugins as $plugin_name => $plugin) {
       $plugin = mailhandler_plugin_load_class('mailhandler', $plugin_name, 'commands', 'handler');
       $sources = array_merge($sources, $plugin->getMappingSources($this->config));
     }
@@ -113,12 +103,11 @@ class MailhandlerParser extends FeedsParser {
    * Parse and apply commands.
    */
   public function commands(&$message, $source) {
-    if (($plugins = $this->config['command_plugin']) && is_array($plugins) && !empty($plugins)) {
-      foreach ($plugins as $plugin) {
-        if ($class = mailhandler_plugin_load_class('mailhandler', $plugin, 'commands', 'handler')) {
-          $class->parse($message, $source);
-          $class->process($message, $source);
-        }
+    $plugins = mailhandler_get_plugins('mailhandler', 'commands');
+    foreach ($plugins as $plugin_name => $plugin) {
+      if ($class = mailhandler_plugin_load_class('mailhandler', $plugin_name, 'commands', 'handler')) {
+        $class->parse($message, $source);
+        $class->process($message, $source);
       }
     }
   }
diff --git a/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.class.php b/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.class.php
deleted file mode 100644
index 26aeb01..0000000
--- a/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.class.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
- * @file
- * MailhandlerCommandsExtendedHeaders class.
- */
-
-class MailhandlerCommandsExtendedHeaders extends MailhandlerCommandsHeaders {
-
-  /**
-   * Build configuration form.
-   */
-  public function configForm(&$form, &$form_state, $config) {
-    $form['extended_headers'] = array(
-      '#type' => 'textarea',
-      '#title' => t('Extended headers'),
-      '#description' => t('Additional headers that can be mapped to Feeds processor targets.'),
-      '#default_value' => $config['extended_headers'],
-    );
-  }
-
-  function getMappingSources($config) {
-    $sources = array();
-    $extended_headers = explode("\n", $config['extended_headers']);
-    foreach ($extended_headers as $header) {
-      $header = trim($header);
-      $sources[$header] = array(
-        'name' => $header,
-        'description' => $header . ' (extended header)',
-      );
-    }
-    return $sources;
-  }
-
-}
diff --git a/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.inc b/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.inc
deleted file mode 100644
index 65cf723..0000000
--- a/plugins/mailhandler/commands/MailhandlerCommandsExtendedHeaders.inc
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-/**
- * @file
- * MailhandlerCommandsExtendedHeaders class.
- */
-
-$plugin = array(
-  'name' => 'Extended headers processor',
-  'description' => 'Provides arbitrary IMAP headers as mapping sources.',
-  'handler' => array(
-    'class' => 'MailhandlerCommandsExtendedHeaders',
-    'parent' => 'MailhandlerCommandsHeaders',
-  ),
-  'file' => 'MailhandlerCommandsExtendedHeaders.class.php',
-  'weight' => 0,
-);
diff --git a/tests/mailhandler.test b/tests/mailhandler.test
index c95bbaf..3bebfa0 100644
--- a/tests/mailhandler.test
+++ b/tests/mailhandler.test
@@ -93,7 +93,6 @@ class MailhandlerTestCase extends DrupalWebTestCase {
     // Override Mailhandler Default importer, map taxonomy and files.
     $this->drupalGet('admin/structure/feeds/edit/mailhandler_nodes/settings/MailhandlerParser');
     $edit = array();
-    $edit['command_plugin[]'] = array('MailhandlerCommandsHeaders', 'MailhandlerCommandsDefault', 'MailhandlerCommandsFiles');
     $edit['available_commands'] = 'status' . "\n" . 'taxonomy';
     $this->drupalPost(NULL, $edit, t('Save'));
     $this->drupalGet('admin/structure/feeds/edit/mailhandler_nodes/mapping');
