X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fmime.php;h=8b364a37ea2e949addcbc07caa7eda70d161ee29;hb=abddc974c228ad2762c276ad68778dde7cdfeabf;hp=8186b747961b2dc1f2fa98a930de0f5ce9eebd8d;hpb=4809f4894f2e81992b5e172aacb3e337da29e615;p=squirrelmail.git diff --git a/functions/mime.php b/functions/mime.php index 8186b747..8b364a37 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -1,29 +1,38 @@
". _("Download this as a file") ."

"; + /** Display the ATTACHMENTS: message if there's more than one part **/ if (count($message["ENTITIES"]) > 1) { - $pos = count($body); - $body[$pos] .= "
ATTACHMENTS:
"; + $body .= "
"; + $body .= "ATTACHMENTS:"; + $body .= "
"; $num = 0; for ($i = 0; $i < count($message["ENTITIES"]); $i++) { @@ -172,16 +177,16 @@ $num++; $filename = $message["ENTITIES"][$i]["FILENAME"]; if (trim($filename) == "") { - $filename = "UNKNOWN_FORMAT_" . time() . $i; - $display_filename = "Attachment $i"; + $display_filename = "untitled$i"; } else { $display_filename = $filename; } $urlMailbox = urlencode($message["INFO"]["MAILBOX"]); $id = $message["INFO"]["ID"]; - $body[$pos] .= "   " . $display_filename . "  (TYPE: $type0/$type1)
"; + $body .= "   " . $display_filename . "  (TYPE: $type0/$type1)
"; } + $body .= "
"; } return $body; } @@ -191,28 +196,42 @@ /** this function decodes the body depending on the encoding type. **/ function decodeBody($body, $encoding) { $encoding = strtolower($encoding); - if ($encoding == "us-ascii") { - $newbody = $body; // if only they all were this easy - } else if ($encoding == "quoted-printable") { - for ($q=0; $q < count($body); $q++) { - if (substr(trim($body[$q]), -1) == "=") { - $body[$q] = trim($body[$q]); - $body[$q] = substr($body[$q], 0, strlen($body[$q])-1); - } else if (substr(trim($body[$q]), -3) == "=20") { - $body[$q] = trim($body[$q]); - $body[$q] = substr($body[$q], 0, strlen($body[$q])-3); - $body[$q] = "$body[$q]\n"; // maybe should be \n.. dunno - } - } - for ($q=0;$q < count($body);$q++) { - $body[$q] = ereg_replace("=3D", "=", $body[$q]); - } - $newbody = $body; + + if ($encoding == "quoted-printable") { + $body = quoted_printable_decode($body); + + while (ereg("=\n", $body)) + $body = ereg_replace ("=\n", "", $body); } else if ($encoding == "base64") { - $newbody = base64_decode($body); - } else { - $newbody = $body; + $body = base64_decode($body); } - return $newbody; + + // All other encodings are returned raw. + return $body; } -?> \ No newline at end of file + + + // This functions decode strings that is encoded according to + // RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text). + function decodeHeader ($string) { + if (eregi('=\?([^?]+)\?(q|b)\?([^?]+)\?=', + $string, $res)) { + if (ucfirst($res[2]) == "B") { + $replace = base64_decode($res[3]); + } else { + $replace = ereg_replace("_", " ", $res[3]); + $replace = quoted_printable_decode($replace); + } + + $replace = charset_decode ($res[1], $replace); + + $string = eregi_replace + ('=\?([^?]+)\?(q|b)\?([^?]+)\?=', + $replace, $string); + // In case there should be more encoding in the string: recurse + return (decodeHeader($string)); + } else + return ($string); + } + +?>