From df8e8ec9eee72743d0f14a8409aacf66c4a80d89 Mon Sep 17 00:00:00 2001
From: yllar <yllar.pajus@gmail.com>
Date: Mon, 11 Dec 2006 12:09:34 -0500
Subject: [PATCH] updated da, de_DE, pt_BR, bs_BA, fr, pl, et_EE translations

---
 program/steps/mail/func.inc |  314 +++++++++++++++++++++++++---------------------------
 1 files changed, 150 insertions(+), 164 deletions(-)

diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index cbe4559..9bda890 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -79,6 +79,7 @@
 
   // add some labels to client
   rcube_add_label('purgefolderconfirm');
+  rcube_add_label('deletemessagesconfirm');
   
 // $mboxlist_start = rcube_timer();
   
@@ -214,7 +215,7 @@
     else if ($folder['id']==$CONFIG['junk_mbox'])
       $class_name = 'junk';
 
-    $js_name = rep_specialchars_output($folder['id'], 'js');
+    $js_name = htmlspecialchars(rep_specialchars_output($folder['id'], 'js'));
     $out .= sprintf('<li id="rcmbx%s" class="mailbox %s %s%s%s"><a href="%s&amp;_mbox=%s"'.
                     ' onclick="return %s.command(\'list\',\'%s\')"'.
                     ' onmouseover="return %s.focus_mailbox(\'%s\')"' .            
@@ -271,7 +272,7 @@
       }
 
     $out .= sprintf('<option value="%s">%s%s</option>'."\n",
-                    $folder['id'],
+                    htmlspecialchars($folder['id']),
                     str_repeat('&nbsp;', $nestLevel*4),
                     rep_specialchars_output($foldername, 'html', 'all'));
 
@@ -495,6 +496,7 @@
   $javascript .= sprintf("%s.set_env('messages', %s);", $JS_OBJECT_NAME, array2js($a_js_message_arr));
   
   $OUTPUT->add_script($javascript);  
+  $OUTPUT->include_script('list.js');
   
   return $out;
   }
@@ -511,8 +513,8 @@
   $a_show_cols = is_array($CONFIG['list_cols']) ? $CONFIG['list_cols'] : array('subject');
 
   // show 'to' instead of from in sent messages
-  if (strtolower($IMAP->get_mailbox_name())=='sent' && ($f = array_search('from', $a_show_cols))
-      && !array_search('to', $a_show_cols))
+  if (($IMAP->get_mailbox_name()==$CONFIG['sent_mbox'] || $IMAP->get_mailbox_name()==$CONFIG['drafts_mbox'])
+      && ($f = array_search('from', $a_show_cols)) && !array_search('to', $a_show_cols))
     $a_show_cols[$f] = 'to';
 
   $commands .= sprintf("this.set_message_coltypes(%s);\n", array2js($a_show_cols)); 
@@ -555,6 +557,27 @@
   return $commands;
   }
 
+
+// return an HTML iframe for loading mail content
+function rcmail_messagecontent_frame($attrib)
+  {
+  global $OUTPUT, $JS_OBJECT_NAME;
+  
+  if (empty($attrib['id']))
+    $attrib['id'] = 'rcmailcontentwindow';
+
+  // allow the following attributes to be added to the <iframe> tag
+  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
+  $framename = $attrib['id'];
+
+  $out = sprintf('<iframe name="%s"%s></iframe>'."\n",
+         $framename,
+         $attrib_str);
+
+  $OUTPUT->add_script("$JS_OBJECT_NAME.set_env('contentframe', '$framename');");
+
+  return $out;
+  }
 
 // return code for search function
 function rcmail_search_form($attrib)
