X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fmime.php;h=ef00957c74b2519bb77c3eeb645d7466fde66b63;hb=9d157cec2821461fe4d348a47e2312db5e84c052;hp=33148ada28f46a7996e777abc8d9d48ca5dbe1e2;hpb=97be216806423d7008317ac7b4ca81ca8a4c8504;p=squirrelmail.git diff --git a/functions/mime.php b/functions/mime.php index 33148ada..ef00957c 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -1,87 +1,105 @@ -
". _("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++) { @@ -138,47 +180,85 @@ $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; } + + + /** 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 - } + + if ($encoding == "quoted-printable") { + $body = quoted_printable_decode($body); + + while (ereg("=\n", $body)) + $body = ereg_replace ("=\n", "", $body); + } else if ($encoding == "base64") { + $body = base64_decode($body); + } + + // All other encodings are returned raw. + return $body; + } + + + // 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); } - for ($q=0;$q < count($body);$q++) { - $body[$q] = ereg_replace("=3D", "=", $body[$q]); + + $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); + } + + // Encode a string according to RFC 1522 for use in headers if it + // contains 8-bit characters + function encodeHeader ($string) { + global $default_charset; + + // Encode only if the string contains 8-bit characters + if (ereg("[\200-\377]", $string)) { + $newstring = "=?$default_charset?Q?"; + $newstring .= str_replace(" ", "_", $string); + + while (ereg("([\200-\377])", $newstring, $regs)) { + $replace = $regs[1]; + $insert = "=" . bin2hex($replace); + $newstring = str_replace($replace, $insert, $newstring); } - $newbody = $body; - } else if ($encoding == "base64") { - $newbody = base64_decode($body); - } else { - $newbody = $body; + + $newstring .= "?="; + + return $newstring; } - return $newbody; + + return $string; } -?> \ No newline at end of file + +?>