Update to current spec.
1.1 --- a/sniffed.php Tue Feb 05 17:38:44 2008 +0000
1.2 +++ b/sniffed.php Sun Aug 10 17:45:20 2008 +0200
1.3 @@ -16,14 +16,15 @@
1.4 if (!isset($this->file->headers['content-encoding'])
1.5 && ($this->file->headers['content-type'] === 'text/plain'
1.6 || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
1.7 - || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'))
1.8 + || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
1.9 + || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8'))
1.10 {
1.11 return $this->text_or_binary();
1.12 }
1.13
1.14 if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
1.15 {
1.16 - $official = substr($this->file->headers['content-type'], 0, $pos);
1.17 + $official = rtrim(substr($this->file->headers['content-type'], 0, $pos));
1.18 }
1.19 else
1.20 {
1.21 @@ -72,34 +73,14 @@
1.22 {
1.23 if (substr($this->file->body, 0, 2) === "\xFE\xFF"
1.24 || substr($this->file->body, 0, 2) === "\xFF\xFE"
1.25 - || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
1.26 || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
1.27 {
1.28 return 'text/plain';
1.29 }
1.30 - elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
1.31 - {
1.32 - return 'application/octect-stream';
1.33 - }
1.34 - else
1.35 + elseif (preg_match('/[^\x00-\x08\x0B\x0E-\x1A\x1C-\x1F]/', substr($this->file->body, 0, 512)))
1.36 {
1.37 return 'text/plain';
1.38 }
1.39 - }
1.40 -
1.41 - private function unknown()
1.42 - {
1.43 - $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
1.44 - if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
1.45 - || strtolower(substr($this->file->body, $ws, 5)) === '<html'
1.46 - || strtolower(substr($this->file->body, $ws, 7)) === '<script')
1.47 - {
1.48 - return 'text/html';
1.49 - }
1.50 - elseif (substr($this->file->body, 0, 5) === '%PDF-')
1.51 - {
1.52 - return 'application/pdf';
1.53 - }
1.54 elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
1.55 {
1.56 return 'application/postscript';
1.57 @@ -121,9 +102,68 @@
1.58 {
1.59 return 'image/bmp';
1.60 }
1.61 + elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
1.62 + {
1.63 + return 'image/vnd.microsoft.icon';
1.64 + }
1.65 else
1.66 {
1.67 - return $this->text_or_binary();
1.68 + return 'application/octet-stream';
1.69 + }
1.70 + }
1.71 +
1.72 + private function unknown()
1.73 + {
1.74 + $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
1.75 + if (strtolower(substr($this->file->body, 0, 14)) === '<!doctype html'
1.76 + || strtolower(substr($this->file->body, $ws, 5)) === '<html'
1.77 + || strtolower(substr($this->file->body, $ws, 5)) === '<head'
1.78 + || strtolower(substr($this->file->body, $ws, 7)) === '<script')
1.79 + {
1.80 + return 'text/html';
1.81 + }
1.82 + elseif (substr($this->file->body, 0, 5) === '%PDF-')
1.83 + {
1.84 + return 'application/pdf';
1.85 + }
1.86 + elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
1.87 + {
1.88 + return 'application/postscript';
1.89 + }
1.90 + elseif (substr($this->file->body, 0, 2) === "\xFE\xFF"
1.91 + || substr($this->file->body, 0, 2) === "\xFF\xFE"
1.92 + || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
1.93 + {
1.94 + return 'text/plain';
1.95 + }
1.96 + elseif (substr($this->file->body, 0, 6) === 'GIF87a'
1.97 + || substr($this->file->body, 0, 6) === 'GIF89a')
1.98 + {
1.99 + return 'image/gif';
1.100 + }
1.101 + elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
1.102 + {
1.103 + return 'image/png';
1.104 + }
1.105 + elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
1.106 + {
1.107 + return 'image/jpeg';
1.108 + }
1.109 + elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
1.110 + {
1.111 + return 'image/bmp';
1.112 + }
1.113 + elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
1.114 + {
1.115 + return 'image/vnd.microsoft.icon';
1.116 + }
1.117 + elseif (preg_match('/[^\x00-\x08\x0B\x0E-\x1A\x1C-\x1F]/', substr($this->file->body, 0, 512)))
1.118 + {
1.119 + return 'text/plain';
1.120 + }
1.121 + else
1.122 + {
1.123 + return 'application/octet-stream';
1.124 }
1.125 }
1.126
1.127 @@ -146,6 +186,10 @@
1.128 {
1.129 return 'image/bmp';
1.130 }
1.131 + elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
1.132 + {
1.133 + return 'image/vnd.microsoft.icon';
1.134 + }
1.135 else
1.136 {
1.137 return false;