Index: mimemail.inc
===================================================================
--- mimemail.inc	(revision 111)
+++ mimemail.inc	(working copy)
@@ -1,5 +1,5 @@
 <?php
-/* $Id: mimemail.inc,v 1.24 2008/02/18 00:43:36 vauxia Exp $ */
+// $Id$: mimemail.inc,v 1.24 2008/02/18 00:43:36 vauxia Exp $
 
 /**
  * @file
@@ -30,7 +30,7 @@
         $value = trim(join(";$crlf    ", $array));
       } 
       else {
-        $value = wordwrap($value, 50, "$crlf    ", false);
+        $value = wordwrap($value, 50, "$crlf    ", FALSE);
       }
     }
     $header .= "$key: $value$crlf";
@@ -126,10 +126,12 @@
   ));
   
   $files = _mimemail_file();
-  
+    
   return array_merge($document, $files);
 }
 
+
+
 /**
  * Helper function to extract local files
  *
@@ -141,7 +143,7 @@
   static $files = array();
 
   if ($file && !preg_match('@://|mailto:@', $file) && file_exists($file)) {
-    $content_id = md5($file) .'@'. $_SERVER['HTTP_HOST'];
+      $content_id = md5($file) .'@'. $_SERVER['HTTP_HOST'];
 
     $new_file = array('name' => substr($file, strrpos($file, '/') + 1),
       'file' => $file,
@@ -195,7 +197,7 @@
  *     'body' is the mime encoded multipart body of a mail.
  *     'headers' is an array that includes some headers for the mail to be sent.
  */
