From c189a9636981d340246670a156f85de3a7bce40f Mon Sep 17 00:00:00 2001 From: stekkel Date: Wed, 15 Jun 2005 23:11:56 +0000 Subject: [PATCH] Put back old 1.5.1 functionality after the rest of magicHtml was synced with stable. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@9618 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mime.php | 73 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/functions/mime.php b/functions/mime.php index 9e4f00a9..af426110 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -1702,8 +1702,8 @@ function sq_cid2http($message, $id, $cidurl, $mailbox){ function sq_body2div($attary, $mailbox, $message, $id){ $me = 'sq_body2div'; $divattary = Array('class' => "'bodyclass'"); - $bgcolor = '#ffffff'; $text = '#000000'; + $has_bgc_stl = $has_txt_stl = false; $styledef = ''; if (is_array($attary) && sizeof($attary) > 0){ foreach ($attary as $attname=>$attvalue){ @@ -1715,13 +1715,20 @@ function sq_body2div($attary, $mailbox, $message, $id){ $styledef .= "background-image: url('$attvalue'); "; break; case 'bgcolor': + $has_bgc_stl = true; $styledef .= "background-color: $attvalue; "; break; case 'text': + $has_txt_stl = true; $styledef .= "color: $attvalue; "; break; } } + // Outlook defines a white bgcolor and no text color. This can lead to + // white text on a white bg with certain themes. + if ($has_bgc_stl && !$has_txt_stl) { + $styledef .= "color: $text; "; + } if (strlen($styledef) > 0){ $divattary{"style"} = "\"$styledef\""; } @@ -1909,9 +1916,18 @@ function sq_sanitize($body, * * @param $body the body of the message * @param $id the id of the message + + * @param $message + * @param $mailbox + * @param boolean $take_mailto_links When TRUE, converts mailto: links + * into internal SM compose links + * (optional; default = TRUE) * @return a string with html safe to display in the browser. */ -function magicHTML($body, $id, $message, $mailbox = 'INBOX') { +function magicHTML($body, $id, $message, $mailbox = 'INBOX', $take_mailto_links =true) { + + require_once(SM_PATH . 'functions/url_parser.php'); // for $MailTo_PReg_Match + global $attachment_common_show_images, $view_unsafe_images, $has_unsafe_images; /** @@ -2063,6 +2079,59 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX') { if (preg_match("|$secremoveimg|i", $trusted)){ $has_unsafe_images = true; } + + // we want to parse mailto's in HTML output, change to SM compose links + // this is a modified version of code from url_parser.php... but Marc is + // right: we need a better filtering implementation; adding this randomly + // here is not a great solution + // + if ($take_mailto_links) { + // parseUrl($trusted); // this even parses URLs inside of tags... too aggressive + global $MailTo_PReg_Match; + $MailTo_PReg_Match = '/mailto:' . substr($MailTo_PReg_Match, 1); + if ((preg_match_all($MailTo_PReg_Match, $trusted, $regs)) && ($regs[0][0] != '')) { + foreach ($regs[0] as $i => $mailto_before) { + $mailto_params = $regs[10][$i]; + // get rid of any tailing quote since we have to add send_to to the end + // + if (substr($mailto_before, strlen($mailto_before) - 1) == '"') + $mailto_before = substr($mailto_before, 0, strlen($mailto_before) - 1); + if (substr($mailto_params, strlen($mailto_params) - 1) == '"') + $mailto_params = substr($mailto_params, 0, strlen($mailto_params) - 1); + + if ($regs[1][$i]) { //if there is an email addr before '?', we need to merge it with the params + $to = 'to=' . $regs[1][$i]; + if (strpos($mailto_params, 'to=') > -1) //already a 'to=' + $mailto_params = str_replace('to=', $to . '%2C%20', $mailto_params); + else { + if ($mailto_params) //already some params, append to them + $mailto_params .= '&' . $to; + else + $mailto_params .= '?' . $to; + } + } + + $url_str = preg_replace(array('/to=/i', '/(?