Source for file mime.php
Documentation is available at mime.php
* This contains the functions necessary to detect and decode MIME
* @copyright © 1999-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: mime.php,v 1.372 2006/10/06 22:02:52 stevetruckstuff Exp $
class/mime/Message.class.php
functions/page_header.php
functions/display_messages.php
functions/imap_general.php
functions/attachment_common.php
functions/display_messages.php
translateText => url_parser
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
* 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.
/* Isolate the body structure and remove beginning and end parenthesis. */
/* removed urldecode because $_GET is auto urldecoded ??? */
$errormessage =
_("SquirrelMail could not decode the bodystructure of the message");
$errormessage .=
'<br />'.
_("The bodystructure provided by your IMAP server:").
'<br /><br />';
foreach ($flags as $flag) {
$msg->is_answered =
true;
/* This starts the parsing of a particular structure. It is called recursively,
* so it can be passed different structures. It returns an object of type
* First, it checks to see if it is a multipart message. If it is, then it
* handles that as it sees is necessary. If it is just a regular entity,
* then it parses it and adds the necessary header information (by calling out
/* 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.
$cmd =
"FETCH $id BODY[]";
$cmd =
"FETCH $id BODY[$ent_id]";
if ($fetch_size!=
0) $cmd .=
"<0.$fetch_size>";
} while($topline &&
($topline[0] ==
'*') &&
!preg_match('/\* [0-9]+ FETCH.*/i', $topline)) ;
$wholemessage =
implode('', $data);
if (ereg('\\{([^\\}]*)\\}', $topline, $regs)) {
$ret =
substr($wholemessage, 0, $regs[1]);
/* There is some information in the content info header that could be important
* in order to parse html messages. Let's get them here.
// $data = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent_id.MIME]", true, $response, $message, TRUE);
} else if (ereg('"([^"]*)"', $topline, $regs)) {
global $where, $what, $mailbox, $passed_id, $startMessage;
$par =
'mailbox=' .
urlencode($mailbox) .
'&passed_id=' .
$passed_id;
if (isset
($where) && isset
($what)) {
$par .=
'&startMessage=' .
$startMessage .
'&show_more=0';
$par .=
'&response=' .
urlencode($response) .
'<table width="80%"><tr>' .
_("Body retrieval error. The reason for this is most probably that the message is malformed.") .
'<tr><td><b>' .
_("Command:") .
"</td><td>$cmd</td></tr>" .
'<tr><td><b>' .
_("Response:") .
"</td><td>$response</td></tr>" .
'<tr><td><b>' .
_("Message:") .
"</td><td>$message</td></tr>" .
'<tr><td><b>' .
_("FETCH line:") .
"</td><td>$topline</td></tr>" .
"</table><br /></tt></font><hr />";
$data =
sqimap_run_command ($imap_stream, "FETCH $passed_id BODY[]", true, $response, $message, TRUE);
$wholemessage =
implode('', $data);
/* Don't kill the connection if the browser is over a dialup
* and it would take over 30 seconds to download it.
* Don't call set_time_limit in safe mode.
/* in case of base64 encoded attachments, do not buffer them.
Instead, echo the decoded attachment directly to screen */
$query =
"FETCH $id BODY[]";
$query =
"FETCH $id BODY[$ent_id]";
sqimap_run_command($imap_stream,$query,true,$response,$message,TRUE,'sqimap_base64_decode',$rStream,true);
TODO, use the same method for quoted printable.
However, I assume that quoted printable attachments aren't that large
so the performancegain / memory usage drop will be minimal.
If we decide to add that then we need to adapt sqimap_fread because
we need to split te result on \n and fread doesn't stop at \n. That
means we also should provide $results from sqimap_fread (by ref) to
te function and set $no_return to false. The $filter function for
quoted printable should handle unsetting of $results.
TODO 2: find out how we write to the output stream php://stdout. fwrite
doesn't work because 'php://stdout isn't a stream.
/* -[ END MIME DECODING ]----------------------------------------------------------- */
/* This is here for debugging purposes. It will print out a list
* of all the entity IDs that are in the $message object.
echo
"<tt>" .
$message->entity_id .
' : ' .
$message->type0 .
'/' .
$message->type1 .
' parent = '.
$message->parent->entity_id.
'<br />';
for ($i =
0; isset
($message->entities[$i]); $i++
) {
$priority_level =
substr($priority,0,1);
switch($priority_level) {
/* Check for a higher then normal priority. */
$priority_string =
_("High");
/* Check for a lower then normal priority. */
$priority_string =
_("Low");
/* Check for a normal priority. */
$priority_string =
_("Normal");
/* returns a $message object for a particular entity id */
* Extracted from strings.php 23/03/2002
global $where, $what; /* from searching */
global $color; /* color theme */
// require_once(SM_PATH . 'functions/url_parser.php');
for ($i=
0; $i <
count($body_ary); $i++
) {
if (strlen($line) -
2 >=
$wrap_at) {
if ($line[$pos] ==
' ') {
} else if (strpos($line, '>', $pos) ===
$pos) {
$line =
'<span class="quote1">' .
$line .
'</style>';
$line =
'<span class="quote2">' .
$line .
'</style>';
$body =
'<pre>' .
implode("\n", $body_ary) .
'</pre>';
* 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
* 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
* @param boolean $clean (since 1.5.1) Do not output stuff that's irrelevant for the printable version.
* @return string html formated message text
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,
$use_iframe, $iframe_height, $download_and_unsafe_link,
$download_href, $unsafe_image_toggle_href, $unsafe_image_toggle_text;
// workaround for not updated config.php
if (! isset
($use_iframe)) $use_iframe =
false;
$view_unsafe_images =
false;
$body_message =
getEntity($message, $ent_num);
if (($body_message->header->type0 ==
'text') ||
($body_message->header->type0 ==
'rfc822')) {
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);
$hookResults =
do_hook("message_body", $body);
/* If there are other types that shouldn't be formatted, add
if ($body_message->header->type1 ==
'html') {
if ($show_html_default <>
1) {
$entity_conv =
array(' ' =>
' ',
$body =
strtr($body, $entity_conv);
$body_message->header->getParameter('charset'));
} elseif ($use_iframe &&
! $clean) {
// $clean is used to remove iframe in printable view.
* 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
.
'mailbox=' .
$urlmailbox
.
'&passed_id=' .
$id
.
'&ent_id=' .
$ent_num
.
'&view_unsafe_images=' . (int)
$view_unsafe_images;
// adding warning message
$body =
html_tag('div',_("Viewing HTML formatted email"),'center');
* height can't be set to 100%, because it does not work as expected when
* iframe is inside the table. Browsers do not create full height objects
* even when iframe is not nested. Maybe there is some way to get full size
* with CSS. Tested in firefox 1.02 and opera 7.53
* width="100%" does not work as expected, when table width is not set (automatic)
* tokul: I think <iframe> are safer sandbox than <object>. Objects might
* need special handling for IE and IE6SP2.
$body.=
"<div><iframe name=\"message_frame\" width=\"100%\" height=\"$iframe_height\" src=\"$iframeurl\""
.
' frameborder="1" marginwidth="0" marginheight="0" scrolling="auto">' .
"\n";
// Message for browsers without iframe support
//$body.= _("Your browser does not support inline frames.
// You can view HTML formated message by following below link.");
//$body.= "<br /><a href=\"$iframeurl\">"._("View HTML Message")."</a>";
// if browser can't render iframe, it renders html message.
$body.=
"</iframe></div>\n";
// old way of html rendering
$body =
magicHTML($body, $id, $message, $mailbox);
* 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.
$body_message->header->getParameter('charset'));
// if this is the clean display (i.e. printer friendly), stop here.
$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_href =
SM_PATH .
'src/download.php?absolute_dl=true&' .
$link;
$download_and_unsafe_link .=
' | <a href="'.
$download_href .
'">' .
_("Download this as a file") .
'</a>';
if ($view_unsafe_images) {
$text =
_("Hide Unsafe Images");
if (isset
($has_unsafe_images) &&
$has_unsafe_images) {
$link .=
'&view_unsafe_images=1';
$text =
_("View Unsafe Images");
$unsafe_image_toggle_href =
SM_PATH .
'src/read_body.php?'.
$link;
$unsafe_image_toggle_text =