alecpl
2008-08-28 79aeb308cb195dcc48004851795e811cee6f8ca1
program/steps/mail/func.inc
@@ -245,7 +245,7 @@
    foreach ($a_show_cols as $col)
      {
      if ($col=='from' || $col=='to')
        $cont = Q(rcmail_address_string($header->$col, 3, $attrib['addicon']), 'show');
        $cont = Q(rcmail_address_string($header->$col, 3, false, $attrib['addicon']), 'show');
      else if ($col=='subject')
        {
        $action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show';
@@ -529,6 +529,27 @@
  return Q($out);
  }
/**
 *
 */
function rcmail_mailbox_name_display($attrib)
{
    global $RCMAIL;
    if (!$attrib['id'])
        $attrib['id'] = 'rcmmailboxname';
    $RCMAIL->output->add_gui_object('mailboxname', $attrib['id']);
    return html::span($attrib, rcmail_get_mailbox_name_text());
}
function rcmail_get_mailbox_name_text()
{
    global $RCMAIL;
    return rcmail_localize_foldername($RCMAIL->imap->get_mailbox_name());
}
/**
 * Convert the given message part to proper HTML
@@ -539,12 +560,14 @@
 * @param bool  True if part should be converted to plaintext
 * @return string Formatted HTML string
 */
function rcmail_print_body($part, $safe=false, $plain=false)
function rcmail_print_body($part, $p = array())
{
  global $REMOTE_OBJECTS;
  
  $p += array('safe' => false, 'plain' => false, 'inline_html' => true);
  // convert html to text/plain
  if ($part->ctype_secondary == 'html' && $plain) {
  if ($part->ctype_secondary == 'html' && $p['plain']) {
    $txt = new html2text($part->body, false, true);
    $body = $txt->get_text();
    $part->ctype_secondary = 'plain';
@@ -553,32 +576,50 @@
  else if ($part->ctype_secondary == 'html') {
    // charset was converted to UTF-8 in rcube_imap::get_message_part() -> change charset specification in HTML accordingly
    $html = $part->body; 
    if(preg_match('/(\s+content=[\'"]\w+\/\w+;\s+charset)=([a-z0-9-]+)/i', $html))
      $html = preg_replace('/(\s+content=[\'"]\w+\/\w+;\s+charset)=([a-z0-9-]+)/i', '\\1='.RCMAIL_CHARSET, $html);
    if (preg_match('/(\s+content=[\'"]\w+\/\w+;\s*charset)=([a-z0-9-_]+)/i', $html))
      $html = preg_replace('/(\s+content=[\'"]\w+\/\w+;\s*charset)=([a-z0-9-_]+)/i', '\\1='.RCMAIL_CHARSET, $html);
    else {
      // add <head> for malformed messages, washtml cannot work without that
      if (!preg_match('/<head>(.*)<\/head>/m', $html))
      if (!preg_match('/<head>(.*)<\\/head>/Uims', $html))
        $html = '<head></head>' . $html;
      $html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '</head>')), 0);
    }
    // PHP bug #32547 workaround: remove title tag
    $html = preg_replace('/<title>.*<\/title>/', '', $html);
    // clean HTML with washhtml by Frederic Motte
    $body = washtml::wash($html, array(
    $wash_opts = array(
      'show_washed' => false,
      'allow_remote' => $safe,
      'allow_remote' => $p['safe'],
      'blocked_src' => "./program/blocked.gif",
      'charset' => RCMAIL_CHARSET,
      'cid_map' => $part->replaces,
      ), $full_inline);
    $REMOTE_OBJECTS = !$full_inline;
      'html_elements' => array('body'),
    );
    if (!$p['inline_html']) {
      $wash_opts['html_elements'] = array('html','head','title','body');
    }
    /* CSS styles need to be sanitized!
    if ($p['safe']) {
      $wash_opts['html_elements'][] = 'style';
      $wash_opts['html_attribs'] = array('type');
    }
    */
    $washer = new washtml($wash_opts);
    $washer->add_callback('form', 'rcmail_washtml_callback');
    $body = $washer->wash($html);
    $REMOTE_OBJECTS = $washer->extlinks;
    return $body;
  }
  // text/enriched
  else if ($part->ctype_secondary=='enriched') {
    $part->ctype_secondary = 'html';
    return Q(enriched_to_html($body), 'show');
    return Q(enriched_to_html($part->body), 'show');
  }
  else
    $body = $part->body;
@@ -637,20 +678,35 @@
  $body = preg_replace("/##string_replacement\{([0-9]+)\}##/e", "\$replace_strings[\\1]", join("\n", $a_lines));
  
  return "<div class=\"pre\">".$body."\n</div>";
  }
}
/**
 * add a string to the replacement array and return a replacement string
 */
function rcmail_str_replacement($str, &$rep)
  {
{
  static $count = 0;
  $rep[$count] = stripslashes($str);
  return "##string_replacement{".($count++)."}##";
  }
}
/**
 * Callback function for washtml cleaning class
 */
function rcmail_washtml_callback($tagname, $attrib, $content)
{
  switch ($tagname) {
    case 'form':
      $out = html::div('form', $content);
      break;
    default:
      $out = '';
  }
  return $out;
}
/**
@@ -658,7 +714,7 @@
 */
