X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fmime.php;h=3227aebb3caa292df10f7945ae285109b9e72a33;hb=5594db7ade1796b3cb26487114d6d01464c9f820;hp=efee881a720ff8d83d4645f8e6c2c65edade7a4f;hpb=53901c7bc984082496cdd2415ae66e967fee45b8;p=squirrelmail.git diff --git a/functions/mime.php b/functions/mime.php index efee881a..3227aebb 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -6,7 +6,7 @@ * This contains the functions necessary to detect and decode MIME * messages. * - * @copyright 1999-2010 The SquirrelMail Project Team + * @copyright 1999-2017 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package squirrelmail @@ -63,7 +63,7 @@ function mime_structure ($bodystructure, $flags=array()) { displayPageHeader( $color, $mailbox ); $errormessage = _("SquirrelMail could not decode the bodystructure of the message"); $errormessage .= '
'._("The bodystructure provided by your IMAP server:").'

'; - $errormessage .= '
' . htmlspecialchars($read) . '
'; + $errormessage .= '
' . sm_encode_html_special_chars($read) . '
'; plain_error_message( $errormessage ); echo ''; exit; @@ -137,7 +137,13 @@ function mime_fetch_body($imap_stream, $id, $ent_id=1, $fetch_size=0) { $data = sqimap_run_command ($imap_stream, $cmd, true, $response, $message, TRUE); do { $topline = trim(array_shift($data)); - } while($topline && ($topline[0] == '*') && !preg_match('/\* [0-9]+ FETCH.*/i', $topline)) ; + } while($topline && ($topline[0] == '*') && !preg_match('/\* [0-9]+ FETCH .*BODY.*/i', $topline)) ; + // Matching with "BODY" above is difficult: in most cases "FETCH \(BODY" would work + // but some servers may put other things in the same result, perhaps something such + // as "* 23 FETCH (FLAGS (\Seen) BODY[1] {174}". There is some small chance that + // if the character sequence "BODY" appears in a response where it isn't actually + // a FETCH response data item name, the current regex will break things. The better + // way to do this would be to parse the response correctly and not use a regex. $wholemessage = implode('', $data); if (preg_match('/\{([^\}]*)\}/', $topline, $regs)) { @@ -626,7 +632,7 @@ function buildAttachmentArray($message, $exclude_id, $mailbox, $id) { $this_attachment['DownloadHREF'] = $links['download link']['href']; $this_attachment['ViewHREF'] = isset($links['attachment_common']) ? $links['attachment_common']['href'] : ''; $this_attachment['Size'] = $header->size; - $this_attachment['ContentType'] = htmlspecialchars($type0 .'/'. $type1); + $this_attachment['ContentType'] = sm_encode_html_special_chars($type0 .'/'. $type1); $this_attachment['OtherLinks'] = array(); foreach ($links as $val) { if ($val['text']==_("Download") || $val['text'] == _("View")) @@ -800,6 +806,7 @@ function decodeHeader ($string, $utfencode=true,$htmlsafe=true,$decide=false) { $iLastMatch = -2; $encoded = true; +// FIXME: spaces are allowed inside quoted-printable encoding, but the following line will bust up any such encoded strings $aString = explode(' ',$string); $ret = ''; foreach ($aString as $chunk) { @@ -825,7 +832,7 @@ function decodeHeader ($string, $utfencode=true,$htmlsafe=true,$decide=false) { $iLastMatch = $i; $j = $i; if ($htmlsafe) { - $ret .= htmlspecialchars($res[1]); + $ret .= sm_encode_html_special_chars($res[1]); } else { $ret .= $res[1]; } @@ -854,14 +861,15 @@ function decodeHeader ($string, $utfencode=true,$htmlsafe=true,$decide=false) { } } else { if ($htmlsafe) { - $replace = htmlspecialchars($replace); + $replace = sm_encode_html_special_chars($replace); } $ret.= $replace; } break; case 'Q': $replace = str_replace('_', ' ', $res[4]); - $replace = preg_replace('/=([0-9a-f]{2})/ie', 'chr(hexdec("\1"))', + $replace = preg_replace_callback('/=([0-9a-f]{2})/i', + create_function ('$matches', 'return chr(hexdec($matches[1]));'), $replace); if ($utfencode) { if ($can_be_encoded) { @@ -875,7 +883,7 @@ function decodeHeader ($string, $utfencode=true,$htmlsafe=true,$decide=false) { } } else { if ($htmlsafe) { - $replace = htmlspecialchars($replace); + $replace = sm_encode_html_special_chars($replace); } } $ret .= $replace; @@ -895,7 +903,7 @@ function decodeHeader ($string, $utfencode=true,$htmlsafe=true,$decide=false) { } if (!$encoded && $htmlsafe) { - $ret .= htmlspecialchars($chunk); + $ret .= sm_encode_html_special_chars($chunk); } else { $ret .= $chunk; } @@ -1890,7 +1898,9 @@ function sq_fix_url($attname, &$attvalue, $message, $id, $mailbox,$sQuote = '"') // images off by default. sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET, FALSE); - $secremoveimg = '../images/' . _("sec_remove_eng.png"); + global $use_transparent_security_image; + if ($use_transparent_security_image) $secremoveimg = '../images/spacer.png'; + else $secremoveimg = '../images/' . _("sec_remove_eng.png"); /** * Replace empty src tags with the blank image. src is only used @@ -2011,7 +2021,7 @@ function sq_fix_url($attname, &$attvalue, $message, $id, $mailbox,$sQuote = '"') break; } } else { - if (!(isset($aUrl['path']) && $aUrl['path'] == $secremoveimg)) { + if (!isset($aUrl['path']) || $aUrl['path'] != $secremoveimg) { // parse_url did not lead to satisfying result $attvalue = $sQuote . SM_PATH . 'images/blank.png' . $sQuote; } @@ -2103,7 +2113,11 @@ function sq_fixstyle($body, $pos, $message, $id, $mailbox){ * and change it to .bodyclass so we can just assign it to a
*/ $content = preg_replace("|body(\s*\{.*?\})|si", ".bodyclass\\1", $content); - $secremoveimg = '../images/' . _("sec_remove_eng.png"); + + global $use_transparent_security_image; + if ($use_transparent_security_image) $secremoveimg = '../images/spacer.png'; + else $secremoveimg = '../images/' . _("sec_remove_eng.png"); + /** * Fix url('blah') declarations. */ @@ -2350,6 +2364,17 @@ function sq_sanitize($body, list($free_content, $curpos) = sq_fixstyle($body, $gt+1, $message, $id, $mailbox); if ($free_content != FALSE){ + if ( !empty($attary) ) { + $attary = sq_fixatts($tagname, + $attary, + $rm_attnames, + $bad_attvals, + $add_attr_to_tag, + $message, + $id, + $mailbox + ); + } $trusted .= sq_tagprint($tagname, $attary, $tagtype); $trusted .= $free_content; $trusted .= sq_tagprint($tagname, false, 2); @@ -2530,7 +2555,10 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX', $take_mailto_links ) ); - $secremoveimg = "../images/" . _("sec_remove_eng.png"); + global $use_transparent_security_image; + if ($use_transparent_security_image) $secremoveimg = '../images/spacer.png'; + else $secremoveimg = '../images/' . _("sec_remove_eng.png"); + $bad_attvals = Array( "/.*/" => Array( @@ -2758,7 +2786,8 @@ function SendDownloadHeaders($type0, $type1, $filename, $force, $filesize=0) { $filename=rawurlencode($filename); header ("Pragma: public"); header ("Cache-Control: no-store, max-age=0, no-cache, must-revalidate"); // HTTP/1.1 - header ("Cache-Control: post-check=0, pre-check=0", false); + // does nothing - see: https://blogs.msdn.microsoft.com/ieinternals/2009/07/20/internet-explorers-cache-control-extensions/ + // header ("Cache-Control: post-check=0, pre-check=0", false); header ("Cache-Control: private"); //set the inline header for IE, we'll add the attachment header later if we need it