Index: mimemail.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mimemail/mimemail.inc,v
retrieving revision 1.24
diff -u -p -r1.24 mimemail.inc
--- mimemail.inc	18 Feb 2008 00:43:36 -0000	1.24
+++ mimemail.inc	18 May 2008 10:08:19 -0000
@@ -1,17 +1,17 @@
 <?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
- * Common mail functions for sending e-mail.  Originally written by Gerhard.  
- * 
+ * Common mail functions for sending e-mail.  Originally written by Gerhard.
+ *
  *   Allie Micka < allie at pajunas dot com >
  */
 
 /**
  * Attempts to RFC822-compliant headers for the mail message or its MIME parts
- * TODO could use some enhancement and stress testing 
- * 
+ * TODO could use some enhancement and stress testing
+ *
  * @param $headers An array of headers
  * @return header string
  */
@@ -22,15 +22,15 @@ function mimemail_rfc_headers($headers) 
     $key = trim($key);
     // collapse spaces and get rid of newline characters
     $value = preg_replace('/(\s+|\n|\r|^\s|\s$)/', ' ', $value);
-    
+
     //fold headers if they're too long
     if (strlen($value) > 60) {
       //if there's a semicolon, use that to separate
       if (count($array = preg_split('/;\s*/', $value)) > 1) {
         $value = trim(join(";$crlf    ", $array));
-      } 
+      }
       else {
-        $value = wordwrap($value, 50, "$crlf    ", false);
+        $value = wordwrap($value, 50, "$crlf    ", FALSE);
       }
     }
     $header .= "$key: $value$crlf";
@@ -44,7 +44,7 @@ function mimemail_rfc_headers($headers) 
  * @param $headers An array of headers
  * @return header string.
  */