function rcmail_message_headers($attrib, $headers=NULL)
  {
  global $IMAP, $OUTPUT, $MESSAGE;
  global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $CONFIG;
  static $sa_attrib;
  
  // keep header table attrib
@@ -678,7 +734,7 @@
  // add empty subject if none exsists
  if (empty($headers['subject']))
    $headers['subject'] = rcube_label('nosubject');
  $header_count = 0;
  
  // allow the following attributes to be added to the <table> tag
@@ -694,9 +750,14 @@
      continue;
    if ($hkey=='date' && !empty($headers[$hkey]))
      $header_value = format_date($headers[$hkey]);
      {
      if ($PRINT_MODE)
        $header_value = format_date($headers[$hkey], $CONFIG['date_long'] ? $CONFIG['date_long'] : 'x');
      else
        $header_value = format_date($headers[$hkey]);
      }
    else if (in_array($hkey, array('from', 'to', 'cc', 'bcc', 'reply-to')))
      $header_value = Q(rcmail_address_string($headers[$hkey], NULL, $attrib['addicon']), 'show');
      $header_value = Q(rcmail_address_string($headers[$hkey], null, true, $attrib['addicon']), 'show');
    else
      $header_value = Q($IMAP->decode_header($headers[$hkey]));
@@ -751,7 +812,7 @@
        if (!isset($part->body))
          $part->body = $MESSAGE->get_part_content($part->mime_id);
        $body = rcmail_print_body($part, $safe_mode, !$CONFIG['prefer_html']);
        $body = rcmail_print_body($part, array('safe' => $safe_mode, 'plain' => !$CONFIG['prefer_html']));
        if ($part->ctype_secondary == 'html')
          $out .= html::div('message-htmlpart', rcmail_html4inline($body, $attrib['id']));
@@ -881,8 +942,8 @@
/**
 * decode address string and re-format it as HTML links
 */
function rcmail_address_string($input, $max=NULL, $addicon=NULL)
  {
function rcmail_address_string($input, $max=null, $linked=false, $addicon=null)
{
  global $IMAP, $PRINT_MODE, $CONFIG, $OUTPUT, $EMAIL_ADDRESS_PATTERN;
  $a_parts = $IMAP->decode_address_list($input);
@@ -894,48 +955,56 @@
  $j = 0;
  $out = '';
  foreach ($a_parts as $part)
    {
  foreach ($a_parts as $part) {
    $j++;
    if ($PRINT_MODE)
    if ($PRINT_MODE) {
      $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>',
                      Q($part['mailto']),
                      JS_OBJECT_NAME,
                      JQ($part['mailto']),
                      Q($part['mailto']),
                      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>',
                        JS_OBJECT_NAME,
                        urlencode($part['string']),
                        rcube_label('addtoaddressbook'),
                        $CONFIG['skin_path'],
                        $addicon);
    }
    else if (preg_match($EMAIL_ADDRESS_PATTERN, $part['mailto'])) {
      if ($linked) {
        $out .= html::a(array(
            'href' => 'mailto:'.$part['mailto'],
            'onclick' => sprintf("return %s.command('compose','%s',this)", JS_OBJECT_NAME, JQ($part['mailto'])),
            'title' => $part['mailto'],
            'class' => "rcmContactAddress",
          ),
        Q($part['name']));
      }
    else
      {
      else {
        $out .= html::span(array('title' => $part['mailto'], 'class' => "rcmContactAddress"), Q($part['name']));
      }
      if ($addicon) {
        $out .= '&nbsp;' . html::a(array(
            'href' => "#add",
            'onclick' => sprintf("return %s.command('add-contact','%s',this)", JS_OBJECT_NAME, urlencode($part['string'])),
            'title' => rcube_label('addtoaddressbook'),
          ),
          html::img(array(
            'src' => $CONFIG['skin_path'] . $addicon,
            'alt' => "Add contact",
            'border' => 0,
          )));
      }
    }
    else {
      if ($part['name'])
        $out .= Q($part['name']);
      if ($part['mailto'])
        $out .= (strlen($out) ? ' ' : '') . sprintf('&lt;%s&gt;', Q($part['mailto']));
      }
    }
      
    if ($c>$j)
      $out .= ','.($max ? '&nbsp;' : ' ');
        
    if ($max && $j==$max && $c>$j)
      {
    if ($max && $j==$max && $c>$j) {
      $out .= '...';
      break;
      }
    }
  }
    
  return $out;
  }
}
function rcmail_message_part_controls()
@@ -1007,7 +1076,7 @@
  $msg_body = $message->get();
  $headers = $message->headers();
  // send thru SMTP server using custom SMTP library
  if ($CONFIG['smtp_server'])
    {
@@ -1053,8 +1122,19 @@
      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from");
    }
  
  if ($sent)  // remove MDN headers after sending
  if ($sent)
  {
    // remove MDN headers after sending
    unset($headers['Return-Receipt-To'], $headers['Disposition-Notification-To']);
    if ($CONFIG['smtp_log'])
      write_log('sendmail', sprintf("[%s] User: %d on %s; Message for %s; %s",
      date("d-M-Y H:i:s O", mktime()),
      $_SESSION['user_id'],
      $_SERVER['REMOTE_ADDR'],
      $mailto,
      !empty($smtp_response) ? join('; ', $smtp_response) : ''));
  }
  
  $message->_headers = array();
  $message->headers($headers);
@@ -1139,6 +1219,7 @@
  'messages' => 'rcmail_message_list',
  'messagecountdisplay' => 'rcmail_messagecount_display',
  'quotadisplay' => 'rcmail_quota_display',
  'mailboxname' => 'rcmail_mailbox_name_display',
  'messageheaders' => 'rcmail_message_headers',
  'messagebody' => 'rcmail_message_body',
  'messagecontentframe' => 'rcmail_messagecontent_frame',