| ';
+ $body .= "$display_filename | ";
+ $body .= '' . show_readable_size($message->header->size) .
+ ' | ';
+ $body .= "[ $type0/$type1 ] | ";
+ $body .= '';
+ if ($message->header->description)
+ $body .= '' . htmlspecialchars($message->header->description) . '';
+ $body .= ' | ';
+
+
+ $SkipSpaces = 1;
+ foreach ($Links as $Val)
+ {
+ if ($SkipSpaces)
+ {
+ $SkipSpaces = 0;
+ }
+ else
+ {
+ $body .= ' | ';
+ }
+ $body .= '' . $Val['text'] . '';
+ }
+
+ unset($Links);
+
+ $body .= " |
\n";
+ }
+ return $body;
+ } else {
+ for ($i = 0; $i < count($message->entities); $i++) {
+ $body .= formatAttachments ($message->entities[$i], $ent_id, $mailbox, $id);
+ }
+ return $body;
+ }
+ }
+ }
+
+
+ /** this function decodes the body depending on the encoding type. **/
function decodeBody($body, $encoding) {
+ $body = str_replace("\r\n", "\n", $body);
$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]);
+ // Convert lowercase Quoted Printable to uppercase for
+ // quoted_printable_decode to understand it.
+ while (ereg("(=(([0-9][abcdef])|([abcdef][0-9])|([abcdef][abcdef])))", $replace, $res)) {
+ $replace = str_replace($res[1], strtoupper($res[1]), $replace);
+ }
+ $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);
+
+ // Remove the name of the character set.
+ $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 or anything that looks like it should
+ // be encoded.
+ function encodeHeader ($string) {
+ global $default_charset;
+
+ // Encode only if the string contains 8-bit characters or =?
+ if (ereg("([\200-\377]|=\\?)", $string)) {
+
+ // First the special characters
+ $string = str_replace("=", "=3D", $string);
+ $string = str_replace("?", "=3F", $string);
+ $string = str_replace("_", "=5F", $string);
+ $string = str_replace(" ", "_", $string);
+
+ for ( $ch = 127 ; $ch <= 255 ; $ch++ ) {
+ $replace = chr($ch);
+ $insert = sprintf("=%02X", $ch);
+ $string = str_replace($replace, $insert, $string);
}
- $newbody = $body;
- } else if ($encoding == "base64") {
- $newbody = base64_decode($body);
- } else {
- $newbody = $body;
+
+ $newstring = "=?$default_charset?Q?".$string."?=";
+
+ return $newstring;
}
- return $newbody;
+
+ return $string;
}
-?>
\ No newline at end of file
+
+?>