thomascube
2006-12-23 853b2e734139aa7fcd97fd931803808bdad201bd
program/steps/mail/func.inc
@@ -51,7 +51,11 @@
  $_SESSION['sort_col'] = $CONFIG['message_sort_col'];
if (!isset($_SESSION['sort_order']))
  $_SESSION['sort_order'] = $CONFIG['message_sort_order'];
// set message set for search result
if (!empty($_GET['_search']) && isset($_SESSION['search'][$_GET['_search']]))
  $IMAP->set_search_set($_SESSION['search'][$_GET['_search']]);
// define url for getting message parts
if (strlen($_GET['_uid']))
@@ -193,7 +197,7 @@
        {
        $fname = abbrevate_string($foldername, $maxlength);
        if ($fname != $foldername)
          $title = ' title="'.rep_specialchars_output($foldername, 'html', 'all').'"';
          $title = ' title="'.Q($foldername).'"';
        $foldername = $fname;
        }
      }
@@ -215,7 +219,7 @@
    else if ($folder['id']==$CONFIG['junk_mbox'])
      $class_name = 'junk';
    $js_name = htmlspecialchars(rep_specialchars_output($folder['id'], 'js'));
    $js_name = htmlspecialchars(JQ($folder['id']));
    $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\')"' .            
@@ -237,7 +241,7 @@
                    $JS_OBJECT_NAME,
                    $js_name,
                    $title,
                    rep_specialchars_output($foldername, 'html', 'all'));
                    Q($foldername));
    if (!empty($folder['folders']))
      $out .= "\n<ul>\n" . rcmail_render_folder_tree_html($folder['folders'], $special, $mbox_name, $maxlength, $nestLevel+1) . "</ul>\n";
@@ -274,7 +278,7 @@
    $out .= sprintf('<option value="%s">%s%s</option>'."\n",
                    htmlspecialchars($folder['id']),
                    str_repeat('&nbsp;', $nestLevel*4),
                    rep_specialchars_output($foldername, 'html', 'all'));
                    Q($foldername));
    if (!empty($folder['folders']))
      $out .= rcmail_render_folder_tree_select($folder['folders'], $special, $mbox_name, $maxlength, $nestLevel+1);
@@ -340,7 +344,7 @@
  foreach ($a_show_cols as $col)
    {
    // get column name
    $col_name = rep_specialchars_output(rcube_label($col));
    $col_name = Q(rcube_label($col));
    // make sort links
    $sort = '';
@@ -394,10 +398,9 @@
  // no messages in this mailbox
  if (!sizeof($a_headers))
    {
    $out .= rep_specialchars_output(
            sprintf('<tr><td colspan="%d">%s</td></tr>',
                   sizeof($a_show_cols)+2,
                   rcube_label('nomessagesfound')));
    $out .= sprintf('<tr><td colspan="%d">%s</td></tr>',
                    sizeof($a_show_cols)+2,
                    Q(rcube_label('nomessagesfound')));
    }
@@ -443,10 +446,10 @@
    foreach ($a_show_cols as $col)
      {
      if ($col=='from' || $col=='to')
        $cont = rep_specialchars_output(rcmail_address_string($header->$col, 3, $attrib['addicon']));
        $cont = Q(rcmail_address_string($header->$col, 3, $attrib['addicon']), 'show');
      else if ($col=='subject')
        {
        $cont = rep_specialchars_output($IMAP->decode_header($header->$col), 'html', 'all');
        $cont = Q($IMAP->decode_header($header->$col));
        // firefox/mozilla temporary workaround to pad subject with content so that whitespace in rows responds to drag+drop
        $cont .= '<img src="./program/blank.gif" height="5" width="1000" alt="" />';
        }
@@ -455,9 +458,9 @@
      else if ($col=='date')
        $cont = format_date($header->date); //date('m.d.Y G:i:s', strtotime($header->date));
      else
        $cont = rep_specialchars_output($header->$col, 'html', 'all');
        $cont = Q($header->$col);
        
     $out .= '<td class="'.$col.'">' . $cont . "</td>\n";
      $out .= '<td class="'.$col.'">' . $cont . "</td>\n";
      }
    $out .= sprintf("<td class=\"icon\">%s</td>\n", $attach_icon ? sprintf($image_tag, $skin_path, $attach_icon, '') : '');
@@ -530,15 +533,15 @@
    foreach ($a_show_cols as $col)
      {
      if ($col=='from' || $col=='to')
        $cont = rep_specialchars_output(rcmail_address_string($header->$col, 3), 'html');
        $cont = Q(rcmail_address_string($header->$col, 3), 'show');
      else if ($col=='subject')
        $cont = rep_specialchars_output($IMAP->decode_header($header->$col), 'html', 'all');
        $cont = Q($IMAP->decode_header($header->$col));
      else if ($col=='size')
        $cont = show_bytes($header->$col);
      else if ($col=='date')
        $cont = format_date($header->date); //date('m.d.Y G:i:s', strtotime($header->date));
      else
        $cont = rep_specialchars_output($header->$col, 'html', 'all');
        $cont = Q($header->$col);
          
      $a_msg_cols[$col] = $cont;
      }
@@ -634,7 +637,7 @@
function rcmail_quota_display($attrib)
  {
  global $IMAP, $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH;
  global $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH;
  if (!$attrib['id'])
    $attrib['id'] = 'rcmquotadisplay';
@@ -643,6 +646,17 @@
  // allow the following attributes to be added to the <span> tag
  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
  $out = '<span' . $attrib_str . '>';
  $out .= rcmail_quota_content($attrib['display']);
  $out .= '</span>';
  return $out;
  }
function rcmail_quota_content($display)
  {
  global $IMAP, $COMM_PATH;
  if (!$IMAP->get_capability('QUOTA'))
    $quota_text = rcube_label('unknown');
@@ -654,9 +668,9 @@
                          $quota["percent"]);
    // show quota as image (by Brett Patterson)
    if ($attrib['display'] == 'image' && function_exists('imagegif'))
    if ($display == 'image' && function_exists('imagegif'))
      {
      $attrib += array('width' => 100, 'height' => 14);
      $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'],
@@ -669,12 +683,8 @@
    }
  else
    $quota_text = rcube_label('unlimited');
  $out = '<span' . $attrib_str . '>';
  $out .= $quota_text;
  $out .= '</span>';
  return $out;
  return $quota_text;
  }