-function mimemail_multipart_body($parts, $content_type = 'multipart/mixed; charset=utf-8', $sub_part=false) {
+function mimemail_multipart_body($parts, $content_type = 'multipart/mixed; charset=utf-8', $sub_part=FALSE) {
   $boundary = md5(uniqid(time()));
   $body = '';
   $headers = array(
@@ -282,7 +284,7 @@
  * sub-parts for HTML and plaintext.  Each subsequent part is the required
  * image/attachment
  */
-function mimemail_html_body($body, $subject, $plaintext=false, $text=null, $attachments = array()) {
+function mimemail_html_body($body, $subject, $plaintext=FALSE, $text=NULL, $attachments = array()) {
   if (is_null($text)) {
     //generate plaintext alternative
     $text = mimemail_html_to_text($body);
@@ -301,10 +303,13 @@
   $pattern = '/(<a[^>]+href=")([^"]*)/emi';
   $body = preg_replace($pattern, '"\\1"._mimemail_url("\2")', $body);
   
+  // extract the images
+  $body = mimemail_extract_images($body);
+  
   $mime_parts = mimemail_extract_files($body);
 
   $content = array($text_part, array_shift($mime_parts)); 
-  $content = mimemail_multipart_body($content, $content_type, true);
+  $content = mimemail_multipart_body($content, $content_type, TRUE);
   $parts = array(array('Content-Type' => $content['headers']['Content-Type'], 'content' => $content['body']));
 
   if ($mime_parts) {
@@ -516,10 +521,10 @@
   list($path, $query) = explode('?', $url, 2);
 
   if (empty($path) && !empty($fragment)) {
-    return '#' . $fragment;
+    return '#'.$fragment;
   }
   
-  return url($path, $query, $fragment, TRUE);
+  return url($path, array('query' => $query, 'fragment' => $fragment, 'absolute' => TRUE));
 }
 
 /**
@@ -626,3 +631,6 @@
 
   return 'application/octet-stream';
 }
+
+
+
Index: mimemail.info
===================================================================
--- mimemail.info	(revision 111)
+++ mimemail.info	(working copy)
@@ -2,9 +2,10 @@
 name = Mime Mail
 description = E-mail with HTML and attachments
 package = Mail
+core = 6.x
 
 ; Information added by drupal.org packaging script on 2008-03-06
-version = "5.x-1.0"
+version = "6.x-1.0dev"
 project = "mimemail"
 datestamp = "1204776309"
 
Index: mimemail.module
===================================================================
--- mimemail.module	(revision 111)
+++ mimemail.module	(working copy)
@@ -1,4 +1,5 @@
-<?php /* $Id: mimemail.module,v 1.24 2008/03/01 05:11:52 vauxia Exp $ */
+<?php
+// $Id$: mimemail.module,v 1.24 2008/03/01 05:11:52 vauxia Exp $ */
 
 /**
  * @file Component module for sending Mime-encoded emails
@@ -9,24 +10,33 @@
  * Implementation of hook_menu()
  */
 function mimemail_menu() {
-  $items[] = array(
-    'path' => 'admin/settings/mimemail',
-    'title' => t('Mail'),
-    'description' => t('HTML E-mail settings'),
-    'callback' => 'drupal_get_form',
-    'callback arguments' => 'mimemail_settings',
-    'access' => user_access('administer site configuration'),
+  $items['admin/settings/mimemail'] = array(
+    'title' => 'Mail',
+    'description' => 'HTML E-mail settings',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('mimemail_settings'),
+    'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM,
   );
-  $items[] = array(
-    'path' => 'mimemail',
-    'callback' => 'mimemail_post',
-    'access' => variable_get('mimemail_incoming', FALSE),
+  $items['mimemail'] = array(
+    'page callback' => 'mimemail_post',
+    'access callback' => 'variable_get',
+    'access arguments' => array('mimemail_incoming', FALSE),
     'type' => MENU_CALLBACK,
   );
   return $items;
 }
 
+
+function mimemail_theme() {
+  return array(
+    'mimemail_message' => array(
+      'arguments' => array('body' => '', 'mailkey' => NULL),
+    )
+  );
+}
+
+
 function mimemail_settings() {
 
   // override the smtp_library value if mimemail is chosen to handle all mail
@@ -136,7 +146,7 @@
         '#type'          => 'fieldset',
         '#title'         => t('Email settings'),
         '#weight'        => 5, 
-        '#collapsible' => true,
+        '#collapsible' => TRUE,
     );
     $form['mimemail']['mimemail_textonly'] = array(
       '#type'           => 'checkbox',
@@ -161,7 +171,7 @@
  * 
  * @return result from mail() call
  */
-function mimemail_prepare($sender, $recipient, $subject, $body, $plaintext=null, $headers=array(), $text=null, $attachments=array(), $mailkey = '') {
+function mimemail_prepare($sender, $recipient, $subject, $body, $plaintext=NULL, $headers=array(), $text=NULL, $attachments=array(), $mailkey = '') {
 
   require_once dirname(__FILE__) .'/mimemail.inc';
 
@@ -208,10 +218,11 @@
   $engine = variable_get('mimemail_engine', 'mimemail') .'_mailengine';
   
   if (!function_exists($engine)) {
-    return false;
+    return FALSE;
   }
 
   $engine_prepare = variable_get('mimemail_engine', 'mimemail') .'_prepare';
+  
   if (function_exists($engine_prepare)) {
     $message = $engine_prepare($sender, $recipient, $subject, $body, $plaintext, $headers, $text, $attachments, $mailkey);
   }
@@ -221,7 +232,7 @@
 
   return $engine('send', $message);
 
-  return false;
+  return FALSE;
 }
 
 /**
@@ -245,6 +256,7 @@
  */
 function mimemail_mailengine($op, $message = array()) {
   //default values
+ob_start(); var_dump($message); file_put_contents("/tmp/mail.txt",ob_get_clean());
   $message = array_merge( array(
       'address' => '', 
       'subject' => '', 
@@ -261,7 +273,7 @@
       return t("Default mailing engine using drupal_mail().");
       
     case 'settings': //not implemented
-      return false;
+      return FALSE;
       
     case 'multiple':
     case 'single':
@@ -269,7 +281,7 @@
       if (!is_array($message['address'])) {
         $message['address'] = array($message['address']);
       }
-      $status = true;
+      $status = TRUE;
       foreach ($message['address'] as $a) {
         $status = mail(
           $a,
@@ -282,24 +294,26 @@
       return $status;
   }
 
-  return false;
+  return FALSE;
 }
 
 if (strpos(variable_get('smtp_library', ''), 'mimemail')
   && !function_exists('drupal_mail_wrapper')) {
 
-  function drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $headers) {
-    return mimemail($from, $to, $subject, $body, NULL, $headers, NULL, array(), $mailkey);
+  function drupal_mail_wrapper($message) {
+    return mimemail($message['from'], $message['to'], $message['subject'], $message['body'], NULL, $message['headers'], NULL, array(), $message['id']);
   }
 } 
 
-function mimemail_mail_alter($mailkey, &$recipient, &$subject, &$body, &$sender, &$headers) {
+function mimemail_mail_alter(&$message) {
+  if (variable_get('mimemail_alter', 0)) {
 
-  if (!variable_get('mimemail_alter', 0)) return;
-
-  // attempt to fixup non-html messages that are being sent through drupal_mail
-  // I'm open to suggestions for better ways of doing this
-  $body = check_markup($body, FILTER_FORMAT_DEFAULT);
+    // attempt to fixup non-html messages that are being sent through drupal_mail
+    // I'm open to suggestions for better ways of doing this
+    foreach ($message['body'] as $index => $body_line) {  
+    	//$message['body'][$index] = check_markup($body_line, FILTER_FORMAT_DEFAULT); 
+    }
+  }
   return;
 }
 
@@ -309,7 +323,7 @@
   $hash    = md5(variable_get('mimemail_key', '**') . $message );
 
   if ($hash != $token) {
-    watchdog('access denied', t('Authentication error for POST e-mail'), WATCHDOG_WARNING);
+    watchdog('access denied', 'Authentication error for POST e-mail', NULL, WATCHDOG_WARNING);
     return drupal_access_denied();
   }
   return mimemail_incoming($message);
@@ -375,13 +389,13 @@
     );
   }
 
-  return false;
+  return FALSE;
 }
 
 /**
  * Themeable message body
  */
-function theme_mimemail_message($body, $mailkey = null) {
+function theme_mimemail_message($body, $mailkey = NULL) {
   $output = '<html><head>';
   $output .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
 
@@ -390,11 +404,36 @@
   $styles = path_to_theme() .'/mail.css';
 
   $output .= '<style type="text/css"><!--';
-  if (!file_exists($styles)) {
+  if (file_exists($styles)) {
+      $styles = array($styles);
+  } else {
     // embed a version of all style definitions
-    $styles = preg_replace('|<style.*"'. base_path() .'([^"]*)".*|', '\1', drupal_get_css());
+//    $styles = preg_replace('|<style.*"'. base_path() .'([^"]*)".*|', '\1', drupal_get_css());
+    $css = "<?xml version='1.0' standalone='yes'?>\n<links>\n".drupal_get_css()."</links>\n";
+    $docs = new SimpleXMLElement($css);
+    $styles = array();
+    
+    global $base_url;
+    
+    foreach ($docs->link as $link) {
+      if ($link['type'] == 'text/css') {
+        $href = $link['href'];
+        if (substr($href,0,7) != 'http://') {
+          // if there's no http:// then add it with the server name
+          // check if it's a relative path, then add the base path... all paths should be relative to the base path
+          // anyway, to ensure compatibility with clean urls
+          if (substr($href,0,1) != '/') {
+            $href = base_path() .'/'. $href;
+          } else {
+            $href = 'http://'. $_SERVER['SERVER_NAME'] . $href;
+          }
+        }
+        $styles[] = $href; 
+      }
+    }
   }
-  foreach (explode("\n", $styles) as $style) {
+  foreach ($styles as $style) {
+      watchdog('mimemail','getting file %file as css to include in mail', array('%file' => $style));
     $output .= file_get_contents($style);
   }
   $output .= '--></style></head><body id="mimemail-body"><div id="center"><div id="main">'. $body .'</div></div></body></html>';
