Allow plugins to customize attachment link (for instance, use image instead of text...
[squirrelmail.git] / functions / mime.php
index ea49c4d8b61ed49695e1e2b6ccd78d4cc406388a..c13a36681f58fd4bfff4ba001769691032613350 100644 (file)
@@ -516,7 +516,7 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
             } else {
                 $attachments .= '  |  ';
             }
-            $attachments .= '<a href="' . $val['href'] . '">' .  $val['text'] . '</a>';
+            $attachments .= '<a href="' . $val['href'] . '">' . (isset($val['text']) && !empty($val['text']) ? $val['text'] : '') . (isset($val['extra']) && !empty($val['extra']) ? $val['extra'] : '') . '</a>';
         }
         unset($links);
         $attachments .= "</td></tr>\n";
@@ -866,6 +866,15 @@ function find_ent_id($id, $message) {
 //                if (sq_check_save_extension($message->entities[$i])) {
                     return $message->entities[$i]->entity_id;
 //                }
+            } elseif (!empty($message->entities[$i]->header->parameters['name'])) {
+                /**
+                 * This is part of a fix for Outlook Express 6.x generating
+                 * cid URLs without creating content-id headers
+                 * @@JA - 20050207
+                 */
+                if (strcasecmp($message->entities[$i]->header->parameters['name'], $id) == 0) {
+                    return $message->entities[$i]->entity_id;
+                }
             }
         }
     }
@@ -1442,12 +1451,34 @@ function sq_fixatts($tagname,
                 }
             }
         }
+
+
+        /**
+         * Replace empty src tags with the blank image.  src is only used
+         * for frames, images, and image inputs.  Doing a replace should
+         * not affect them working as should be, however it will stop
+         * IE from being kicked off when src for img tags are not set
+         */
+        if (($attname == 'src') && ($attvalue == '""')) {
+            $attary{$attname} = '"' . SM_PATH . 'images/blank.png"';
+        }
+
         /**
         * Turn cid: urls into http-friendly ones.
         */
         if (preg_match("/^[\'\"]\s*cid:/si", $attvalue)){
             $attary{$attname} = sq_cid2http($message, $id, $attvalue, $mailbox);
         }
+
+        /**
+         * "Hack" fix for Outlook using propriatary outbind:// protocol in img tags.
+         * One day MS might actually make it match something useful, for now, falling
+         * back to using cid2http, so we can grab the blank.png.
+         */
+        if (preg_match("/^[\'\"]\s*outbind:\/\//si", $attvalue)) {
+            $attary{$attname} = sq_cid2http($message, $id, $attvalue, $mailbox);
+        }
+
     }
     /**
     * See if we need to append any attributes to this tag.
@@ -1550,11 +1581,37 @@ function sq_cid2http($message, $id, $cidurl, $mailbox){
     /* in case of non-save cid links $httpurl should be replaced by a sort of
     unsave link image */
     $httpurl = '';
-    if ($linkurl) {
+
+   /**
+    * This is part of a fix for Outlook Express 6.x generating
+    * cid URLs without creating content-id headers. These images are
+    * not part of the multipart/related html mail. The html contains
+    * <img src="cid:{some_id}/image_filename.ext"> references to
+    * attached images with as goal to render them inline although
+    * the attachment disposition property is not inline.
+    **/
+
+    if (empty($linkurl)) {
+        if (preg_match('/{.*}\//', $cidurl)) {
+            $cidurl = preg_replace('/{.*}\//','', $cidurl);
+            if (!empty($cidurl)) {
+                $linkurl = find_ent_id($cidurl, $message);
+            }
+        }
+    }
+    if (!empty($linkurl)) {
         $httpurl = $quotchar . SM_PATH . 'src/download.php?absolute_dl=true&amp;' .
-                "passed_id=$id&amp;mailbox=" . urlencode($mailbox) .
-                '&amp;ent_id=' . $linkurl . $quotchar;
+                   "passed_id=$id&amp;mailbox=" . urlencode($mailbox) .
+                   '&amp;ent_id=' . $linkurl . $quotchar;
+    } else {
+        /**
+         * If we couldn't generate a proper img url, drop in a blank image
+         * instead of sending back empty, otherwise it causes unusual behaviour
+         */
+        $httpurl = $quotchar . SM_PATH . 'images/blank.png';
     }
     return $httpurl;
 }
 
@@ -1822,7 +1879,8 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX') {
                                 "img",
                                 "br",
                                 "hr",
-                                "input"
+                                "input",
+                                "outbind"
                                 );
 
     $force_tag_closing = true;
@@ -1935,6 +1993,11 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX') {
     if (preg_match("|$secremoveimg|i", $trusted)){
         $has_unsafe_images = true;
     }
+
+
+    // we want to parse mailto's and other URLs in HTML output too
+    parseUrl($trusted);
+
     return $trusted;
 }
 
@@ -2046,4 +2109,4 @@ function SendDownloadHeaders($type0, $type1, $filename, $force, $filesize=0) {
 
 }  // end fn SendDownloadHeaders
 
-?>
\ No newline at end of file
+?>