/**
* mime.php
*
- * Copyright (c) 1999-2003 The SquirrelMail Project Team
+ * Copyright (c) 1999-2004 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This contains the functions necessary to detect and decode MIME
/**
* Get the MIME structure
- *
+ *
* This function gets the structure of a message and stores it in the "message" class.
* It will return this object for use with all relevant header information and
* fully parsed into the standard "message" object format.
translateText($body, $wrap_at,
$body_message->header->getParameter('charset'));
}
- $link = 'read_body.php?passed_id=' . $id . '&ent_id='.$ent_num.
+ $link = 'passed_id=' . $id . '&ent_id='.$ent_num.
'&mailbox=' . $urlmailbox .'&sort=' . $sort .
'&startMessage=' . $startMessage . '&show_more=0';
if (isset($passed_ent_id)) {
$link .= '&passed_ent_id='.$passed_ent_id;
}
+ $body .= '<center><small><a href="download.php?absolute_dl=true&' .
+ $link . '">' . _("Download this as a file") . '</a>';
if ($view_unsafe_images) {
$text = _("Hide Unsafe Images");
} else {
$text = '';
}
}
- $body .= '<center><small><a href="'.$link.'">'.$text.
- '</a></small></center><br>' . "\n";
+ if($text != '') {
+ $body .= ' | <a href="read_body.php?' . $link . '">' . $text . '</a>';
+ }
+ $body .= '</small></center><br>' . "\n";
}
return $body;
}
return $body;
}
-/*
+/**
+ * Decodes headers
+ *
* This functions decode strings that is encoded according to
* RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text).
* Patched by Christian Schmidt <christian@ostenfeld.dk> 23/03/2002
+ *
+ * @param string $string header string that has to be made readable
+ * @param boolean $utfencode change message in order to be readable on user's charset. defaults to true
+ * @param boolean $htmlsave preserve spaces and sanitize html special characters. defaults to true
+ * @param boolean $decide decide if string can be utfencoded. defaults to false
+ * @return string decoded header string
*/
-function decodeHeader ($string, $utfencode=true,$htmlsave=true) {
+function decodeHeader ($string, $utfencode=true,$htmlsave=true,$decide=false) {
global $languages, $squirrelmail_language;
if (is_array($string)) {
$string = implode("\n", $string);
/* if the last chunk isn't an encoded string then put back the space, otherwise don't */
if ($iLastMatch !== $j) {
if ($htmlsave) {
- $ret .= ' ';
+ $ret .= ' ';
} else {
$ret .= ' ';
}
$replace = str_replace('_', ' ', $res[4]);
$replace = preg_replace('/=([0-9a-f]{2})/ie', 'chr(hexdec("\1"))',
$replace);
+ /* decide about valid decoding */
+ if ($decide && is_conversion_safe($res[2])) {
+ $utfencode=true;
+ $can_be_decoded=true;
+ } else {
+ $can_be_decoded=false;
+ }
/* Only encode into entities by default. Some places
* don't need the encoding, like the compose form.
*/
$chunk = $res[5];
$encoded = true;
}
-
- if (!$encoded && $htmlsave) {
- $ret .= htmlspecialchars($chunk);
- } else {
- $ret .= $chunk;
- }
-
if (!$encoded) {
if ($htmlsave) {
- $ret .= ' ';
+ $ret .= ' ';
} else {
$ret .= ' ';
}
}
+
+ if (!$encoded && $htmlsave) {
+ $ret .= htmlspecialchars($chunk);
+ } else {
+ $ret .= $chunk;
+ }
++$i;
}
+ /* remove the first added space */
+ if ($ret) {
+ if ($htmlsave) {
+ $ret = substr($ret,5);
+ } else {
+ $ret = substr($ret,1);
+ }
+ }
return $ret;
}
-/*
+/**
+ * Encodes header as quoted-printable
+ *
* 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.
+ *
+ * @param string $string header string, that has to be encoded
+ * @return string quoted-printable encoded string
*/
function encodeHeader ($string) {
global $default_charset, $languages, $squirrelmail_language;
function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
return $languages[$squirrelmail_language]['XTRA_CODE']('encodeheader', $string);
}
- if (strtolower($default_charset) == 'iso-8859-1') {
- $string = str_replace("\240",' ',$string);
- }
+ // instead of removing nbsp here, we don't add it in decodeHeader
+ // if (strtolower($default_charset) == 'iso-8859-1') {
+ // $string = str_replace("\240",' ',$string);
+ //}
// Encode only if the string contains 8-bit characters or =?
$j = strlen($string);
/**
* Remove any backslashes. See if there are any first.
*/
+
if (strstr($attvalue, '\\') !== false){
$attvalue = stripslashes($attvalue);
}
* @param $attvalue A string to run entity check against.
* @return Translated value.
*/
+
function sq_deent($attvalue){
$me = 'sq_deent';
/**
* See if we have to run the checks first. All entities must start
* with "&".
*/
- if (strpos($attvalue, "&") === false){
+ if (strpos($attvalue, '&') === false){
return $attvalue;
}
/**
* Leave " in, as it can mess us up.
*/
$trans = array_flip($trans);
- unset($trans{"""});
+ unset($trans{'"'});
while (list($ent, $val) = each($trans)){
- $attvalue = preg_replace("/$ent*(\W)/si", "$val\\1", $attvalue);
+ $attvalue = preg_replace('/' . $ent . '*/si', $val, $attvalue);
}
/**
* Now translate numbered entities from 1 to 255 if needed.
*/
- if (strpos($attvalue, "#") !== false){
+ if (strpos($attvalue, '#') !== false){
$omit = Array(34, 39);
- for ($asc=1; $asc<256; $asc++){
+ for ($asc = 256; $asc >= 0; $asc--){
if (!in_array($asc, $omit)){
$chr = chr($asc);
- $attvalue = preg_replace("/\�*$asc;*(\D)/si", "$chr\\1",
- $attvalue);
- $attvalue = preg_replace("/\�*".dechex($asc).";*(\W)/si",
- "$chr\\1", $attvalue);
+ $octrule = '/\�*' . $asc . ';*/si';
+ $hexrule = '/\�*' . dechex($asc) . ';*/si';
+ $attvalue = preg_replace($octrule, $chr, $attvalue);
+ $attvalue = preg_replace($hexrule, $chr, $attvalue);
}
}
}
$attvalue = sq_deent($attvalue);
$attvalue = sq_unspace($attvalue);
+ /**
+ * Remove \r \n \t \0 " " "\\"
+ */
+ $attvalue = str_replace(Array("\r", "\n", "\t", "\0", " ", "\\"),
+ Array('', '','','','',''), $attvalue);
+
/**
* Now let's run checks on the attvalues.
* I don't expect anyone to comprehend this. If you do,
"/include-source/i",
"/url\s*\(\s*([\'\"])\s*\S+script\s*:.*([\'\"])\s*\)/si",
"/url\s*\(\s*([\'\"])\s*mocha\s*:.*([\'\"])\s*\)/si",
- "/url\s*\(\s*([\'\"])\s*about\s*:.*([\'\"])\s*\)/si"
+ "/url\s*\(\s*([\'\"])\s*about\s*:.*([\'\"])\s*\)/si",
+ "/(.*)\s*:\s*url\s*\(\s*([\'\"]*)\s*\S+script\s*:.*([\'\"]*)\s*\)/si"
),
Array(
"idiocy",
"url(\\1#\\1)",
"url(\\1#\\1)",
"url(\\1#\\1)",
- "url(\\1#\\1)"
+ "url(\\1#\\1)",
+ "\\1:url(\\2#\\3)"
)
)
)
* @param string $type1 second half of mime type
* @param string $filename filename to tell the browser for downloaded file
* @param boolean $force whether to force the download dialog to pop
+ * @param integer $filesize optional, send the Content-Header and length to the browser
* @return void
*/
- function SendDownloadHeaders($type0, $type1, $filename, $force) {
+ function SendDownloadHeaders($type0, $type1, $filename, $force, $filesize=0) {
global $languages, $squirrelmail_language;
$isIE = $isIE6 = 0;
header("Content-Type: application/octet-stream; name=\"$filename\"");
}
}
- }
+
+ //send the content-length header if the calling function provides it
+ if ($filesize > 0) {
+ header("Content-Length: $filesize");
+ }
+
+ } // end fn SendDownlaodHeaders
?>