* Fix bugtracker issue 3172: re-write getMimeType in t3lib_htmlmail
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 13 Apr 2006 15:33:41 +0000 (15:33 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Thu, 13 Apr 2006 15:33:41 +0000 (15:33 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1429 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_htmlmail.php

index 22cfbf1..e71e1f9 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-04-13  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
+
+       * Fix bugtracker issue 3172: re-write getMimeType in t3lib_htmlmail
+
 2006-04-12  Ingmar Schlecht <ingmar@typo3.org>
 
        * Fixed bug #3174: chr() was misspelled char() in t3lib_div
index 6889bb2..63384b3 100755 (executable)
@@ -1263,32 +1263,21 @@ class t3lib_htmlmail {
        }
 
        /**
-        * [Describe function...]
+        * This function returns the mime type of the file specified by the url
         *
-        * @param       [type]          $url: ...
-        * @return      [type]          ...
+        * @param       string          $url: the url
+        * @return      string          $mimeType: the mime type found in the header
         */
-       function getMimeType($url)      {
-                       // Opens a connection to the server and returns the mime-type of the file
-                       // takes url only
-               $pathInfo = parse_url($url);
-               if (!$pathInfo["scheme"])       {return false;}
-               $getAdr = ($pathInfo["query"])?$pathInfo["path"]."?".$pathInfo["query"]:$pathInfo["path"];
-               $fp = fsockopen($pathInfo['host'], ($pathInfo['port']?$pathInfo['port']:80), $errno, $errstr);
-               if(!$fp) {
-                       return false;
-               } else {
-                       fputs($fp,'HEAD '.$getAdr." HTTP/1.0\r\nHost: ".$pathInfo['host']."\r\n\r\n");
-                       while(!feof($fp)) {
-                               $thePortion= fgets($fp,128);
-                               if (eregi("(^Content-Type: )(.*)",trim($thePortion), $reg))     {
-                                       $res = trim($reg[2]);
-                                       break;
-                               }
+       function getMimeType($url) {
+               $mimeType = '';
+               $headers = trim(t3lib_div::getURL($url, 2));
+               if ($headers) {
+                       $matches = array();
+                       if (preg_match('/(Content-Type:[\s]*)([a-zA-Z_0-9\/\-]*)([\s]|$)/', $headers, $matches)) {
+                               $mimeType = trim($matches[2]);
                        }
-                       fclose($fp);
                }
-               return $res;
+               return $mimeType;
        }
 
        /**