diff --git a/mimemail.mail_edit.inc b/mimemail.mail_edit.inc
new file mode 100644
index 0000000..4b8f431
--- /dev/null
+++ b/mimemail.mail_edit.inc
@@ -0,0 +1,188 @@
+<?php
+
+/**
+ * @file
+ * Implementation of Mail Editor hooks for mimemail module.
+ * Currently just the mimemail rules are supported.
+ */
+
+/**
+ * Implements hook_mailkeys().
+ */
+function mimemail_mailkeys() {
+  $mail_keys = array();
+  // Currently just the rules implementation is supported.
+  if (module_exists('rules')) {
+    // Load all rules to detect mail actions.
+    $rules = rules_get_components(FALSE, 'action');
+    foreach ($rules as $rule) {
+      foreach ($rule as $element) {
+        if ($element instanceof RulesAction && in_array($element->getElementName(), array('mimemail', 'mimemail_to_users_of_role'))) {
+          // If this is an old rule build own key.
+          if (!isset($element->settings['key'])) {
+            // Build the unique key for this mail action.
+            $name = isset($element->root()->name) ? $element->root()->name : 'unnamed';
+            // The key depends on the name if the used action.
+            // @see rules_action_mimemail()
+            // @see rules_action_mimemail_to_users_of_role()
+            $key = 'rules_' . $element->getElementName() . $name . '_' . $element->elementId();
+          }
+          else {
+            $key = $element->settings['key'];
+          }
+
+          $mail_keys[$key] = t('Rule !root_label', array('!component_label' => $element->label(), '!root_label' => $element->root()->label()));
+        }
+      }
+    }
+  }
+  return $mail_keys;
+}
+
+/**
+ * Implements hook_mail_edit_text().
+ */
+function mimemail_mail_edit_text($mailkey, $language) {
+  $element = _mimemail_mail_edit_get_element_by_mailkey($mailkey);
+  // We need to check if the settings are set up as needed. We don't want to
+  // interfere with settings set by data selectors (:select).
+  $return = array(
+    'subject' => '',
+    'body' => '',
+    'data' => array('plaintext' => ''),
+  );
+  if (isset($element->settings['subject'])) {
+    $return['subject'] = $element->settings['subject'];
+  }
+  elseif (isset($element->settings['subject:select'])) {
+    // Warn user and hide form field.
+    drupal_set_message(t("The mail subject is set using a rules data selector and can't be altered here."), 'warning');
+    unset($return['subject']);
+  }
+
+  if (isset($element->settings['body'])) {
+    $return['body'] = $element->settings['body'];
+  }
+  elseif (isset($element->settings['body:select'])) {
+    // Warn user and hide form field.
+    drupal_set_message(t("The mail body is set using a rules data selector and can't be altered here."), 'warning');
+    unset($return['body']);
+  }
+
+  if (isset($element->settings['plaintext'])) {
+    $return['data']['plaintext'] = $element->settings['plaintext'];
+  }
+  elseif (isset($element->settings['plaintext:select'])) {
+    // Warn user and hide form field.
+    drupal_set_message(t("The mail plain text body is set using a rules data selector and can't be altered here."), 'warning');
+    unset($return['data']['plaintext']);
+  }
+  return $return;
+}
+
+/**
+ * Implements hook_mail_edit_mail_alter_postprocess().
+ */
+function mimemail_mail_edit_mail_alter_postprocess(&$message, $mailkey, $template, $data, $options) {
+  if (isset($template['data']['plaintext'])) {
+    // Preprocess and set the plaintext.
+    $message['params']['plaintext'] = mail_edit_format($template['data']['plaintext'], $data, $options);
+  }
+}
+
+/**
+ * Implements hook_mail_edit_format_preprocess().
+ */
+function mimemail_mail_edit_format_preprocess($text, $template, $data, &$options, $context) {
+  // Reuse rules integration.
+  rules_mail_edit_format_preprocess($text, $template, $data, $options, $context);
+}
+
+/**
+ * Implements hook_mail_edit_form_extra().
+ */
+function mimemail_mail_edit_form_extra(&$form, $form_state, $mailkey, $template) {
+  // Reuse rules integration to fetch the rules replacement tokens.
+  rules_mail_edit_form_extra($form, $form_state, $mailkey, $template);
+  // Add plaintext edit element if possible.
+  if (isset($template['data']['plaintext'])) {
+    $form['data']['plaintext'] = array(
+      '#title'         => t('Plain Text Body'),
+      '#type'          => 'textarea',
+      '#default_value' => $template['data']['plaintext'],
+      '#rows'          => 10,
+      '#description'   => t("The mail's message plaintext body."),
+    );
+  }
+}
+
+/**
+ * Implements hook_mail_edit_token_types().
+ */
+function mimemail_mail_edit_token_types($template_id) {
+  // Extract the prefix mimemail_ (9 chars) to get the mailkey only.
+  $mailkey = substr($template_id, 9);
+  $element = _mimemail_mail_edit_get_element_by_mailkey($mailkey);
+
+  // Ensure the rules token type mapping function is available.
+  module_load_include('inc', 'rules', 'modules/system.eval');
+
+  $token_types = array();
+  foreach ($element->availableVariables() as $var) {
+    $token_types[] = _rules_system_token_map_type($var['type']);
+  }
+  return $token_types;
+}
+
+/**
+ * Returns the rules element matching the mailkey.
+ *
+ * @param string $mailkey
+ *   The mailkey to parse.
+ *
+ * @return RulesAction
+ *   The rules actions element to use.
+ */
+function _mimemail_mail_edit_get_element_by_mailkey($mailkey) {
+  $elements = &drupal_static(__FUNCTION__);
+  if (!isset($elements[$mailkey])) {
+    // If this is an old rule build own key.
+    // Check what we've to ignore in the key to get the rules name.
+    $new_loader = TRUE;
+    if (strpos($mailkey, 'rules_mimemail_to_users_of_role_') === 0) {
+      $cleaning_length = 31;
+      $new_loader = FALSE;
+    }
+    elseif (strpos($mailkey, 'rules_mimemail_') === 0 && is_numeric(substr($mailkey, strrpos($mailkey, '_') + 1))) {
+      $cleaning_length = 22;
+      $new_loader = FALSE;
+    }
+    // Check how to load the related rule.
+    if ($new_loader) {
+      $query = new EntityFieldQuery('rules_config');
+      $rules = $query
+        ->entityCondition('entity_type', 'rules_config')
+        ->propertyCondition('data', '%' . db_like(':"' . $mailkey . '"') . '%', 'LIKE')
+        ->propertyCondition('plugin', '%' . db_like('rule') . '%', 'LIKE')
+        ->execute();
+      if (!empty($rules['rules_config'])) {
+        $rules_config_id = key($rules['rules_config']);
+        $rules_config = rules_config_load($rules_config_id);
+        foreach ($rules_config as $element) {
+          // Compare element type, element name and mailkey.
+          if ($element instanceof RulesAction && in_array($element->getElementName(), array('mimemail', 'mimemail_to_users_of_role')) && $element->settings['key'] == $mailkey) {
+            $elements[$mailkey] = $element;
+            break;
+          }
+        }
+      }
+    }
+    else {
+      // Extract the rules name.
+      $rules_name = substr($mailkey, $cleaning_length, strrpos($mailkey, '_') - $cleaning_length);
+      $element_id = substr($mailkey, strrpos($mailkey, '_') + 1);
+      $elements[$mailkey] = rules_element_load($element_id, $rules_name);
+    }
+  }
+  return $elements[$mailkey];
+}
