diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 58c1017..759f6c9 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,7 @@
 
-Views Send x.x-x.x, xxxx-xx-xx
+Views Send 7.x-1.x, xxxx-xx-xx
 ------------------------------
+Initial ugly port to Drupal 7, by hansfn
 
 Views Send 6.x-1.x, xxxx-xx-xx
 ------------------------------
diff --git a/views_send.cron.inc b/views_send.cron.inc
index c4681c7..6fc759c 100644
--- a/views_send.cron.inc
+++ b/views_send.cron.inc
@@ -21,22 +21,21 @@ function views_send_send_from_spool() {
   timer_start('views_send');
 
   // Retrieve messages to be send.
-  $query = "SELECT * FROM {views_send_spool} WHERE status = %d ORDER BY tentatives ASC, timestamp ASC";
-  $result = $limit ? db_query_range($query, 0, 0, $limit) : db_query($query, 0);
-  while ($message = db_fetch_object($result)) {
-
+  $query = "SELECT * FROM {views_send_spool} WHERE status = :status ORDER BY tentatives ASC, timestamp ASC";
+  $result = $limit ? db_query_range($query, 0, $limit, array(':status' => 0)) : db_query($query, array(':status' => 0));
+  foreach ($result as $message) {
     // Send the message.
     $status = views_send_deliver($message);
 
     if ($status) {
       // Update the spool status.
-      db_query("UPDATE {views_send_spool} SET status = %d WHERE eid = %d", 1, $message->eid);
+      db_query("UPDATE {views_send_spool} SET status = :status WHERE eid = :eid", array(':status' => 1, ':eid' => $message->eid));
       $ok++;
     }
     else {
       // Increment tentatives so that next time this message
       // will be scheduled with low priority.
-      db_query("UPDATE {views_send_spool} SET tentatives = tentatives + 1 WHERE eid = %d", $message->eid);
+      db_query("UPDATE {views_send_spool} SET tentatives = tentatives + 1 WHERE eid = :eid", array(':eid' => $message->eid));
       $fail++;
     }
 
@@ -70,30 +69,28 @@ function views_send_send_from_spool() {
  *   Boolean indicating if the message was sent successfully.
  */
 function views_send_deliver($message) {
+  $key = 'direct';
   $headers = unserialize($message->headers);
   $to = _views_send_format_address($message->to_mail, $message->to_name);
   $from = _views_send_format_address($message->from_mail, $message->from_name);
 
+  $mail = array(
+    'to' => $to,
+    'subject' => $message->subject,
+    'body' => $message->body,
+    'from' => $from,
+    'headers' => $headers,
+  );
+
   if (VIEWS_SEND_MIMEMAIL) {
-    $mail = array(
-      'address' => $to,
-      'subject' => mime_header_encode($message->subject),
-      'body' => $message->body,
-      'sender' => $from,
-      'headers' => $headers,
-    );
-    return mimemail_send_message($mail);
-  }
-  else {
-    $mail = array(
-      'to' => $to,
-      'subject' => $message->subject,
-      'body' => $message->body,
-      'from' => $from,
-      'headers' => $headers,
-    );
-    return drupal_mail_send($mail);
+    $mail['subject'] = mime_header_encode($message->subject);
+    mailsystem_set(array(
+      "views_send_$key" => 'MimeMailSystem'
+    ));
   }
+
+  $system = drupal_mail_system('views_send', $key);
+  return $system->mail($mail);
 }
 
 /**
@@ -102,5 +99,5 @@ function views_send_deliver($message) {
 function views_send_clear_spool() {
   // TODO: Drupal 7: replace time() with REQUEST_TIME.
   $expiration_time = time() - variable_get('views_send_spool_expire', 0) * 86400;
-  db_query("DELETE FROM {views_send_spool} WHERE status = %d AND timestamp <= %d", 1, $expiration_time);
+  db_query("DELETE FROM {views_send_spool} WHERE status = :status AND timestamp <= :expiry", array(':status' => 1, 'expiry' => $expiration_time));
 }
diff --git a/views_send.info b/views_send.info
index 67a1317..a682909 100644
--- a/views_send.info
+++ b/views_send.info
@@ -1,7 +1,6 @@
 name = "Views Send E-mail"
 descripion = "Implements a new action to be used with VBO in order to send E-mails to a list created with Views"
 dependencies[] = views_bulk_operations
+configure = admin/config/system/views_send
 package = Views
-core = 6.x
-
-
+core = 7.x
diff --git a/views_send.install b/views_send.install
index 3055c25..59f6f84 100644
--- a/views_send.install
+++ b/views_send.install
@@ -10,7 +10,7 @@
 /**
  * Impementation of hook_schema().
  *
- * @see http://api.drupal.org/api/function/hook_schema/6
+ * @see http://api.drupal.org/api/function/hook_schema/7
  */
 function views_send_schema() {
   $schema['views_send_spool'] = array(
@@ -85,8 +85,7 @@ function views_send_schema() {
         'description' => 'The E-mail additional headers.',
         'type' => 'text',
         'not null' => TRUE,
-        'size' => 'big',
-        'default' => ''),
+        'size' => 'big',),
     ),
     'indexes' => array(
       'uid' => array('uid'),
@@ -98,21 +97,11 @@ function views_send_schema() {
 }
 
 /**
- * Implementation of hook_install().
- *
- * @see http://api.drupal.org/api/function/hook_install/6
- */
-function views_send_install() {
-  drupal_install_schema('views_send');
-}
-
-/**
  * Implementation of hook_uninstall().
  *
- * @see http://api.drupal.org/api/function/hook_uninstall/6
+ * @see http://api.drupal.org/api/function/hook_uninstall/7
  */
 function views_send_uninstall() {
-  drupal_uninstall_schema('views_send');
   db_query("DELETE FROM {variable} WHERE name LIKE 'views_send_%'");
   db_query("DELETE FROM {cache} WHERE cid LIKE 'variables%'");
 }
diff --git a/views_send.module b/views_send.module
index e7d8d3c..8f51dad 100644
--- a/views_send.module
+++ b/views_send.module
@@ -10,7 +10,7 @@
  */
 
 /**
- * E-mail priorities.
+ * e-mail priorities.
  */
 define('VIEWS_SEND_PRIORITY_NONE', 0);
 define('VIEWS_SEND_PRIORITY_HIGHEST', 1);
@@ -45,15 +45,14 @@ define('VIEWS_SEND_MIMEMAIL', module_exists('mimemail'));
 /**
  * Implementation of hook_action_info()
  *
- * @see http://drupal.org/node/172152
+ * @see http://api.drupal.org/api/function/hook_action_info/7
  */
 function views_send_action_info() {
   return array(
     'views_send_mail_action' => array(
       'type' => 'system',
-      'description' => t('Send mass mail'),
+      'label' => t('Send mass mail'),
       'configurable' => TRUE,
-      'permissions' => array('mass mailing with views_send'),
     ),
   );
 }
@@ -64,7 +63,15 @@ function views_send_action_info() {
  * @see http://drupal.org/node/172152
  */
 function views_send_mail_action_form($context) {
-  $display = $context['view']->name .':'. $context['view']->current_display;
+  /* This copied from SMS Bulk - not sure if it always does what we want */
+  $view = views_get_current_view();
+  if (empty($view) and $context['view']) {
+    $view = views_get_view($context['view']->name);
+    $view->build('default');
+    views_set_current_view($view);
+  }
+  /* End copy */
+  $display = $view->name .':'. $view->current_display;
   $form = array();
   $form['display'] = array(
     '#type' => 'value',
@@ -86,20 +93,19 @@ function views_send_mail_action_form($context) {
   $form['from']['views_send_from_mail'] = array(
     '#type' => 'textfield',
     '#title' => t('Sender\'s e-mail'),
-    '#description' => t("Enter the sender's E-mail address."),
+    '#description' => t("Enter the sender's e-mail address."),
     '#required' => TRUE,
     '#default_value' => variable_get('views_send_from_mail_'. $display, variable_get('site_mail', ini_get('sendmail_from'))),
     '#maxlen' => 255,
   );
 
   $fields = array();
-  $keys = array_keys((array)$context['view']->result[0]);
-
-  foreach ($context['view']->field as $field_name => $field) {
-    if (in_array($field->field_alias, $keys) && !isset($fields[$field->field_alias])) {
-      $field_text = $field->label() .' ('. $field->field_alias .')';
-      $fields[$field->field_alias] = $field_text;
-      $tokens['[views-send-'. $field->field_alias .']'] = $field_text;
+  $keys = array_keys((array)$view->result[0]);
+  foreach ($view->field as $field_name => $field) {
+    if (in_array($field->field_alias, $keys) && ($field_name != 'views_bulk_operations')) {
+      $field_text = $field->label() .' ('. $field_name .')';
+      $fields[$field_name] = $field_text;
+      $tokens['[views-send-'. $field_name .']'] = $field_text;
     }
 
     /* TODO: Find a right way to obtain the right Label for aliases.
@@ -135,22 +141,22 @@ function views_send_mail_action_form($context) {
   );
   $form['to']['views_send_to_mail'] = array(
     '#type' => 'select',
-    '#title' => t('Field used for recipient\'s E-mail'),
-    '#description' => t('Select which field from the current view will be used as recipient\'s E-mail.'),
+    '#title' => t('Field used for recipient\'s e-mail'),
+    '#description' => t('Select which field from the current view will be used as recipient\'s e-mail.'),
     '#options' => $fields_options,
     '#default_value' => variable_get('views_send_to_mail_'. $display, ''),
     '#required' => TRUE,
   );
   $form['mail'] = array(
     '#type' => 'fieldset',
-    '#title' => t('E-mail content'),
+    '#title' => t('e-mail content'),
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
   );
   $form['mail']['views_send_subject'] = array(
     '#type' => 'textfield',
     '#title' => t('Subject'),
-    '#description' => t('Enter the E-mail\'s subject line.'),
+    '#description' => t('Enter the e-mail\'s subject line.'),
     '#maxlen' => 255,
     '#required' => TRUE,
     '#default_value' => variable_get('views_send_subject_'. $display, ''),
@@ -172,13 +178,12 @@ function views_send_mail_action_form($context) {
     '#collapsed' => TRUE,
   );
   $form['mail']['token']['tokens'] = array(
-    '#type' => 'markup',
-    '#value' => theme('views_send_token_help', $fields),
+    '#markup' => theme('views_send_token_help', $fields),
   );
 
   $form['additional'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Additional E-mail options'),
+    '#title' => t('Additional e-mail options'),
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
@@ -200,7 +205,7 @@ function views_send_mail_action_form($context) {
     '#type' => 'checkbox',
     '#title' => t('Request receipt'),
     '#default_value' => variable_get('views_send_receipt_'. $display, 0),
-    '#description' => t('Request a Read Receipt from your E-mails. A lot of email programs ignore these so it is not a definitive indication of how many people have read your message.'),
+    '#description' => t('Request a Read Receipt from your e-mails. A lot of email programs ignore these so it is not a definitive indication of how many people have read your message.'),
   );
   $form['additional']['views_send_headers'] = array(
     '#type' => 'textarea',
@@ -226,43 +231,33 @@ function views_send_mail_action_form($context) {
 function views_send_mail_action_validate($form, $form_state) {
   $values =& $form_state['values'];
 
-  // Check if sender's E-mail is a valid one.
+  // Check if sender's e-mail is a valid one.
   if (!valid_email_address($values['views_send_from_mail'])) {
-    form_set_error('from_mail', t('The sender\'s E-mail is not a valid E-mail name: %mail', array('%mail' => $values['views_send_from_mail'])));
+    form_set_error('from_mail', t('The sender\'s e-mail is not a valid e-mail name: %mail', array('%mail' => $values['views_send_from_mail'])));
   }
 
-  // Check in the column selected as E-mail contain valid E-mail values.
+  // Check in the column selected as e-mail contain valid e-mail values.
   if (!empty($values['views_send_to_mail'])) {
     $wrong_addresses = 0;
 
-    /**
-     * "views_send_mail_action" was the only action configured and "Merge single
-     * action's form with node selection view" checkbox is checked. We are on
-     * first submit and the $form_state['storage'] is not populated yet.
-     */
-    if ($values['step'] == VIEWS_BULK_OPS_STEP_SINGLE) {
-      // Normalize selection.
-      _views_bulk_operations_adjust_selection($values['objects']['selection'], $values['objects']['select_all'], $values['exposed_input'], $values['arguments'], $form['#plugin']);
-      $records =& $values['objects']['selection'];
-    }
-    /**
-     * Common usage: "views_send_mail_action" isn't the only action configured
-     * or "Merge single action's form with node selection view" checkbox is
-     * checked. $form_state['storage'] is populated and we will use it.
-     */
-    else {
-      $records =& $form_state['storage'][1]['objects']['selection'];
+    if ($form_state['step'] == 'views_form_views_form') {
+      /* The following line is inspired by _views_bulk_operations_get_selection */
+      $selection = array_flip(array_filter($form_state['values']['views_bulk_operations']));
+    } else {
+      $selection = $form_state['views_bulk_operations']['views_form_views_form']['selection'];
     }
-
-    foreach ($records as $record) {
+ 
+    foreach ($selection as $nid) {
+      /* TODO: Load e-mail field from node and verify - or is this available in the form?
       $email = $record->{$values["views_send_to_mail"]};
       if (!valid_email_address($email)) {
         $wrong_addresses++;
       }
+      */
     }
 
     if ($wrong_addresses) {
-      form_set_error('to_mail', t('The field used for recipient\'s E-mail %field contains @wrong invalid E-mail addresses from a total of @total selected. Choose other field to act as recipient\'s E-mail or narrow the selection to a subset containing only valid addresses.', array('%field' => $values['views_send_to_mail'], '@wrong' => $wrong_addresses, '@total' => count($records))));
+      form_set_error('to_mail', t('The field used for recipient\'s e-mail %field contains @wrong invalid e-mail addresses from a total of @total selected. Choose other field to act as recipient\'s e-mail or narrow the selection to a subset containing only valid addresses.', array('%field' => $values['views_send_to_mail'], '@wrong' => $wrong_addresses, '@total' => count($records))));
     }
   }
 }
@@ -276,8 +271,6 @@ function views_send_mail_action_submit($form, &$form_state) {
   $display = $form['display']['#value'];
   $values =& $form_state['values'];
   $return = array(
-    // TODO: Do we need this?
-    'view' => &$form_state['storage'][1]['plugin']->view,
     /**
      * TODO: This is just a flag needed in hook_form_alter() to identify the
      * form. Find other clever way to do that...
@@ -305,38 +298,57 @@ function views_send_mail_action_submit($form, &$form_state) {
  */
 function views_send_mail_action($object, $context) {
   global $user;
+  if (!user_access('mass mailing with views_send')) {
+    return;
+  }
 
   // From: parts.
   $from_mail = $context['views_send_from_mail'];
   $from_name = $context['views_send_from_name'];
 
   // To: parts.
-  $to_mail = $context['row']->{$context["views_send_to_mail"]};
-  $to_name = $context['views_send_to_name'] ? $context['row']->{$context["views_send_to_name"]} : '';
+  // (E-mail is either a field (on a node) or the mail address for a user, right?)
+  if (($context['entity_type'] == 'user') && ($context['views_send_to_mail'] == 'mail')) {
+    $to_mail = $object->mail;
+  } else {
+    $to_mail_arr = field_get_items($context['entity_type'],$object,$context['views_send_to_mail']);
+    $to_mail = isset($to_mail_arr[0]['email']) ? $to_mail_arr[0]['email'] : $to_mail_arr[0]['value'];
+  }
+
+  // Name can be a field or a node title ...
+  if (substr($context['views_send_to_name'],0,6) == 'field_') {
+    $to_name_arr = field_get_items($context['entity_type'],$object,$context['views_send_to_name']);
+    $to_name = $to_name_arr[0]['value'];
+  } else {
+    $to_name = $object->{$context['views_send_to_name']};
+  }
 
   // Formatting using selected input format.
   $subject = $context['views_send_subject'];
-  $body = ($context['views_send_message_format'] == VIEWS_SEND_FORMAT_PLAIN) ? $context['views_send_message'] : check_markup($context['views_send_message'], $context['views_send_message_format']);
+  $body = ($context['views_send_message_format'] == VIEWS_SEND_FORMAT_PLAIN) ? $context['views_send_message'] : 
+    check_markup($context['views_send_message'], $context['views_send_message_format']);
 
   // Populate row/context tokens.
   $token_keys = $token_values = array();
   foreach (array_keys($context['views_send_tokens']) as $field) {
     $token_keys[] = sprintf(VIEWS_SEND_TOKEN_PATTERN, $field);
-    $token_values[] = $context['row']->{$field};
+    if (substr($field,0,6) == 'field_') {
+      $token_arr = field_get_items($context['entity_type'],$object,$field);
+      $token_values[] = isset($token_arr[0]['email']) ? $token_arr[0]['email'] : $token_arr[0]['value'];
+    } else {
+      $token_values[] = $object->{$field};
+    }
   }
   $subject = str_replace($token_keys, $token_values, $subject);
   $body = str_replace($token_keys, $token_values, $body);
 
-  // Let Token module operate substitutions.
-  if (module_exists('token')) {
-    _views_send_normalize_context($context);
-    $subject = token_replace_multiple($subject, $context);
-    $body = token_replace_multiple($body, $context);
-  }
+  _views_send_normalize_context($context);
+  $subject = token_replace($subject, $context);
+  $body = token_replace($body, $context);
 
   // Process PHP code when only plain format is available.
   if (!VIEWS_SEND_MIMEMAIL && _views_send_allow_php() && ($context['views_send_message_format'] == VIEWS_SEND_FORMAT_PLAIN)) {
-    $body = drupal_eval($body);
+    $body = php_eval($body);
   }
 
   // We transform receipt, priority in headers,
@@ -348,7 +360,18 @@ function views_send_mail_action($object, $context) {
   _views_send_prepare_mail($from_name, $from_mail, $to_name, $to_mail, $subject, $body, $headers, $context['views_send_message_format']);
 
   // Queue the message to the spool table.
-  db_query("INSERT INTO {views_send_spool} (uid, timestamp, from_name, from_mail, to_name, to_mail, subject, body, headers) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $user->uid, time(), $from_name, $from_mail, $to_name, $to_mail, $subject, $body, serialize($headers));
+  $fields = array(
+    'uid' => $user->uid,
+    'timestamp' => time(),
+    'from_name' => $from_name,
+    'from_mail' => $from_mail,
+    'to_name' => $to_name,
+    'to_mail' => $to_mail,
+    'subject' => $subject,
+    'body' => $body,
+    'headers' => serialize($headers),
+  );
+  db_insert('views_send_spool')->fields($fields)->execute();
 }
 
 // === Hook implementations ====================================================
@@ -356,14 +379,14 @@ function views_send_mail_action($object, $context) {
 /**
  * Implementation of hook_menu().
  *
- * @see http://api.drupal.org/api/function/hook_menu/6
+ * @see http://api.drupal.org/api/function/hook_menu/7
  */
 function views_send_menu() {
   $items = array();
-  $items['admin/settings/views_send'] = array(
+  $items['admin/config/system/views_send'] = array(
     'type' => MENU_NORMAL_ITEM,
     'title' => 'Views Send',
-    'description' => 'Configure Views Send general options.',
+    'description' => t('Configure Views Send general options.'),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('views_send_settings'),
     'access arguments' => array('administer views_send'),
@@ -373,14 +396,20 @@ function views_send_menu() {
 }
 
 /**
- * Implementation of hook_perm().
+ * Implementation of hook_permission().
  *
- * @see http://api.drupal.org/api/function/hook_perm/6
+ * @see http://api.drupal.org/api/function/hook_permission/7
  */
-function views_send_perm() {
+function views_send_permission() {
   return array(
-    'administer views_send',
-    'mass mailing with views_send'
+    'administer views_send' => array(
+      'title' => t('Administer mass mail with Views'),
+      'description' => t('Configure sending of e-mails to a list created with Views.'),
+    ),
+    'mass mailing with views_send' => array(
+      'title' => t('Send mass mail with Views'),
+      'description' => t('Use VBO in order to send e-mails to a list created with Views.'),
+    ),
   );
 }
 
@@ -465,7 +494,7 @@ function views_send_form_alter($form, $form_state, $form_id) {
 /**
  * Implementation of hook_cron().
  *
- * @see http://api.drupal.org/api/function/hook_cron/6
+ * @see http://api.drupal.org/api/function/hook_cron/7
  */
 function views_send_cron() {
   // Load cron functions.
@@ -481,7 +510,7 @@ function views_send_cron() {
 /**
  * Implementation of hook_mail().
  *
- * @see http://api.drupal.org/api/function/hook_mail/6
+ * @see http://api.drupal.org/api/function/hook_mail/7
  */
 function views_send_mail($key, &$message, $params) {
 
@@ -492,7 +521,7 @@ function views_send_mail($key, &$message, $params) {
     $message['subject'] = $params['subject'];
 
     // Set the body.
-    $message['body'] = $params['body'];
+    $message['body'][] = $params['body'];
 
     // Add additional headers.
     $message['headers'] += $params['headers'];
@@ -527,11 +556,10 @@ function _views_send_filter_form($default_value) {
     '#title' => t('Message format'),
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
-    '#element_validate' => array('filter_form_validate'),
   );
 
   $guidelines = array();
-  $guidelines[] = VIEWS_SEND_MIMEMAIL ? t('Messages will be send in plain format.') : t('Only plain format is available. If you want to format the message as HTML, you\'ll have to install and enable <a href="http://drupal.org/project/mimemail">Mime Mail</a> module.');
+  $guidelines[] = VIEWS_SEND_MIMEMAIL ? t('Messages will be send in plain text format.') : t('Only plain text format is available. If you want to format the message as HTML, you\'ll have to install and enable <a href="http://drupal.org/project/mimemail">Mime Mail</a> module.');
   if (!VIEWS_SEND_MIMEMAIL && _views_send_allow_php()) {
     $guidelines[] = t('You may post PHP code. You should include &lt;?php ?&gt; tags.');
   }
@@ -539,12 +567,12 @@ function _views_send_filter_form($default_value) {
 
   $form[VIEWS_SEND_FORMAT_PLAIN] = array(
     '#type' => 'radio',
-    '#title' => t('Plain'),
+    '#title' => t('Plain text'),
     '#default_value' => VIEWS_SEND_MIMEMAIL ? $default_value : VIEWS_SEND_FORMAT_PLAIN,
     '#return_value' => VIEWS_SEND_FORMAT_PLAIN,
     '#parents' => $parents,
     '#description' => $guidelines,
-    '#id' => form_clean_id('edit-'. implode('-', array_merge($parents, array(VIEWS_SEND_FORMAT_PLAIN)))),
+    '#id' => drupal_html_id('edit-'. implode('-', array_merge($parents, array(VIEWS_SEND_FORMAT_PLAIN)))),
   );
 
   // If Mime Mail module is not present we allow only plain format.
@@ -567,7 +595,7 @@ function _views_send_filter_form($default_value) {
       '#return_value' => $format->format,
       '#parents' => $parents,
       '#description' => theme('filter_tips', _filter_tips($format->format, FALSE)),
-      '#id' => form_clean_id('edit-'. implode('-', $parents_for_id)),
+      '#id' => drupal_html_id('edit-'. implode('-', $parents_for_id)),
     );
   }
   $form[] = array('#value' => $extra);
@@ -582,7 +610,7 @@ function _views_send_filter_form($default_value) {
  * @param $priority
  *   Integer: The message priority.
  * @param $from
- *   String: The sender's E-mail address.
+ *   String: The sender's e-mail address.
  *
  * @return Header array with priority and receipt confirmation info
  */
@@ -643,7 +671,7 @@ function _views_send_headers($receipt, $priority, $from, $additional_headers) {
 }
 
 /**
- * Build a formatted E-mail address.
+ * Build a formatted e-mail address.
  */
 function _views_send_format_address($mail, $name, $encode = TRUE) {
   $name = trim($name);
@@ -658,19 +686,19 @@ function _views_send_format_address($mail, $name, $encode = TRUE) {
  * @param $from_name
  *   String holding the Sender's name.
  * @param $from_mail
- *   String holding the Sender's E-mail.
+ *   String holding the Sender's e-mail.
  * @param $to_name
  *   String holding the Recipient's name.
  * @param $to_mail
- *   String holding the Recipient's E-mail.
+ *   String holding the Recipient's e-mail.
  * @param $subject
- *   String with the E-mail subject. This argument can be altered here.
+ *   String with the e-mail subject. This argument can be altered here.
  * @param $body
- *   Text with the E-mail body. This argument can be altered here.
+ *   Text with the e-mail body. This argument can be altered here.
  * @param $headers
- *   Associative array with E-mail headers. This argument can be altered here.
+ *   Associative array with e-mail headers. This argument can be altered here.
  * @param $format
- *   String with the E-mail format.
+ *   String with the e-mail format.
  */
 function _views_send_prepare_mail($from_name, $from_mail, $to_name, $to_mail, &$subject, &$body, &$headers, $format) {
   /**
@@ -695,19 +723,17 @@ function _views_send_prepare_mail($from_name, $from_mail, $to_name, $to_mail, &$
   $params['body'] = $body;
   $params['headers'] = $headers;
 
-  // Call Drupal standard mail function, but without sending.
-  $mail = drupal_mail('views_send', $key, $params['to_formatted'], NULL, $params, $params['from_formatted'], FALSE);
-
-  // Add additional Mime Mail processing.
   if (VIEWS_SEND_MIMEMAIL) {
-    $plain = ($format == VIEWS_SEND_FORMAT_PLAIN);
-    $plain_text = $plain ? $mail['body'] : _views_send_html_to_text($mail['body'], TRUE);
-
-    $mail = mimemail($mail['from'], $mail['to'], $mail['subject'], $mail['body'], $plain, $mail['headers'], $plain_text, array(), '', FALSE);
+    mailsystem_set(array(
+      "views_send_$key" => 'MimeMailSystem'
+    ));
+  }
 
-    // From: header may be broken after mimemail_prepare().
-    $mail['headers']['From'] = _views_send_format_address($from_mail, $from_name);
+  // Call Drupal standard mail function, but without sending.
+  $mail = drupal_mail('views_send', $key, $params['to_formatted'], language_default(), $params, $params['from_formatted'], FALSE);
 
+  // Add additional Mime Mail post processing.
+  if (VIEWS_SEND_MIMEMAIL) {
     // We want to spool the Subject decoded.
     $mail['subject'] = mime_header_decode($mail['subject']);
   }
@@ -830,11 +856,10 @@ function _views_send_allow_php() {
   static $allow_php;
   if (!isset($allow_php)) {
     $allow_php = FALSE;
-    $result = db_query("SELECT format FROM {filters} WHERE module = 'php'");
-    while ($row = db_fetch_object($result)) {
-      if (filter_access($row->format)) {
+    if (module_exists('php')) {
+      $format = filter_format_load('php_code');
+      if ($format && filter_access($format)) {
         $allow_php = TRUE;
-        break;
       }
     }
   }
@@ -851,6 +876,8 @@ function _views_send_allow_php() {
  *
  * @return
  *   A themed table wirh all tokens.
+ *
+ * @todo: Add help for other tokens
  */
 function theme_views_send_token_help($fields) {
   $headers = array(t('Token'), t('Replacement value'));
@@ -861,21 +888,6 @@ function theme_views_send_token_help($fields) {
     $rows[] = array(sprintf(VIEWS_SEND_TOKEN_PATTERN, $field), $title);
   }
 
-  if (module_exists('token')) {
-    token_include();
-    $full_list = token_get_list();
-
-    foreach ($full_list as $key => $category) {
-      $rows[] = array(array('data' => drupal_ucfirst($key) .' '. t('tokens'), 'class' => 'region', 'colspan' => 2));
-      foreach ($category as $token => $description) {
-        $row = array();
-        $row[] = '['. $token .']';
-        $row[] = $description;
-        $rows[] = $row;
-      }
-    }
-  }
-
-  $output = theme('table', $headers, $rows, array('class' => 'description'));
+  $output = theme('table', array('headers' => $headers, 'rows' => $rows));
   return $output;
 }