@@ -611,7 +634,7 @@
 
 function rcmail_quota_display($attrib)
   {
-  global $IMAP, $OUTPUT, $JS_OBJECT_NAME;
+  global $IMAP, $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH;
 
   if (!$attrib['id'])
     $attrib['id'] = 'rcmquotadisplay';
@@ -620,11 +643,33 @@
 
   // allow the following attributes to be added to the <span> tag
   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
-  
+
   if (!$IMAP->get_capability('QUOTA'))
     $quota_text = rcube_label('unknown');
-  else if (!($quota_text = $IMAP->get_quota()))
+  else if ($quota = $IMAP->get_quota())
+    {
+    $quota_text = sprintf("%s / %s (%.0f%%)",
+                          show_bytes($quota["used"] * 1024),
+                          show_bytes($quota["total"] * 1024),
+                          $quota["percent"]);
+
+    // show quota as image (by Brett Patterson)
+    if ($attrib['display'] == 'image' && function_exists('imagegif'))
+      {
+      $attrib += array('width' => 100, 'height' => 14);
+      $quota_text = sprintf('<img src="%s&amp;_action=quotaimg&amp;u=%s&amp;q=%d&amp;w=%d&amp;h=%d" width="%d" height="%d" alt="%s" title="%s / %s" />',
+                            $COMM_PATH,
+                            $quota['used'], $quota['total'],
+                            $attrib['width'], $attrib['height'],
+                            $attrib['width'], $attrib['height'],
+                            $quota_text,
+                            show_bytes($quota["used"] * 1024),
+                            show_bytes($quota["total"] * 1024));
+      }
+    }
+  else
     $quota_text = rcube_label('unlimited');
+    
 
   $out = '<span' . $attrib_str . '>';
   $out .= $quota_text;
@@ -667,24 +712,27 @@
   global $IMAP, $REMOTE_OBJECTS, $JS_OBJECT_NAME;
   
   $body = is_array($part->replaces) ? strtr($part->body, $part->replaces) : $part->body;
-  
+
   // text/html
   if ($part->ctype_secondary=='html')
     {
+    // remove charset specification in HTML message
+    $body = preg_replace('/charset=[a-z0-9\-]+/i', '', $body);
+
     if (!$safe)  // remove remote images and scripts
       {
-      $remote_patterns = array('/(src|background)=(["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)(\2|\s|>)/Ui',
-                           //  '/(src|background)=(["\']?)([\.\/]+[^"\'\s]+)(\2|\s|>)/Ui',
+      $remote_patterns = array('/<img\s+(.*)src=(["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)(\2|\s|>)/Ui',
+                               '/(src|background)=(["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)(\2|\s|>)/Ui',
                                '/(<base.*href=["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)([^<]*>)/i',
                                '/(<link.*href=["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)([^<]*>)/i',
                                '/url\s*\(["\']?([hftps]{3,5}:\/{2}[^"\'\s]+)["\']?\)/i',
                                '/url\s*\(["\']?([\.\/]+[^"\'\s]+)["\']?\)/i',
                                '/<script.+<\/script>/Umis');
 
-      $remote_replaces = array('',  // '\\1=\\2#\\4',
-                            // '\\1=\\2#\\4',
+      $remote_replaces = array('<img \\1src=\\2./program/blank.gif\\4',
                                '',
-                               '',  // '\\1#\\3',
+                               '',
+                               '',
                                'none',
                                'none',
                                '');
@@ -715,7 +763,7 @@
     // make links and email-addresses clickable
     $convert_patterns = $convert_replaces = $replace_strings = array();
     
-    $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:';
+    $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:;';
     $url_chars_within = '\?\.~,!';
 
     $convert_patterns[] = "/([\w]+):\/\/([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/ie";
@@ -726,39 +774,44 @@
     
     $convert_patterns[] = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/ie';
     $convert_replaces[] = "rcmail_str_replacement('<a href=\"mailto:\\1\" onclick=\"return $JS_OBJECT_NAME.command(\'compose\',\'\\1\',this)\">\\1</a>', \$replace_strings)";
+    
+    if ($part->ctype_parameters['format'] != 'flowed')
+      $body = wordwrap(trim($body), 80);
 
-    $body = wordwrap(trim($body), 80);
     $body = preg_replace($convert_patterns, $convert_replaces, $body);
 
     // split body into single lines
     $a_lines = preg_split('/\r?\n/', $body);
+    $quote_level = 0;
 
     // colorize quoted parts
     for($n=0; $n<sizeof($a_lines); $n++)
       {
       $line = $a_lines[$n];
+      $quotation = '';
+      $q = 0;
+      
+      if (preg_match('/^(>+\s*)/', $line, $regs))
+        {
+        $q = strlen(preg_replace('/\s/', '', $regs[1]));
+        $line = substr($line, strlen($regs[1]));
 
-      if ($line{2}=='>')
-        $color = 'red';
-      else if ($line{1}=='>')
-        $color = 'green';
-      else if ($line{0}=='>')
-        $color = 'blue';
-      else
-        $color = FALSE;
+        if ($q > $quote_level)
+          $quotation = str_repeat('<blockquote>', $q - $quote_level);
+        else if ($q < $quote_level)
+          $quotation = str_repeat("</blockquote>", $quote_level - $q);
+        }
+      else if ($quote_level > 0)
+        $quotation = str_repeat("</blockquote>", $quote_level);
 
-      $line = rep_specialchars_output($line, 'html', 'replace', FALSE);
-        
-      if ($color)
-        $a_lines[$n] = sprintf('<font color="%s">%s</font>', $color, $line);
-      else
-        $a_lines[$n] = $line;
+      $quote_level = $q;
+      $a_lines[$n] = $quotation . rep_specialchars_output($line, 'html', 'replace', FALSE);
       }
 
     // insert the links for urls and mailtos
     $body = preg_replace("/##string_replacement\{([0-9]+)\}##/e", "\$replace_strings[\\1]", join("\n", $a_lines));
     
-    return "<pre>\n".$body."\n</pre>";
+    return "<div class=\"pre\">".$body."\n</div>";
     }
   }
 
@@ -939,7 +992,7 @@
       $a_replaces = array();
         
       foreach ($sa_inline_objects as $inline_object)
-        $a_replaces['cid:'.$inline_object->content_id] = sprintf($get_url, $inline_object->mime_id);
+        $a_replaces['cid:'.$inline_object->content_id] = htmlspecialchars(sprintf($get_url, $inline_object->mime_id));
       
       // add replace array to each content part
       // (will be applied later when part body is available)
@@ -1052,12 +1105,12 @@
       else if ($part->type=='content')
         {
         if (empty($part->ctype_parameters) || empty($part->ctype_parameters['charset']))
-          $$part->ctype_parameters['charset'] = $MESSAGE['headers']->charset;
-         
+          $part->ctype_parameters['charset'] = $MESSAGE['headers']->charset;
+
         // fetch part if not available
         if (!isset($part->body))
           $part->body = $IMAP->get_message_part($MESSAGE['UID'], $part->mime_id, $part);
-        
+
         $body = rcmail_print_body($part, $safe_mode);
         $out .= '<div class="message-part">';
         
@@ -1084,8 +1137,8 @@
     foreach ($MESSAGE['attachments'] as $attach_prop)
       {
       if (strpos($attach_prop->mimetype, 'image/')===0)
-        $out .= sprintf("\n<hr />\n<p align=\"center\"><img src=\"%s&_part=%s\" alt=\"%s\" title=\"%s\" /></p>\n",
-                        $GET_URL, $attach_prop->mime_id,
+        $out .= sprintf("\n<hr />\n<p align=\"center\"><img src=\"%s&amp;_part=%s\" alt=\"%s\" title=\"%s\" /></p>\n",
+                        htmlspecialchars($GET_URL), $attach_prop->mime_id,
                         $attach_prop->filename,
                         $attach_prop->filename);
       }
@@ -1113,15 +1166,12 @@
   // find STYLE tags
   while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos)))
     {
-    $pos2 += 8;
-    $body_pre = substr($body, 0, $pos);
-    $styles = substr($body, $pos, $pos2-$pos);
-    $body_post = substr($body, $pos2, strlen($body)-$pos2);
-    
+    $pos = strpos($body_lc, '>', $pos)+1;
+
     // replace all css definitions with #container [def]
-    $styles = rcmail_mod_css_styles($styles, $container_id);
-    
-    $body = $body_pre . $styles . $body_post;
+    $styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos), $container_id);
+
+    $body = substr($body, 0, $pos) . $styles . substr($body, $pos2);    
     $last_style_pos = $pos2;
     }
 