@@ -703,7 +713,7 @@
                                              'to'    => min($max, $start_msg + $IMAP->page_size - 1),
                                              'count' => $max)));
  return rep_specialchars_output($out);
  return Q($out);
  }
@@ -729,7 +739,7 @@
                               '/url\s*\(["\']?([\.\/]+[^"\'\s]+)["\']?\)/i',
                               '/<script.+<\/script>/Umis');
      $remote_replaces = array('<img \\1src=\\2./program/blank.gif\\4',
      $remote_replaces = array('<img \\1src=\\2./program/blocked.gif\\4',
                               '',
                               '',
                               '',
@@ -750,13 +760,13 @@
      $body = preg_replace($remote_patterns, $remote_replaces, $body);
      }
    return rep_specialchars_output($body, 'html', '', FALSE);
    return Q($body, 'show', FALSE);
    }
  // text/enriched
  if ($part->ctype_secondary=='enriched')
    {
    return rep_specialchars_output(enriched_to_html($body), 'html');
    return Q(enriched_to_html($body), 'show');
    }
  else
    {
@@ -805,7 +815,7 @@
        $quotation = str_repeat("</blockquote>", $quote_level);
      $quote_level = $q;
      $a_lines[$n] = $quotation . rep_specialchars_output($line, 'html', 'replace', FALSE);
      $a_lines[$n] = $quotation . Q($line, 'replace', FALSE);
      }
    // insert the links for urls and mailtos
@@ -1004,6 +1014,18 @@
      }
    }
  // message is single part non-text
  else
    {
    if (($fname = $structure->d_parameters['filename']) ||
        ($fname = $structure->ctype_parameters['name']) ||
        ($fname = $structure->headers['content-description']))
      {
      $structure->filename = rcube_imap::decode_mime_string($fname);
      $a_attachments[] = $structure;
      }
    }
  return array($a_return_parts, $a_attachments);
  }
@@ -1047,12 +1069,12 @@
    if ($hkey=='date' && !empty($headers[$hkey]))
      $header_value = format_date(strtotime($headers[$hkey]));
    else if (in_array($hkey, array('from', 'to', 'cc', 'bcc', 'reply-to')))
      $header_value = rep_specialchars_output(rcmail_address_string($headers[$hkey], NULL, $attrib['addicon']));
      $header_value = Q(rcmail_address_string($headers[$hkey], NULL, $attrib['addicon']), 'show');
    else
      $header_value = rep_specialchars_output($IMAP->decode_header($headers[$hkey]), '', 'all');
      $header_value = Q($IMAP->decode_header($headers[$hkey]));
    $out .= "\n<tr>\n";
    $out .= '<td class="header-title">'.rep_specialchars_output(rcube_label($hkey)).":&nbsp;</td>\n";
    $out .= '<td class="header-title">'.Q(rcube_label($hkey)).":&nbsp;</td>\n";
    $out .= '<td class="'.$hkey.'" width="90%">'.$header_value."</td>\n</tr>";
    $header_count++;
    }