-function mimemail_headers($headers, $from='') {
+function mimemail_headers($headers, $from = '') {
   // Note: This may not work. The MTA may rewrite the Return-Path, and Errors-To is deprecated.
   if (!$from) {
     $from = variable_get('site_mail', ini_get('sendmail_from'));
@@ -61,7 +61,7 @@ function mimemail_headers($headers, $fro
  * Converts html to utf-8 encoded text.
  *
  * @param $txt html text that needs formatting.
- * @param $inline Optional. If TRUE put links in the text, 
+ * @param $inline Optional. If TRUE put links in the text,
  *               if FALSE put a footnote into the text and
  *               a list of links below it. Default: FALSE
  *
@@ -110,7 +110,7 @@ function mimemail_html_to_text($txt, $in
  *                     'name' => file name,
  *                     'file' => reference to local file,
  *                     'Content-ID' => generated Content-ID,
- *                     'Content-Type' => derived using mime_content_type 
+ *                     'Content-Type' => derived using mime_content_type
  *                                       if available, educated guess otherwise
  *                     )
  *                  )
@@ -118,15 +118,15 @@ function mimemail_html_to_text($txt, $in
 function mimemail_extract_files($html) {
   $pattern = '/(<link[^>]+href="?|<object[^>]+codebase="?|@import |src="?)\/?([^"]+)("?)/emis';
   $html = preg_replace($pattern, '"\\1". _mimemail_file("\\2") ."\\3"', $html);
-  
+
   $document = array(array(
     'Content-Type' => "text/html; charset=utf-8",
     'Content-Transfer-Encoding' => 'base64',
     'content' => chunk_split(base64_encode($html)),
   ));
-  
+
   $files = _mimemail_file();
-  
+
   return array_merge($document, $files);
 }
 
@@ -143,7 +143,8 @@ function _mimemail_file($file = NULL, $t
   if ($file && !preg_match('@://|mailto:@', $file) && file_exists($file)) {
     $content_id = md5($file) .'@'. $_SERVER['HTTP_HOST'];
 
-    $new_file = array('name' => substr($file, strrpos($file, '/') + 1),
+    $new_file = array(
+      'name' => substr($file, strrpos($file, '/') + 1),
       'file' => $file,
       'Content-ID' => $content_id,
       'Content-Disposition' => $disposition,
@@ -154,11 +155,11 @@ function _mimemail_file($file = NULL, $t
 
     return 'cid:'. $content_id;
   }
-  
+
   if ($file) {
     return $file;
   }
-  
+
   $ret = $files;
   $files = array();
   return $ret;
@@ -166,7 +167,7 @@ function _mimemail_file($file = NULL, $t
 
 /**
  *
- * @param $parts 
+ * @param $parts
  *        an array of parts to be included
  *        each part is itself an array:
  *        array(
@@ -195,39 +196,39 @@ function _mimemail_file($file = NULL, $t
  *     '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(
     'Content-Type' => "$content_type; boundary=\"$boundary\"",
   );
   if (!$sub_part) {
-    $headers['MIME-Version'] = '1.0'; 
+    $headers['MIME-Version'] = '1.0';
     $body = "This is a multi-part message in MIME format.\n";
   }
 
   foreach ($parts as $part) {
     $part_headers = array();
-    
+
     if (isset($part['Content-ID'])) {
       $part_headers['Content-ID'] = '<'. $part['Content-ID'] .'>';
     }
-    
+
     if (isset($part['Content-Type'])) {
       $part_headers['Content-Type'] = $part['Content-Type'];
     }
-    
+
     if (isset($part['Content-Disposition'])) {
       $part_headers['Content-Disposition'] = $part['Content-Disposition'];
     }
-    else { 
+    else {
       $part_headers['Content-Disposition'] = 'inline';
     }
-    
+
     if ($part['Content-Transfer-Encoding']) {
       $part_headers['Content-Transfer-Encoding'] = $part['Content-Transfer-Encoding'];
     }
-    
+
     // mail content provided as a string
     if (isset($part['content']) && $part['content']) {
       if (!isset($part['Content-Transfer-Encoding'])) {
@@ -238,14 +239,14 @@ function mimemail_multipart_body($parts,
         $part_headers['Content-Type'] .= '; name="'. $part['name'] .'"';
         $part_headers['Content-Disposition'] .= '; filename="'. $part['name'] .'"';
       }
-      
+
     // mail content references in a filename
-    } 
+    }
     else {
       if (!isset($part['Content-Transfer-Encoding'])) {
         $part_headers['Content-Transfer-Encoding'] = 'base64';
       }
-      
+
       if (!isset($part['Content-Type'])) {
         $part['Content-Type'] = _mimemail_mimetype($part['file'], $type);
       }
@@ -254,10 +255,10 @@ function mimemail_multipart_body($parts,
         $part_headers['Content-Type'] .= '; name="'. $part['name'] .'"';
         $part_headers['Content-Disposition'] .= '; filename="'. $part['name'] .'"';
       }
-      
+
       $part_body = chunk_split(base64_encode(file_get_contents($part['file'])));
     }
-    
+
     $body .= "\n--$boundary\n";
     $body .= mimemail_rfc_headers($part_headers) ."\n\n";
     $body .= $part_body;
@@ -272,7 +273,7 @@ function mimemail_multipart_body($parts,
  * @param $body An HTML message body
  * @param $subject The message subject
  * @param $plaintext Whether the recipient prefers plaintext-only messages (default false)
- * 
+ *
  * @return
  *     an array containing the elements 'header' and 'body'.
  *     'body' is the mime encoded multipart body of a mail.
@@ -282,29 +283,29 @@ function mimemail_multipart_body($parts,
  * 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);
   }
   if ($plaintext) {
     return array(
-      'body' => $text, 
+      'body' => $text,
       'headers' => array('Content-Type' => 'text/plain; charset=utf-8'),
     );
   }
   $content_type = 'multipart/alternative';
 
   $text_part = array('Content-Type' => 'text/plain; charset=utf-8', 'content' => $text);
-  
+
   //expand all local links
   $pattern = '/(<a[^>]+href=")([^"]*)/emi';
   $body = preg_replace($pattern, '"\\1"._mimemail_url("\2")', $body);
-  
+
   $mime_parts = mimemail_extract_files($body);
 
-  $content = array($text_part, array_shift($mime_parts)); 
-  $content = mimemail_multipart_body($content, $content_type, true);
+  $content = array($text_part, array_shift($mime_parts));
+  $content = mimemail_multipart_body($content, $content_type, TRUE);
   $parts = array(array('Content-Type' => $content['headers']['Content-Type'], 'content' => $content['body']));
 
   if ($mime_parts) {
@@ -505,27 +506,27 @@ function _mimemail_url($url) {
   if (strpos($url, '://')) {
     return $url;
   }
-  
+
   if (preg_match('!mailto:!i', $url)) {
     return $url;
   }
-  
+
   $url = preg_replace( '!'. base_path() .'!', '', $url, 1);
   $url = str_replace('?q=', '', $url);
   list($url, $fragment) = explode('#', $url, 2);
   list($path, $query) = explode('?', $url, 2);
 
   if (empty($path) && !empty($fragment)) {
-    return '#' . $fragment;
+    return '#'. $fragment;
   }
-  
+
   return url($path, $query, $fragment, TRUE);
 }
 
 /**
  * Helper function to store processed urls.
  *
- * @param $url Optional. 
+ * @param $url Optional.
  * @param $refresh Optional. If TRUE refresh the cache.
  *
  * @return a count of stored if $url evaluates to false, the stored urls ortherwise.
@@ -594,25 +595,25 @@ function _mimemail_html2text() {
 }
 
 /**
- * Attempt to determine the mimetime from or filename .  While not ideal, 
+ * Attempt to determine the mimetime from or filename .  While not ideal,
  * using the filename as a fallback ensures that images will appear inline
  * in HTML messages
  *
  * @param $name Name of the file
- * 
+ *
  * @return best-guess mimetype string
  */
-function _mimemail_mimetype($file, $type='') {
+function _mimemail_mimetype($file, $type = '') {
   if ($type) {
     return $type;
-  } 
+  }
 
   if (function_exists('mime_content_type')) {
       return mime_content_type($file);
   }
 
   // some common embedded/attachment types
-  $types = array( 
+  $types = array(
     'jpg'  => 'image/jpeg',
     'jpeg' => 'image/jpeg',
     'gif'  => 'image/gif',
Index: mimemail.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mimemail/mimemail.module,v
retrieving revision 1.24
diff -u -p -r1.24 mimemail.module
--- mimemail.module	1 Mar 2008 05:11:52 -0000	1.24
+++ mimemail.module	18 May 2008 10:08:19 -0000
@@ -1,16 +1,18 @@
-<?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
- * 
+ * @file
+ * Component module for sending Mime-encoded emails
+ *
  */
- 
+
 /**
- * Implementation of hook_menu()
+ * Implementation of hook_menu().
  */
 function mimemail_menu() {
   $items[] = array(
-    'path' => 'admin/settings/mimemail',
+  'path' => 'admin/settings/mimemail',
     'title' => t('Mail'),
     'description' => t('HTML E-mail settings'),
     'callback' => 'drupal_get_form',
@@ -43,14 +45,14 @@ function mimemail_settings() {
   }
 
   $engines = mimemail_get_engines();
-  
+
   $form = array();
   $form['site_mail'] = array(
-    '#type'          => 'textfield', 
-    '#title'         => t('E-mail address'), 
-    '#default_value' => variable_get('site_mail', ini_get('sendmail_from')), 
-    '#size'          => 60, 
-    '#maxlength'     => 128, 
+    '#type'          => 'textfield',
+    '#title'         => t('E-mail address'),
+    '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
+    '#size'          => 60,
+    '#maxlength'     => 128,
     '#description'   => t('A valid e-mail address for this website, used by the auto-mailer during registration, new password requests, notifications, etc.')
   );
   $form['mimemail']['mimemail_alter'] = array(
@@ -85,24 +87,24 @@ function mimemail_settings() {
     '#required'      => TRUE,
     '#description'   => t('This string will be used to validate incoming messages.  It can be anything, but must be used on both sides of the transfer'),
   );
-  
+
   // hide the settings if only 1 engine is available
   if (count($engines) == 1) {
     variable_set('mimemail_engine', key($engines));
     $form['mimemail_engine'] = array(
         '#type'          => 'hidden',
-        '#title'         => t('E-mail engine'), 
-        '#default_value' => variable_get('mimemail_engine', 'mail'), 
-        '#options'       => $engines, 
+        '#title'         => t('E-mail engine'),
+        '#default_value' => variable_get('mimemail_engine', 'mail'),
+        '#options'       => $engines,
         '#description'   => t('Choose an e-mail engine for sending mails from your site.')
     );
   }
   else {
     $form['mimemail_engine'] = array(
         '#type'          => 'select',
-        '#title'         => t('E-mail engine'), 
-        '#default_value' => variable_get('mimemail_engine', 'mail'), 
-        '#options'       => $engines, 
+        '#title'         => t('E-mail engine'),
+        '#default_value' => variable_get('mimemail_engine', 'mail'),
+        '#options'       => $engines,
         '#description'   => t('Choose an e-mail engine for sending mails from your site.')
     );
   }
@@ -111,7 +113,7 @@ function mimemail_settings() {
     $settings = module_invoke(variable_get('mimemail_engine', 'mail'), 'mailengine', 'settings');
     if ($settings) {
         $form['mimemail_engine_settings'] = array(
-          '#type'        => 'fieldset', 
+          '#type'        => 'fieldset',
           '#title'       => t('Engine specific settings'),
       );
       foreach ($settings as $name => $value) {
@@ -127,16 +129,16 @@ function mimemail_settings() {
 }
 
 /**
- * Implementation of hook_user()
+ * Implementation of hook_user().
  */
-function mimemail_user($op, &$edit, &$user, $category='') {
-  if ( $op == 'form' && $category == 'account') { 
+function mimemail_user($op, &$edit, &$user, $category = '') {
+  if ( $op == 'form' && $category == 'account') {
     $form = array();
     $form['mimemail'] = array(
         '#type'          => 'fieldset',
         '#title'         => t('Email settings'),
-        '#weight'        => 5, 
-        '#collapsible' => true,
+        '#weight'        => 5,
+        '#collapsible' => TRUE,
     );
     $form['mimemail']['mimemail_textonly'] = array(
       '#type'           => 'checkbox',
@@ -145,23 +147,23 @@ function mimemail_user($op, &$edit, &$us
       '#description'     => t('Check this option if you do not wish to receive email messages with graphics and styles'),
     );
     return $form;
-  } 
+  }
   return;
 }
 
 /**
  * Send a mime-encoded email
- * 
+ *
  * @param $sender The email address or user object
  * @param $recipient An email address or user object * @param $subject An subject line string
  * @param $body An HTML body
  * @param $plaintext Whether to send message as plaintext only
  * @param $headers Optional e-mail headers in a keyed array
  * @param $text Optional plaintext portion of a multipart e-mail (instead of auto-generated)
- * 
+ *
  * @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';
 
@@ -171,7 +173,7 @@ function mimemail_prepare($sender, $reci
         'mail' => variable_get('site_mail', ini_get('sendmail_from')),
     );
   }
-  
+
   // try to determine recpient's text mail preference
   if (is_null($plaintext)) {
     if (is_object($recipient)) {
@@ -187,7 +189,7 @@ function mimemail_prepare($sender, $reci
     }
   }
   $subject = mime_header_encode($subject);
-  
+
   $plaintext = $plaintext || variable_get('mimemail_textonly', 0);
   $sender    = mimemail_address($sender);
   $mail      = mimemail_html_body(theme('mimemail_message', $body, $mailkey), $subject, $plaintext, $text, $attachments);
@@ -203,12 +205,26 @@ function mimemail_prepare($sender, $reci
   return $message;
 }
 
-function mimemail($sender, $recipient, $subject, $body, $plaintext = NULL, $headers=array(), $text = NULL, $attachments = array(), $mailkey = '') {
+/**
+ * Entrance function for processing mail information. Calls hook_mailengine(),
+ * which is custom to this module.
+ *
+ * @param string $sender
+ * @param string $recipient
+ * @param string $subject
+ * @param string $body
+ * @param ? $plaintext
+ * @param array $headers
+ * @param ? $text
+ * @param array $attachments
+ * @return bool
+ */
+function mimemail($sender, $recipient, $subject, $body, $plaintext = NULL, $headers = array(), $text = NULL, $attachments = array(), $mailkey = '') {
 
   $engine = variable_get('mimemail_engine', 'mimemail') .'_mailengine';
-  
+
   if (!function_exists($engine)) {
-    return false;
+    return FALSE;
   }
 
   $engine_prepare = variable_get('mimemail_engine', 'mimemail') .'_prepare';
@@ -221,7 +237,7 @@ function mimemail($sender, $recipient, $
 
   return $engine('send', $message);
 
-  return false;
+  return FALSE;
 }
 
 /**
@@ -246,30 +262,30 @@ function mimemail_get_engines() {
 function mimemail_mailengine($op, $message = array()) {
   //default values
   $message = array_merge( array(
-      'address' => '', 
-      'subject' => '', 
-      'body' => '', 
-      'sender' => '', 
-      'headers' => '', 
+      'address' => '',
+      'subject' => '',
+      'body' => '',
+      'sender' => '',
+      'headers' => '',
       ), $message);
-      
+
   switch ($op) {
     case 'name':
       return t('Mime Mail');
-      
+
     case 'description':
-      return t("Default mailing engine using drupal_mail().");
-      
+      return t('Default mailing engine using drupal_mail().');
+
     case 'settings': //not implemented
-      return false;
-      
+      return FALSE;
+
     case 'multiple':
     case 'single':
     case 'send':
       if (!is_array($message['address'])) {
         $message['address'] = array($message['address']);
       }
-      $status = true;
+      $status = TRUE;
       foreach ($message['address'] as $a) {
         $status = mail(
           $a,
@@ -277,12 +293,12 @@ function mimemail_mailengine($op, $messa
           $message['body'],
           mimemail_rfc_headers($message['headers'])
         ) && $status;
-    
+
       }
       return $status;
   }
 
-  return false;
+  return FALSE;
 }
 
 if (strpos(variable_get('smtp_library', ''), 'mimemail')
@@ -291,7 +307,7 @@ if (strpos(variable_get('smtp_library', 
   function drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $headers) {
     return mimemail($from, $to, $subject, $body, NULL, $headers, NULL, array(), $mailkey);
   }
-} 
+}
 
 function mimemail_mail_alter($mailkey, &$recipient, &$subject, &$body, &$sender, &$headers) {
 
@@ -319,35 +335,35 @@ function mimemail_incoming($message) {
   require_once dirname(__FILE__) .'/mimemail.inc';
   $mail = mimemail_parse($message);
 
-  foreach (module_implements('mimemail_incoming_alter') as $module) { 
-    call_user_func_array($module .'_mimemail_incoming_alter', $mail); 
+  foreach (module_implements('mimemail_incoming_alter') as $module) {
+    call_user_func_array($module .'_mimemail_incoming_alter', $mail);
   }
 
   module_invoke_all('mimemail_incoming', $mail);
 }
 
 /**
- * Formats an address string 
- * TODO could use some enhancement and stress testing 
- * 
+ * Formats an address string
+ * TODO could use some enhancement and stress testing
+ *
  * @param $address - a user object, a text email address or an array containing name, mail
  * @return formatted address string
  */
 function mimemail_address($address) {
-  
+
   if (is_array($address)) {
-    
+
     // it's an array containing 'mail' and/or 'name'
     if (isset($address['mail'])) {
       $output = '';
       if (empty($address['name'])) {
         return $address['mail'];
-      } 
+      }
       else {
         return '"'. addslashes($address['name']) .'" <'. $address['mail'] .'>';
       }
     }
-    
+
     // it's an array of address items
     $addresses = array();
     foreach ($address as $a) {
@@ -355,12 +371,12 @@ function mimemail_address($address) {
     }
     return $addresses;
   }
-  
+
   // it's a user object
   if (is_object($address) && isset($address->mail)) {
     return '"'. addslashes($address->name) .'" <'. $address->mail .'>';
   }
-  
+
   // it's formatted or unformatted string
   // TODO shouldn't assume it's valid - should try to re-parse
   if (is_string($address)) {
@@ -375,13 +391,13 @@ function mimemail_address($address) {
     );
   }
 
-  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" />';
 