@@ -1160,13 +1210,13 @@
                             '/(<\/?meta[^>]*>)/i'),
                       '<!--\\1-->',
                       $body);
-                      
+
   $out = preg_replace(array('/(<body[^>]*>)/i',
                             '/(<\/body>)/i'),
                       array('<div class="rcmBody">',
                             '</div>'),
                       $out);
-  
+
   return $out;
   }
 
@@ -1212,15 +1262,65 @@
   }
 
 
+function rcmail_has_html_part($message_parts)
+{
+   if (!is_array($message_parts))
+      return FALSE;
 
-// return first text part of a message
-function rcmail_first_text_part($message_struct)
+   // check all message parts
+   foreach ($message_parts as $pid => $part)
+   {
+      $mimetype = strtolower($part->ctype_primary.'/'.$part->ctype_secondary);
+      if ($mimetype=='text/html')
+      {
+         return TRUE;
+      }
+   }
+    
+   return FALSE;
+}
+
+// return first HTML part of a message
+function rcmail_first_html_part($message_struct)
   {
   global $IMAP;
 
   if (!is_array($message_struct['parts']))
     return FALSE;
     
+  $html_part = NULL;
+
+  // check all message parts
+  foreach ($message_struct['parts'] as $pid => $part)
+    {
+    $mimetype = strtolower($part->ctype_primary.'/'.$part->ctype_secondary);
+    if ($mimetype=='text/html')
+      {
+      $html_part = $IMAP->get_message_part($message_struct['UID'], $pid, $part);
+      }
+    }
+
+  if ($html_part)
+    {
+    // remove special chars encoding
+    //$trans = array_flip(get_html_translation_table(HTML_ENTITIES));
+    //$html_part = strtr($html_part, $trans);
+
+    return $html_part;
+    }
+
+  return FALSE;
+}
+
+
+// return first text part of a message
+function rcmail_first_text_part($message_struct)
+  {
+  global $IMAP;
+
+  if (empty($message_struct['parts']))
+    return $message_struct['UID'] ? $IMAP->get_body($message_struct['UID']) : false;
+
   // check all message parts
   foreach ($message_struct['parts'] as $pid => $part)
     {
@@ -1244,94 +1344,6 @@
     }
 
   return FALSE;
-  }
-
-
-// get source code of a specific message and cache it
-// deprecated
-function rcmail_message_source($uid)
-  {
-  global $IMAP, $DB, $CONFIG;
-
-  // get message ID if uid is given
-  $cache_key = $IMAP->mailbox.'.msg';
-  $cached = $IMAP->get_cached_message($cache_key, $uid, FALSE);
-  
-  // message is cached in database
-  if ($cached && !empty($cached->body))
-    return $cached->body;
-
-  if (!$cached)
-    $headers = $IMAP->get_headers($uid);
-  else
-    $headers = &$cached;
-
-  // create unique identifier based on message_id
-  if (!empty($headers->messageID))
-    $message_id = md5($headers->messageID);
-  else
-    $message_id = md5($headers->uid.'@'.$_SESSION['imap_host']);
-  
-  $temp_dir = $CONFIG['temp_dir'].(!eregi('\/$', $CONFIG['temp_dir']) ? '/' : '');
-  $cache_dir = $temp_dir.$_SESSION['client_id'];
-  $cache_path = $cache_dir.'/'.$message_id;
-
-  // message is cached in temp dir
-  if ($CONFIG['enable_caching'] && is_dir($cache_dir) && is_file($cache_path))
-    {
-    if ($fp = fopen($cache_path, 'r'))
-      {
-      $msg_source = fread($fp, filesize($cache_path));
-      fclose($fp);
-      return $msg_source;
-      }
-    }
-
-
-  // get message from server
-  $msg_source = $IMAP->get_raw_body($uid);
-  
-  // return message source without caching
-  if (!$CONFIG['enable_caching'])
-    return $msg_source;
-
-
-  // let's cache the message body within the database
-  if ($cached && ($CONFIG['db_max_length'] -300) > $headers->size)
-    {
-    $DB->query("UPDATE ".get_table_name('messages')."
-                SET    body=?
-                WHERE  user_id=?
-                AND    cache_key=?
-                AND    uid=?",
-               $msg_source,
-               $_SESSION['user_id'],
-               $cache_key,
-               $uid);
-
-    return $msg_source;
-    }
-
-
-  // create dir for caching
-  if (!is_dir($cache_dir))
-    $dir = mkdir($cache_dir);
-  else
-    $dir = true;
-
-  // attempt to write a file with the message body    
-  if ($dir && ($fp = fopen($cache_path, 'w')))
-    {
-    fwrite($fp, $msg_source);
-    fclose($fp);
-    }
-  else
-    {
-    raise_error(array('code' => 403, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__, 
-                      'message' => "Failed to write to temp dir"), TRUE, FALSE);
-    }
-
-  return $msg_source;
   }
 
 
