--- mimemail.inc 
+++ mimemail-outlook+filename.inc 
@@ -169,10 +169,13 @@
   $pattern = '/(<link[^>]+href="?|<object[^>]+codebase="?|@import |src="?)\/?([^"]+)("?)/emis';
   $html = preg_replace($pattern,'"\\1". _mimemail_file("\\2") ."\\3"', $html);
   
+  // agidise-mod: removed base64 encoding
   $document = array(array(
     'Content-Type' => "text/html; charset=utf-8",
-    'Content-Transfer-Encoding' => 'base64',
-    'content' => chunk_split(base64_encode($html)),
+    'Content-Transfer-Encoding' => '8bit',
+    // agidise-mod: no Content-Disposition
+    'Content-Disposition'=>'',
+    'content' => $html
   ));
   
   $files = _mimemail_file();
@@ -187,13 +190,15 @@
  *
  * @return an absolute :
  */
-function _mimemail_file($file = NULL, $type = '', $disposition = 'related') {
+// agidise-mod: added param $fileName
+function _mimemail_file($file = NULL, $type = '', $disposition = 'related', $fileName = null) {
   static $files = array();
 
   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),
+    // agidise-mod: handle specific filename
+    $new_file = array('name' => $fileName ? $fileName : substr($file, strrpos($file, '/') + 1),
                       'file' => $file,
                       'Content-ID' => $content_id,
                       'Content-Disposition' => $disposition,
@@ -267,8 +272,9 @@
       $part_headers['Content-Type'] = $part['Content-Type'];
     }
     
-    if (isset($part['Content-Disposition'])) {
-      $part_headers['Content-Disposition'] = $part['Content-Disposition'];
+    // agidise-mod: empty Content-Disposition
+    if (@array_key_exists($k='Content-Disposition', $part)) {
+      if ($part[$k]) $part_headers[$k] = $part[$k];
     }
     else { 
       $part_headers['Content-Disposition'] = 'inline';
@@ -280,8 +286,9 @@
     
     // mail content provided as a string
     if (isset($part['content']) && $part['content']) {
-      if (!isset($part['Content-Transfer-Encoding'])) {
-        $part_headers['Content-Transfer-Encoding'] = '8bit';
+      // agidise-mod: changed to array_key_exists instead of isset
+      if (!array_key_exists($k='Content-Transfer-Encoding', $part)) {
+        $part_headers[$k] = '8bit';
       }
       $part_body = $part['content'];
       if (isset($part['name'])) {
@@ -308,7 +315,8 @@
       $part_body = chunk_split(base64_encode(file_get_contents($part['file'])));
     }
     
-    $body .= "\n--$boundary\n";
+    // agidise-mod: extra newline required
+    $body .= "\n\n--$boundary\n";
     $body .= mimemail_rfc_headers($part_headers)."\n\n";
     $body .= $part_body;
   }
@@ -333,6 +341,7 @@
  * image/attachment
  */
 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);
@@ -345,7 +354,8 @@
   }
   $content_type = 'multipart/alternative';
 
-  $text_part = array('Content-Type'=>'text/plain; charset=utf-8','content'=>$text);
+  // agidise-mod: no Content-Disposition
+  $text_part = array('Content-Type'=>'text/plain; charset=utf-8','Content-Disposition'=>'','content'=>$text);
   
   //expand all local links
   $pattern = '/(<a[^>]+href=")([^"]*)/emi';
@@ -355,7 +365,8 @@
 
   $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']));
+  // agidise-mod: no Content-Disposition and Content-Transfer-Encoding
+  $parts = array(array('Content-Type'=>$content['headers']['Content-Type'],'Content-Transfer-Encoding'=>'','Content-Disposition'=>'','content'=>$content['body']));
 
   if ($mime_parts) {
     $content_type = 'multipart/related';
@@ -365,11 +376,16 @@
   foreach ($attachments as $a) {
     $a = (object) $a;
     $content_type = 'multipart/mixed';
-    _mimemail_file($a->filepath, $a->filemime, 'attachment');
+    // agidise-mod: handle specific filename
+    _mimemail_file($a->filepath, $a->filemime, 'attachment', $a->filename);
     $parts = array_merge($parts, _mimemail_file());
   }
 
-  return mimemail_multipart_body($parts,"$content_type; charset=utf-8");
+  // agidise-mod: mixed
+  $content_type = 'multipart/mixed';
+  
+  // agidise-mod: removed "$content_type; charset=utf-8"
+  return mimemail_multipart_body($parts,$content_type);
 }
 
 /**
