X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fmime.php;h=e7016d790c6a5f227d2ff41ea2dcff4f82f5cb78;hb=346817d46e0342d2611be7732e96bc07e1b72453;hp=278e5673f202a9a255e47322b19c8b16a1da5d16;hpb=5106a9be2f89a816f8da9595dff34b7d12e4f549;p=squirrelmail.git diff --git a/functions/mime.php b/functions/mime.php index 278e5673..e7016d79 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -20,12 +20,11 @@ class msg_header { /** msg_header contains generic variables for values that **/ /** could be in a header. **/ - var $type0 = '', $type1 = '', $boundary = '', $charset = ''; - var $encoding = '', $size = 0, $to = array(), $from = '', $date = ''; - var $cc = array(), $bcc = array(), $reply_to = '', $subject = ''; - var $id = 0, $mailbox = '', $description = '', $filename = ''; - var $entity_id = 0, $message_id = 0, $name = ''; - // var $priority = ""; + var $type0 = '', $type1 = '', $boundary = '', $charset = '', + $encoding = '', $size = 0, $to = array(), $from = '', $date = '', + $cc = array(), $bcc = array(), $reply_to = '', $subject = '', + $id = 0, $mailbox = '', $description = '', $filename = '', + $entity_id = 0, $message_id = 0, $name = '', $priority = 3; } class message { @@ -371,15 +370,22 @@ function mime_match_parenthesis ($pos, $structure) { return( $pos ); } -function mime_fetch_body ($imap_stream, $id, $ent_id ) { - // do a bit of error correction. If we couldn't find the entity id, just guess - // that it is the first one. That is usually the case anyway. - if (!$ent_id) +function mime_fetch_body($imap_stream, $id, $ent_id ) { + + /* + * do a bit of error correction. If we couldn't find the entity id, just guess + * that it is the first one. That is usually the case anyway. + */ + if (!$ent_id) { $ent_id = 1; - $data = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent_id]", true, $response, $message); + } + + $cmd = "FETCH $id BODY[$ent_id]"; + $data = sqimap_run_command ($imap_stream, $cmd, true, $response, $message); $topline = array_shift($data); - while (! ereg('\\* [0-9]+ FETCH ', $topline) && $data) + while (! ereg('\\* [0-9]+ FETCH ', $topline) && $data) { $topline = array_shift($data); + } $wholemessage = implode('', $data); if (ereg('\\{([^\\}]*)\\}', $topline, $regs)) { $ret = substr( $wholemessage, 0, $regs[1] ); @@ -410,36 +416,42 @@ function mime_fetch_body ($imap_stream, $id, $ent_id ) { } $k++; } - if ( $base <> '' ) - + if ( $base <> '' ) { $ret = "" . $ret; + } } } else if (ereg('"([^"]*)"', $topline, $regs)) { $ret = $regs[1]; } else { global $where, $what, $mailbox, $passed_id, $startMessage; - $par = "mailbox=".urlencode($mailbox)."&passed_id=$passed_id"; + $par = 'mailbox=' . urlencode($mailbox) . "&passed_id=$passed_id"; if (isset($where) && isset($what)) { - $par .= "&where=".urlencode($where)."&what=".urlencode($what); + $par .= '&where='. urlencode($where) . "&what=" . urlencode($what); } else { $par .= "&startMessage=$startMessage&show_more=0"; } - $par .= '&response='.urlencode($response).'&message='.urlencode($message). - '&topline='.urlencode($topline); + $par .= '&response=' . urlencode($response) . + '&message=' . urlencode($message). + '&topline=' . urlencode($topline); - echo '' . + echo '
' . + '' . + '' . + '" . + '" . + '" . + '" . + "
' . _("Body retrieval error. The reason for this is most probably that the message is malformed. Please help us making future versions better by submitting this message to the developers knowledgebase!") . - "Submit message
" . - '' . _("Response:") . "$response
" . - _("Message:") . " $message
" . - _("FETCH line:") . " $topline
"; + "
" . + _("Submit message") . '

 ' . + '
' . _("Command:") . "$cmd
' . _("Response:") . "$response
' . _("Message:") . "$message
' . _("FETCH line:") . "$topline


"; $data = sqimap_run_command ($imap_stream, "FETCH $passed_id BODY[]", true, $response, $message); array_shift($data); $wholemessage = implode('', $data); - $ret = "---------------\n$wholemessage"; - + $ret = $wholemessage; } return( $ret ); } @@ -453,8 +465,12 @@ function mime_print_body_lines ($imap_stream, $id, $ent_id, $encoding) { $sid = sqimap_session_id(); // Don't kill the connection if the browser is over a dialup // and it would take over 30 seconds to download it. - set_time_limit(0); - + + // donĀ“t call set_time_limit in safe mode. + if (!ini_get("safe_mode")) { + set_time_limit(0); + } + fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id]\r\n"); $cnt = 0; $continue = true; @@ -690,9 +706,17 @@ function formatAttachments ($message, $ent_id, $mailbox, $id) { "../src/download.php?absolute_dl=true&passed_id=$id&mailbox=$urlMailbox&passed_ent_id=$ent"; $ImageURL = ''; + /* this executes the attachment hook with a specific MIME-type. + * if that doens't have results, it tries if there's a rule + * for a more generic type. */ $HookResults = do_hook("attachment $type0/$type1", $Links, $startMessage, $id, $urlMailbox, $ent, $DefaultLink, $display_filename, $where, $what); + if(count($HookResults[1]) <= 1) { + $HookResults = do_hook("attachment $type0/*", $Links, + $startMessage, $id, $urlMailbox, $ent, $DefaultLink, + $display_filename, $where, $what); + } $Links = $HookResults[1]; $DefaultLink = $HookResults[6]; @@ -759,33 +783,40 @@ function decodeBody($body, $encoding) { * RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text). */ function decodeHeader ($string, $utfencode=true) { - if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', + +if ( is_array( $string ) ) { + $string = implode("\n", $string ); +} + +if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $string, $res)) { - if (ucfirst($res[2]) == "B") { + 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); - } + } else { + $replace = str_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); - } - /* Only encode into entities by default. Some places + } + /* Only encode into entities by default. Some places don't need the encoding, like the compose form. */ - if ($utfencode){ - $replace = charset_decode ($res[1], $replace); - } + if ($utfencode){ + $replace = charset_decode ($res[1], $replace); + } - // Remove the name of the character set. - $string = eregi_replace ('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', - $replace, $string); + // 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); + // In case there should be more encoding in the string: recurse + $string = decodeHeader($string); +} + +return ($string); } /* @@ -827,7 +858,7 @@ function encodeHeader ($string) { if ( $l ) { $string = "=?$default_charset?Q?$ret?="; } - + return( $string ); } @@ -836,7 +867,7 @@ function encodeHeader ($string) { */ function MagicHTML( $body, $id ) { - global $message, $PHP_SELF, $HTTP_SERVER_VARS, + global $message, $HTTP_SERVER_VARS, $attachment_common_show_images; $attachment_common_show_images = @@ -897,8 +928,8 @@ function MagicHTML( $body, $id ) { case '/HEA': case '!DOC': case 'META': - case 'DIV ': - case '/DIV': + //case 'DIV ': + //case '/DIV': case '!-- ': $i += 4; while ( $body{$i} <> '>' && @@ -1137,7 +1168,7 @@ function stripEvent( &$i, $j, &$body, $id, $base ) { $src = '../images/' . _("sec_remove_eng.png"); } $ret .= 'src="' . $src . '" '; - $i = $k - 3; + $i = $k - 2; } else { $ret .= 'src'; $i = $i + 3;