@@ -1412,7 +1424,7 @@
     {
     $out .= sprintf('<tr><td class="title">%s</td><td>%s</td><td>[<a href="./?%s">%s</a>]</tr>'."\n",
                     rcube_label('filename'),
-                    rep_specialchars_output($filename),
+                    rep_specialchars_output(rcube_imap::decode_mime_string($filename)),
                     str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']),
                     rcube_label('download'));
     }
@@ -1445,42 +1457,16 @@
   }
 
 
-// create temp dir for attachments
-function rcmail_create_compose_tempdir()
-  {
-  global $CONFIG;
-  
-  if ($_SESSION['compose']['temp_dir'])
-    return $_SESSION['compose']['temp_dir'];
-  
-  if (!empty($CONFIG['temp_dir']))
-    $temp_dir = $CONFIG['temp_dir'].(!eregi('\/$', $CONFIG['temp_dir']) ? '/' : '').$_SESSION['compose']['id'];
-
-  // create temp-dir for uploaded attachments
-  if (!empty($CONFIG['temp_dir']) && is_writeable($CONFIG['temp_dir']))
-    {
-    mkdir($temp_dir);
-    $_SESSION['compose']['temp_dir'] = $temp_dir;
-    }
-
-  return $_SESSION['compose']['temp_dir'];
-  }
-
-
 // clear message composing settings
 function rcmail_compose_cleanup()
   {
   if (!isset($_SESSION['compose']))
     return;
-  
+
   // remove attachment files from temp dir
   if (is_array($_SESSION['compose']['attachments']))
     foreach ($_SESSION['compose']['attachments'] as $attachment)
       @unlink($attachment['path']);
-
-  // kill temp dir
-  if ($_SESSION['compose']['temp_dir'])
-    @rmdir($_SESSION['compose']['temp_dir']);
   
   unset($_SESSION['compose']);
   }

--
Gitblit v1.9.1