@@ -1188,7 +1210,8 @@
    }
  // replace event handlers on any object
  $body = preg_replace('/\s(on[a-z]+)=/im', ' __removed=', $body);
  $body = preg_replace('/\s(on[^=]+)=/im', ' __removed=', $body);
  $body = preg_replace('/\shref=["\']?(javascript:)/im', 'null:', $body);
  // resolve <base href>
  $base_reg = '/(<base.*href=["\']?)([hftps]{3,5}:\/{2}[^"\'\s]+)([^<]*>)/i';
@@ -1229,7 +1252,7 @@
  if (stristr((string)$attrib['href'], 'mailto:'))
    $attrib['onclick'] = sprintf("return %s.command('compose','%s',this)",
                                 $GLOBALS['JS_OBJECT_NAME'],
                                 substr($attrib['href'], 7));
                                 JQ(substr($attrib['href'], 7)));
  else if (!empty($attrib['href']) && $attrib['href']{0}!='#')
    $attrib['target'] = '_blank';
  
@@ -1251,13 +1274,13 @@
    $source = substr($source, 0, $pos+1) . "<<str_replacement[$key]>>" . substr($source, $pos2, strlen($source)-$pos2);
    $last_pos = $pos+2;
    }
  $styles = preg_replace('/(^\s*|,\s*)([a-z0-9\._][a-z0-9\.\-_]*)/im', "\\1#$container_id \\2", $source);
  $styles = preg_replace('/<<str_replacement\[([0-9]+)\]>>/e', "\$a_css_values[\\1]", $styles);
  // replace body definition because we also stripped off the <body> tag
  $styles = preg_replace("/$container_id\s+body/i", "$container_id div.rcmBody", $styles);
  // remove html commends and add #container to each tag selector.
  // also replace body definition because we also stripped off the <body> tag
  $styles = preg_replace(array('/(^\s*<!--)|(-->\s*$)/', '/(^\s*|,\s*|\}\s*)([a-z0-9\._][a-z0-9\.\-_]*)/im', '/<<str_replacement\[([0-9]+)\]>>/e', "/$container_id\s+body/i"),
                         array('', "\\1#$container_id \\2", "\$a_css_values[\\1]", "$container_id div.rcmBody"),
                         $source);
  return $styles;
  }
@@ -1365,7 +1388,7 @@
    {
    $j++;
    if ($PRINT_MODE)
      $out .= sprintf('%s &lt;%s&gt;', rep_specialchars_output($part['name']), $part['mailto']);
      $out .= sprintf('%s &lt;%s&gt;', Q($part['name']), $part['mailto']);
    else if (preg_match($EMAIL_ADDRESS_PATTERN, $part['mailto']))
      {
      $out .= sprintf('<a href="mailto:%s" onclick="return %s.command(\'compose\',\'%s\',this)" class="rcmContactAddress" title="%s">%s</a>',
@@ -1373,7 +1396,7 @@
                      $JS_OBJECT_NAME,
                      $part['mailto'],
                      $part['mailto'],
                      rep_specialchars_output($part['name']));
                      Q($part['name']));
                      
      if ($addicon)
        $out .= sprintf('&nbsp;<a href="#add" onclick="return %s.command(\'add-contact\',\'%s\',this)" title="%s"><img src="%s%s" alt="add" border="0" /></a>',
@@ -1386,7 +1409,7 @@
    else
      {
      if ($part['name'])
        $out .= rep_specialchars_output($part['name']);
        $out .= Q($part['name']);
      if ($part['mailto'])
        $out .= (strlen($out) ? ' ' : '') . sprintf('&lt;%s&gt;', $part['mailto']);
      }
@@ -1423,15 +1446,15 @@
  if ($filename)
    {
    $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(rcube_imap::decode_mime_string($filename)),
                    Q(rcube_label('filename')),
                    Q(rcube_imap::decode_mime_string($filename)),
                    str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']),
                    rcube_label('download'));
                    Q(rcube_label('download')));
    }
    
  if ($filesize)
    $out .= sprintf('<tr><td class="title">%s</td><td>%s</td></tr>'."\n",
                    rcube_label('filesize'),
                    Q(rcube_label('filesize')),
                    show_bytes($filesize));
  
  $out .= "\n</table>";