$unsafe_url = 'view_text.php?' . $QUERY_STRING; $unsafe_url = set_url_var($unsafe_url, 'view_unsafe_images', 1); $body = mime_fetch_body($imapConnection, $passed_id, $ent_id); $body = decodeBody($body, $encoding); if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { if (mb_detect_encoding($body) != 'ASCII') { $body = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $body); } } if ($type1 == 'html' || isset($override_type1) && $override_type1 == 'html') { $ishtml = TRUE; // html attachment with character set information if (!empty($charset)) { $body = charset_decode($charset, $body, false, true); } $body = magicHTML($body, $passed_id, $message, $mailbox); } else { $ishtml = FALSE; translateText($body, $wrap_at, $charset); } displayPageHeader($color, 'None'); ?> <br /><table width="100%" border="0" cellspacing="0" cellpadding="2" align="center"><tr><td bgcolor="<?php echo $color[0]; ?> "> <b><center> <?php echo _("Viewing a text attachment") . ' - ' . '<a href="' . $msg_url . '">' . _("View message") . '</a>'; ?> </b></td><tr><tr><td><center>
/** * This returns a parsed string called $body. That string can then * be displayed as the actual message in the HTML. It contains * everything needed, including HTML Tags, Attachments at the * bottom, etc. * * Since 1.2.0 function uses message_body hook. * Till 1.3.0 function included output of formatAttachments(). * * @param resource $imap_stream imap connection resource * @param object $message squirrelmail message object * @param array $color squirrelmail color theme array * @param integer $wrap_at number of characters per line * @param string $ent_num (since 1.3.0) message part id * @param integer $id (since 1.3.0) message id * @param string $mailbox (since 1.3.0) imap folder name * @return string html formated message text */ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $mailbox = 'INBOX') { /* This if statement checks for the entity to show as the * primary message. To add more of them, just put them in the * order that is their priority. */ global $startMessage, $languages, $squirrelmail_language, $show_html_default, $sort, $has_unsafe_images, $passed_ent_id, $use_iframe, $iframe_height, $download_and_unsafe_link, $download_href, $unsafe_image_toggle_href, $unsafe_image_toggle_text, $oTemplate, $nbsp; // workaround for not updated config.php if (!isset($use_iframe)) { $use_iframe = false; } // If there's no "view_unsafe_images" variable in the URL, turn unsafe // images off by default. sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET, FALSE); $body = ''; $urlmailbox = urlencode($mailbox); $body_message = getEntity($message, $ent_num); if ($body_message->header->type0 == 'text' || $body_message->header->type0 == 'rfc822') { $body = mime_fetch_body($imap_stream, $id, $ent_num); $body = decodeBody($body, $body_message->header->encoding); if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { if (mb_detect_encoding($body) != 'ASCII') { $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $body); } } /* As of 1.5.2, $body is passed (and modified) by reference */ do_hook('message_body', $body); /* If there are other types that shouldn't be formatted, add * them here. */ if ($body_message->header->type1 == 'html') { if ($show_html_default != 1) { $entity_conv = array(' ' => ' ', '<p>' => "\n", '<P>' => "\n", '<br>' => "\n", '<BR>' => "\n", '<br />' => "\n", '<BR />' => "\n", '>' => '>', '<' => '<'); $body = strtr($body, $entity_conv); $body = strip_tags($body); $body = trim($body); translateText($body, $wrap_at, $body_message->header->getParameter('charset')); } elseif ($use_iframe) { /** * If we don't add html message between iframe tags, * we must detect unsafe images and modify $has_unsafe_images. */ $html_body = magicHTML($body, $id, $message, $mailbox); // Convert character set in order to display html mails in different character set $html_body = charset_decode($body_message->header->getParameter('charset'), $html_body, false, true); // creating iframe url $iframeurl = sqm_baseuri() . 'src/view_html.php?' . 'mailbox=' . $urlmailbox . '&passed_id=' . $id . '&ent_id=' . $ent_num . '&view_unsafe_images=' . (int) $view_unsafe_images; global $oTemplate; $oTemplate->assign('iframe_url', $iframeurl); $oTemplate->assign('iframe_height', $iframe_height); $oTemplate->assign('html_body', $html_body); $body = $oTemplate->fetch('read_html_iframe.tpl'); } else { // old way of html rendering /** * convert character set. charset_decode does not remove html special chars * applied by magicHTML functions and does not sanitize them second time if * fourth argument is true. */ $charset = $body_message->header->getParameter('charset'); if (!empty($charset)) { $body = charset_decode($charset, $body, false, true); } $body = magicHTML($body, $id, $message, $mailbox); } } else { translateText($body, $wrap_at, $body_message->header->getParameter('charset')); } /* * Previously the links for downloading and unsafe images were printed * under the mail. By putting the links in a global variable we can * print it in the toolbar where it belongs. Since the original code was * in this place it's left here. It might be possible to move it to some * other place if that makes sense. The possibility to do so has not * been evaluated yet. */ // Initialize the global variable to an empty string. // FIXME: To have $download_and_unsafe_link as a global variable might not be needed since the use of separate variables ($download_href, $unsafe_image_toggle_href, and $unsafe_image_toggle_text) for the templates was introduced. $download_and_unsafe_link = ''; // Prepare and build a link for downloading the mail. $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; } $download_href = SM_PATH . 'src/download.php?absolute_dl=true&' . $link; // Always add the link for downloading the mail as a file to the global // variable. $download_and_unsafe_link .= "{$nbsp}|{$nbsp}" . create_hyperlink($download_href, _("Download this as a file")); // Find out the right text to use in the link depending on the // circumstances. If the unsafe images are displayed the link should // hide them, if they aren't displayed the link should only appear if // the mail really contains unsafe images. if ($view_unsafe_images) { $text = _("Hide Unsafe Images"); } else { if (isset($has_unsafe_images) && $has_unsafe_images) { $link .= '&view_unsafe_images=1'; $text = _("View Unsafe Images"); } else { $text = ''; } } // Only create a link for unsafe images if there's need for one. If so: // add it to the global variable. if ($text != '') { $unsafe_image_toggle_href = SM_PATH . 'src/read_body.php?' . $link; $unsafe_image_toggle_text = $text; $download_and_unsafe_link .= "{$nbsp}|{$nbsp}" . create_hyperlink($unsafe_image_toggle_href, $text); } } return $body; }
/** * This returns a parsed string called $body. That string can then * be displayed as the actual message in the HTML. It contains * everything needed, including HTML Tags, Attachments at the * bottom, etc. */ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $mailbox = 'INBOX', $clean = false) { /* This if statement checks for the entity to show as the * primary message. To add more of them, just put them in the * order that is their priority. */ global $startMessage, $languages, $squirrelmail_language, $show_html_default, $sort, $has_unsafe_images, $passed_ent_id, $username, $key, $imapServerAddress, $imapPort, $download_and_unsafe_link; if (!sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET)) { $view_unsafe_images = false; } $body = ''; $urlmailbox = urlencode($mailbox); $body_message = getEntity($message, $ent_num); if ($body_message->header->type0 == 'text' || $body_message->header->type0 == 'rfc822') { $body = mime_fetch_body($imap_stream, $id, $ent_num); $body = decodeBody($body, $body_message->header->encoding); if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { if (mb_detect_encoding($body) != 'ASCII') { $body = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $body); } } $hookResults = do_hook("message_body", $body); $body = $hookResults[1]; /* If there are other types that shouldn't be formatted, add * them here. */ if ($body_message->header->type1 == 'html') { if ($show_html_default != 1) { $entity_conv = array(' ' => ' ', '<p>' => "\n", '<P>' => "\n", '<br>' => "\n", '<BR>' => "\n", '<br />' => "\n", '<BR />' => "\n", '>' => '>', '<' => '<'); $body = strtr($body, $entity_conv); $body = strip_tags($body); $body = trim($body); translateText($body, $wrap_at, $body_message->header->getParameter('charset')); } else { $charset = $body_message->header->getParameter('charset'); if (!empty($charset)) { $body = charset_decode($charset, $body, false, true); } $body = magicHTML($body, $id, $message, $mailbox); } } else { translateText($body, $wrap_at, $body_message->header->getParameter('charset')); } // if this is the clean display (i.e. printer friendly), stop here. if ($clean) { return $body; } $download_and_unsafe_link = ''; $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; } $download_and_unsafe_link .= ' | <a href="download.php?absolute_dl=true&' . $link . '">' . _("Download this as a file") . '</a>'; if ($view_unsafe_images) { $text = _("Hide Unsafe Images"); } else { if (isset($has_unsafe_images) && $has_unsafe_images) { $link .= '&view_unsafe_images=1'; $text = _("View Unsafe Images"); } else { $text = ''; } } if ($text != '') { $download_and_unsafe_link .= ' | <a href="read_body.php?' . $link . '">' . $text . '</a>'; } } return $body; }
/** * This returns a parsed string called $body. That string can then * be displayed as the actual message in the HTML. It contains * everything needed, including HTML Tags, Attachments at the * bottom, etc. */ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $mailbox = 'INBOX', $clean = false) { /* This if statement checks for the entity to show as the * primary message. To add more of them, just put them in the * order that is their priority. */ global $startMessage, $languages, $squirrelmail_language, $show_html_default, $sort, $has_unsafe_images, $passed_ent_id, $username, $key, $imapServerAddress, $imapPort, $download_and_unsafe_link; // If there's no "view_unsafe_images" variable in the URL, turn unsafe // images off by default. if (!sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET)) { $view_unsafe_images = false; } $body = ''; $urlmailbox = urlencode($mailbox); $body_message = getEntity($message, $ent_num); if ($body_message->header->type0 == 'text' || $body_message->header->type0 == 'rfc822') { $body = mime_fetch_body($imap_stream, $id, $ent_num); $body = decodeBody($body, $body_message->header->encoding); if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { if (mb_detect_encoding($body) != 'ASCII') { $body = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $body); } } $hookResults = do_hook("message_body", $body); $body = $hookResults[1]; /* If there are other types that shouldn't be formatted, add * them here. */ if ($body_message->header->type1 == 'html') { if ($show_html_default != 1) { $entity_conv = array(' ' => ' ', '<p>' => "\n", '<P>' => "\n", '<br>' => "\n", '<BR>' => "\n", '<br />' => "\n", '<BR />' => "\n", '>' => '>', '<' => '<'); $body = strtr($body, $entity_conv); $body = strip_tags($body); $body = trim($body); translateText($body, $wrap_at, $body_message->header->getParameter('charset')); } else { $charset = $body_message->header->getParameter('charset'); if (!empty($charset)) { $body = charset_decode($charset, $body, false, true); } $body = magicHTML($body, $id, $message, $mailbox); } } else { translateText($body, $wrap_at, $body_message->header->getParameter('charset')); } // if this is the clean display (i.e. printer friendly), stop here. if ($clean) { return $body; } /* * Previously the links for downloading and unsafe images were printed * under the mail. By putting the links in a global variable we can * print it in the toolbar where it belongs. Since the original code was * in this place it's left here. It might be possible to move it to some * other place if that makes sense. The possibility to do so has not * been evaluated yet. */ // Initialize the global variable to an empty string. $download_and_unsafe_link = ''; // Prepare and build a link for downloading the mail. $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; } // Always add the link for downloading the mail as a file to the global // variable. $download_and_unsafe_link .= ' | <a href="download.php?absolute_dl=true&' . $link . '">' . _("Download this as a file") . '</a>'; // Find out the right text to use in the link depending on the // circumstances. If the unsafe images are displayed the link should // hide them, if they aren't displayed the link should only appear if // the mail really contains unsafe images. if ($view_unsafe_images) { $text = _("Hide Unsafe Images"); } else { if (isset($has_unsafe_images) && $has_unsafe_images) { $link .= '&view_unsafe_images=1'; $text = _("View Unsafe Images"); } else { $text = ''; } } // Only create a link for unsafe images if there's need for one. If so: // add it to the global variable. if ($text != '') { $download_and_unsafe_link .= ' | <a href="read_body.php?' . $link . '">' . $text . '</a>'; } } return $body; }