Updating strings
[squirrelmail.git] / functions / mime.php
index f642133ec7bde39cc671be78ff689cfef6746b68..f7c3379d67b4c881a1f321161a5014887be6ab04 100644 (file)
@@ -23,7 +23,7 @@ require_once(SM_PATH . 'functions/attachment_common.php');
 
 /**
  * Get the MIME structure
- * 
+ *
  * 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.
@@ -163,7 +163,7 @@ function mime_print_body_lines ($imap_stream, $id, $ent_id=1, $encoding) {
 
     /* 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.
+     * Dont call set_time_limit in safe mode.
      */
 
     if (!ini_get('safe_mode')) {
@@ -393,12 +393,14 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $ma
             translateText($body, $wrap_at,
                           $body_message->header->getParameter('charset'));
         }
-        $link = 'read_body.php?passed_id=' . $id . '&ent_id='.$ent_num.
+        $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;
         }
+        $body .= '<center><small><a href="download.php?absolute_dl=true&amp;' . 
+                 $link . '">' . _("Download this as a file") .  '</a>';
         if ($view_unsafe_images) {
             $text = _("Hide Unsafe Images");
         } else {
@@ -409,8 +411,10 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $ma
                 $text = '';
             }
         }
-        $body .= '<center><small><a href="'.$link.'">'.$text.
-                 '</a></small></center><br>' . "\n";
+        if($text != '') {
+            $body .= '&nbsp;|&nbsp;<a href="read_body.php?' . $link . '">' . $text . '</a>';
+        }
+        $body .= '</small></center><br>' . "\n";
     }
     return $body;
 }
@@ -614,7 +618,7 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) {
         $encoded = false;
         /* if encoded words are not separated by a linear-space-white we still catch them */
         $j = $i-1;
-//  if ($chunk{0} === '=') { /* performance, saves an unnessecarry preg call */
+
         while ($match = preg_match('/^(.*)=\?([^?]*)\?(Q|B)\?([^?]*)\?=(.*)$/Ui',$chunk,$res)) {
             /* if the last chunk isn't an encoded string then put back the space, otherwise don't */
             if ($iLastMatch !== $j) {
@@ -656,7 +660,6 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) {
             $chunk = $res[5];
             $encoded = true;
         }
-//  }
         if (!$encoded) {
             if ($htmlsave) {
                 $ret .= '&nbsp;';
@@ -854,6 +857,7 @@ function sq_unbackslash($attvalue){
     /**
      * Remove any backslashes. See if there are any first.
      */
+
     if (strstr($attvalue, '\\') !== false){
         $attvalue = stripslashes($attvalue);
     }
@@ -1286,13 +1290,14 @@ function sq_getnxtag($body, $offset){
  * @param  $attvalue A string to run entity check against.
  * @return           Translated value.
  */
+
 function sq_deent($attvalue){
     $me = 'sq_deent';
     /**
      * See if we have to run the checks first. All entities must start
      * with "&".
      */
-    if (strpos($attvalue, "&") === false){
+    if (strpos($attvalue, '&') === false){
         return $attvalue;
     }
     /**
@@ -1303,22 +1308,22 @@ function sq_deent($attvalue){
      * Leave &quot; in, as it can mess us up.
      */
     $trans = array_flip($trans);
-    unset($trans{"&quot;"});
+    unset($trans{'&quot;'});
     while (list($ent, $val) = each($trans)){
-        $attvalue = preg_replace("/$ent*(\W)/si", "$val\\1", $attvalue);
+        $attvalue = preg_replace('/' . $ent . '*/si', $val, $attvalue);
     }
     /**
      * Now translate numbered entities from 1 to 255 if needed.
      */
-    if (strpos($attvalue, "#") !== false){
+    if (strpos($attvalue, '#') !== false){
         $omit = Array(34, 39);
-        for ($asc=1; $asc<256; $asc++){
+        for ($asc = 256; $asc >= 0; $asc--){
             if (!in_array($asc, $omit)){
                 $chr = chr($asc);
-                $attvalue = preg_replace("/\&#0*$asc;*(\D)/si", "$chr\\1",
-                                         $attvalue);
-                $attvalue = preg_replace("/\&#x0*".dechex($asc).";*(\W)/si",
-                                         "$chr\\1", $attvalue);
+                $octrule = '/\&#0*' . $asc . ';*/si';
+                $hexrule = '/\&#x0*' . dechex($asc) . ';*/si';
+                $attvalue = preg_replace($octrule, $chr, $attvalue);
+                $attvalue = preg_replace($hexrule, $chr, $attvalue);
             }
         }
     }
@@ -1418,9 +1423,10 @@ function sq_fixatts($tagname,
  * @param  $message  the message object
  * @param  $id       the message id
  * @param  $content  a string with whatever is between <style> and </style>
+ * @param  $mailbox  the message mailbox
  * @return           a string with edited content.
  */
-function sq_fixstyle($body, $pos, $message, $id){
+function sq_fixstyle($body, $pos, $message, $id, $mailbox){
     global $view_unsafe_images;
     $me = 'sq_fixstyle';
     $ret = sq_findnxreg($body, $pos, '</\s*style\s*>');
@@ -1457,7 +1463,7 @@ function sq_fixstyle($body, $pos, $message, $id){
     while (preg_match("|url\s*\(\s*([\'\"]\s*cid:.*?[\'\"])\s*\)|si",
                       $content, $matches)){
         $cidurl = $matches{1};
-        $httpurl = sq_cid2http($message, $id, $cidurl);
+        $httpurl = sq_cid2http($message, $id, $cidurl, $mailbox);
         $content = preg_replace("|url\s*\(\s*$cidurl\s*\)|si",
                                 "url($httpurl)", $content);
     }
@@ -1482,6 +1488,7 @@ function sq_fixstyle($body, $pos, $message, $id){
  * @param  $message  the message object
  * @param  $id       the message id
  * @param  $cidurl   the cid: url.
+ * @param  $mailbox  the message mailbox
  * @return           a string with a http-friendly url
  */
 function sq_cid2http($message, $id, $cidurl, $mailbox){
@@ -1619,7 +1626,7 @@ function sq_sanitize($body,
          */
         if ($tagname == "style" && $tagtype == 1){
             list($free_content, $curpos) =
-                sq_fixstyle($body, $gt+1, $message, $id);
+                sq_fixstyle($body, $gt+1, $message, $id, $mailbox);
             if ($free_content != FALSE){
                 $trusted .= sq_tagprint($tagname, $attary, $tagtype);
                 $trusted .= $free_content;
@@ -1897,9 +1904,10 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX') {
  * @param string $type1 second half of mime type
  * @param string $filename filename to tell the browser for downloaded file
  * @param boolean $force whether to force the download dialog to pop
+ * @param integer $filesize optional, send the Content-Header and length to the browser
  * @return void
  */
- function SendDownloadHeaders($type0, $type1, $filename, $force) {
+ function SendDownloadHeaders($type0, $type1, $filename, $force, $filesize=0) {
      global $languages, $squirrelmail_language;
      $isIE = $isIE6 = 0;
 
@@ -1960,6 +1968,12 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX') {
              header("Content-Type: application/octet-stream; name=\"$filename\"");
          }
      }
- }
+
+     //send the content-length header if the calling function provides it
+     if ($filesize > 0) {
+        header("Content-Length: $filesize");
+     }
+
+ }  // end fn SendDownlaodHeaders
 
 ?>