Dennis1993
2013-07-26 4bf322d256d0460a2df5c03b1e173f6ccd9a6eb3
program/steps/mail/func.inc
@@ -120,13 +120,47 @@
  if (!$OUTPUT->ajax_call)
    $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash',
      'movingmessage', 'copyingmessage', 'deletingmessage', 'markingmessage',
      'copy', 'move', 'quota');
      'copy', 'move', 'quota', 'replyall', 'replylist', 'importwait');
  $pagetitle = $RCMAIL->localize_foldername($RCMAIL->storage->mod_folder($mbox_name), true);
  $pagetitle = str_replace($delimiter, " \xC2\xBB ", $pagetitle);
  $OUTPUT->set_pagetitle($pagetitle);
}
// register UI objects
$OUTPUT->add_handlers(array(
  'mailboxlist'         => 'rcmail_mailbox_list',
  'messages'            => 'rcmail_message_list',
  'messagecountdisplay' => 'rcmail_messagecount_display',
  'quotadisplay'        => 'rcmail_quota_display',
  'mailboxname'         => 'rcmail_mailbox_name_display',
  'messageheaders'      => 'rcmail_message_headers',
  'messagefullheaders'  => 'rcmail_message_full_headers',
  'messagebody'         => 'rcmail_message_body',
  'messagecontentframe' => 'rcmail_messagecontent_frame',
  'messageimportform'   => 'rcmail_message_import_form',
  'searchfilter'        => 'rcmail_search_filter',
  'searchform'          => array($OUTPUT, 'search_form'),
));
// register action aliases
$RCMAIL->register_action_map(array(
    'refresh' => 'check_recent.inc',
    'preview' => 'show.inc',
    'print'   => 'show.inc',
    'move'    => 'move_del.inc',
    'delete'  => 'move_del.inc',
    'send'    => 'sendmail.inc',
    'expunge' => 'folders.inc',
    'purge'   => 'folders.inc',
    'remove-attachment'  => 'attachments.inc',
    'display-attachment' => 'attachments.inc',
    'upload'             => 'attachments.inc',
    'group-expand'       => 'autocomplete.inc',
));
/**
 * Returns 'to' if current folder is configured Sent or Drafts
@@ -224,7 +258,7 @@
  if (!in_array('threads', $a_show_cols))
    array_unshift($a_show_cols, 'threads');
  $skin_path = $_SESSION['skin_path'] = $CONFIG['skin_path'];
  $_SESSION['skin_path'] = $CONFIG['skin_path'];
  // set client env
  $OUTPUT->add_gui_object('messagelist', $attrib['id']);
@@ -289,7 +323,7 @@
  $thead = $head_replace ? rcmail_message_list_head($_SESSION['list_attrib'], $a_show_cols) : NULL;
  // get name of smart From/To column in folder context
  if (($f = array_search('fromto', $a_show_cols)) !== false) {
  if (array_search('fromto', $a_show_cols) !== false) {
    $smart_col = rcmail_message_list_smart_column_name();
  }
@@ -305,7 +339,7 @@
  }
  // loop through message headers
  foreach ($a_headers as $n => $header) {
  foreach ($a_headers as $header) {
    if (empty($header))
      continue;
@@ -379,7 +413,6 @@
  global $RCMAIL;
  $skin_path = $_SESSION['skin_path'];
  $image_tag = html::img(array('src' => "%s%s", 'alt' => "%s"));
  // check to see if we have some settings for sorting
  $sort_col   = $_SESSION['sort_col'];
@@ -415,7 +448,7 @@
  $cells = array();
  // get name of smart From/To column in folder context
  if (($f = array_search('fromto', $a_show_cols)) !== false) {
  if (array_search('fromto', $a_show_cols) !== false) {
    $smart_col = rcmail_message_list_smart_column_name();
  }
@@ -606,6 +639,8 @@
            $message->set_safe(true);
          }
        }
        $RCMAIL->plugins->exec_hook('message_check_safe', array('message' => $message));
        break;
      case 2: // always
@@ -734,8 +769,13 @@
  unset($data['body']);
  // plaintext postprocessing
  if ($part->ctype_secondary == 'plain')
    $body = rcmail_plain_body($body, $part->ctype_parameters['format'] == 'flowed');
  if ($part->ctype_secondary == 'plain') {
    if ($part->ctype_secondary == 'plain' && $part->ctype_parameters['format'] == 'flowed') {
      $body = rcube_mime::unfold_flowed($body);
    }
    $body = rcmail_plain_body($body);
  }
  // allow post-processing of the message body
  $data = $RCMAIL->plugins->exec_hook('message_part_after',
@@ -749,11 +789,10 @@
 * Handle links and citation marks in plain text message
 *
 * @param string  Plain text string
 * @param boolean Text uses format=flowed
 *
 * @return string Formatted HTML string
 */
function rcmail_plain_body($body, $flowed=false)
function rcmail_plain_body($body)
{
  global $RCMAIL;
@@ -778,53 +817,17 @@
      if ($q > $quote_level) {
        $body[$n] = $replacer->get_replacement($replacer->add(
          str_repeat('<blockquote>', $q - $quote_level))) . $body[$n];
        $last = $n;
      }
      else if ($q < $quote_level) {
        $body[$n] = $replacer->get_replacement($replacer->add(
          str_repeat('</blockquote>', $quote_level - $q))) . $body[$n];
      }
      else if ($flowed) {
        // previous line is flowed
        if (isset($body[$last]) && $body[$n]
          && $body[$last][strlen($body[$last])-1] == ' ') {
          // merge lines
          $body[$last] .= $body[$n];
          unset($body[$n]);
        }
        else {
          $last = $n;
        }
        $last = $n;
      }
    }
    else {
      $q = 0;
      if ($flowed) {
        // sig separator - line is fixed
        if ($body[$n] == '-- ') {
          $last = $last_sig = $n;
        }
        else {
          // remove space-stuffing
          if ($body[$n][0] == ' ')
            $body[$n] = substr($body[$n], 1);
          // previous line is flowed?
          if (isset($body[$last]) && $body[$n]
            && $last !== $last_sig
            && $body[$last][strlen($body[$last])-1] == ' '
          ) {
            $body[$last] .= $body[$n];
            unset($body[$n]);
          }
          else {
            $last = $n;
          }
        }
        if ($quote_level > 0)
          $body[$last] = $replacer->get_replacement($replacer->add(
            str_repeat('</blockquote>', $quote_level))) . $body[$last];
      }
      else if ($quote_level > 0)
      if ($quote_level > 0)
        $body[$n] = $replacer->get_replacement($replacer->add(
          str_repeat('</blockquote>', $quote_level))) . $body[$n];
    }
@@ -895,7 +898,7 @@
 */
function rcmail_message_headers($attrib, $headers=null)
{
  global $OUTPUT, $MESSAGE, $PRINT_MODE, $RCMAIL;
  global $MESSAGE, $PRINT_MODE, $RCMAIL;
  static $sa_attrib;
  // keep header table attrib
@@ -933,7 +936,7 @@
      $value = $headers[$hkey];
    else if ($headers['others'][$hkey])
      $value = $headers['others'][$hkey];
    else
    else if (!$attrib['valueof'])
      continue;
    if (in_array($hkey, $exclude_headers))
@@ -1080,7 +1083,7 @@
      $header_attrib[$regs[1]] = $value;
  if (!empty($MESSAGE->parts)) {
    foreach ($MESSAGE->parts as $i => $part) {
    foreach ($MESSAGE->parts as $part) {
      if ($part->type == 'headers') {
        $out .= html::div('message-partheaders', rcmail_message_headers(sizeof($header_attrib) ? $header_attrib : null, $part->headers));
      }
@@ -1450,9 +1453,10 @@
    $name   = $part['name'];
    $mailto = $part['mailto'];
    $string = $part['string'];
    $valid  = check_email($mailto, false);
    // phishing email prevention (#1488981), e.g. "valid@email.addr <phishing@email.addr>"
    if (!$show_email && $name && $name != $mailto && strpos($name, '@')) {
    if (!$show_email && $valid && $name && $name != $mailto && strpos($name, '@')) {
      $name = '';
    }
@@ -1468,7 +1472,7 @@
      // for printing we display all addresses
      continue;
    }
    else if (check_email($part['mailto'], false)) {
    else if ($valid) {
      if ($linked) {
        $attrs = array(
           'href' => 'mailto:' . $mailto,
@@ -1509,7 +1513,7 @@
      if ($name)
        $address .= Q($name);
      if ($mailto)
        $address .= (strlen($address) ? ' ' : '') . sprintf('&lt;%s&gt;', Q($mailto));
        $address = trim($address . ' ' . Q($name ? sprintf('<%s>', $mailto) : $mailto));
    }
    $address = html::span('adr', $address);
@@ -1548,11 +1552,11 @@
/**
 * Wrap text to a given number of characters per line
 * but respect the mail quotation of replies messages (>).
 * Finally add another quotation level by prpending the lines
 * Finally add another quotation level by prepending the lines
 * with >
 *
 * @param string Text to wrap
 * @param int The line width
 * @param int    The line width
 * @return string The wrapped text
 */
function rcmail_wrap_and_quote($text, $length = 72)
@@ -1568,7 +1572,7 @@
      $line = '>' . rtrim($line);
    else if (mb_strlen($line) > $max) {
      $newline = '';
      foreach(explode("\n", rc_wordwrap($line, $length - 2)) as $l) {
      foreach (explode("\n", rc_wordwrap($line, $length - 2)) as $l) {
        if (strlen($l))
          $newline .= '> ' . $l . "\n";
        else
@@ -1608,45 +1612,6 @@
  }
  return $info;
}
function rcmail_message_part_controls($attrib)
{
  global $MESSAGE, $RCMAIL;
  $part = asciiwords(get_input_value('_part', RCUBE_INPUT_GPC));
  if (!is_object($MESSAGE) || !is_array($MESSAGE->parts) || !($_GET['_uid'] && $_GET['_part']) || !$MESSAGE->mime_parts[$part])
    return '';
  $part  = $MESSAGE->mime_parts[$part];
  $table = new html_table(array('cols' => 3));
  $filename = rcmail_attachment_name($part);
  if (!empty($filename)) {
    $table->add('title', Q(rcube_label('filename')));
    $table->add('header', Q($filename));
    $table->add('download-link', html::a(array('href' => './?'.str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING'])), Q(rcube_label('download'))));
  }
  $table->add('title', Q(rcube_label('filesize')));
  $table->add('header', Q($RCMAIL->message_part_size($part)));
  return $table->show($attrib);
}
function rcmail_message_part_frame($attrib)
{
  global $MESSAGE;
  $part = $MESSAGE->mime_parts[asciiwords(get_input_value('_part', RCUBE_INPUT_GPC))];
  $ctype_primary = strtolower($part->ctype_primary);
  $attrib['src'] = './?' . str_replace('_frame=', ($ctype_primary=='text' ? '_embed=' : '_preload='), $_SERVER['QUERY_STRING']);
  return html::iframe($attrib);
}
@@ -1737,8 +1702,7 @@
    $sent = rcmail_deliver_message($compose, $identity['email'], $mailto, $smtp_error, $body_file, $options);
    if ($sent)
    {
    if ($sent) {
      $RCMAIL->storage->set_flag($message->uid, 'MDNSENT');
      return true;
    }
@@ -1819,9 +1783,12 @@
    // Try Return-Path
    if ($from_idx === null && ($return_path = $MESSAGE->headers->others['return-path'])) {
        foreach ($identities as $idx => $ident) {
            if (strpos($return_path, str_replace('@', '=', $ident['email_ascii']).'@') !== false) {
                $from_idx = $idx;
                break;
            $ident = str_replace('@', '=', $ident['email_ascii']) . '@';
            foreach ((array)$return_path as $path) {
                if (strpos($path, $ident) !== false) {
                    $from_idx = $idx;
                    break 2;
                }
            }
        }
    }
@@ -1856,8 +1823,7 @@
  // application/pdf.A520491B_3BF7_494D_8855_7FAC2C6C0608
  if (preg_match('/^application\/pdf.+/', $name))
    $name = 'application/pdf';
  // treat image/pjpeg as image/jpeg
  // treat image/pjpeg (image/pjpg, image/jpg) as image/jpeg (#1489097)
  else if (preg_match('/^image\/p?jpe?g$/', $name))
    $name = 'image/jpeg';
@@ -1953,35 +1919,37 @@
  $RCMAIL->output->send('messageerror');
}
// register UI objects
$OUTPUT->add_handlers(array(
  'mailboxlist' => 'rcmail_mailbox_list',
  'messages' => 'rcmail_message_list',
  'messagecountdisplay' => 'rcmail_messagecount_display',
  'quotadisplay' => 'rcmail_quota_display',
  'mailboxname' => 'rcmail_mailbox_name_display',
  'messageheaders' => 'rcmail_message_headers',
  'messagefullheaders' => 'rcmail_message_full_headers',
  'messagebody' => 'rcmail_message_body',
  'messagecontentframe' => 'rcmail_messagecontent_frame',
  'messagepartframe' => 'rcmail_message_part_frame',
  'messagepartcontrols' => 'rcmail_message_part_controls',
  'searchfilter' => 'rcmail_search_filter',
  'searchform' => array($OUTPUT, 'search_form'),
));
function rcmail_message_import_form($attrib = array())
{
  global $OUTPUT;
// register action aliases
$RCMAIL->register_action_map(array(
    'refresh' => 'check_recent.inc',
    'preview' => 'show.inc',
    'print'   => 'show.inc',
    'moveto'  => 'move_del.inc',
    'delete'  => 'move_del.inc',
    'send'    => 'sendmail.inc',
    'expunge' => 'folders.inc',
    'purge'   => 'folders.inc',
    'remove-attachment'  => 'attachments.inc',
    'display-attachment' => 'attachments.inc',
    'upload'             => 'attachments.inc',
    'group-expand'       => 'autocomplete.inc',
));
  // set defaults
  $attrib += array('id' => 'rcmImportform', 'buttons' => 'yes');
  // Get filesize, enable upload progress bar
  $max_filesize = rcube_upload_init();
  $button = new html_inputfield(array('type' => 'button'));
  $fileinput = new html_inputfield(array(
      'type' => 'file',
      'name' => '_file[]',
      'size' => $attrib['attachmentfieldsize'],
      'multiple' => 'multiple',
      'accept' => ".eml, .mbox, message/rfc822, text/*",
  ));
  $out = html::div($attrib,
    $OUTPUT->form_tag(array('id' => $attrib['id'].'Frm', 'method' => 'post', 'enctype' => 'multipart/form-data'),
      html::tag('input', array('type' => 'hidden', 'name' => '_unlock', 'value' => '')) .
      html::div(null, $fileinput->show()) .
      html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize)))) .
      (get_boolean($attrib['buttons']) ? html::div('buttons',
        $button->show(rcube_label('close'), array('class' => 'button', 'onclick' => "$('#$attrib[id]').hide()")) . ' ' .
        $button->show(rcube_label('upload'), array('class' => 'button mainaction', 'onclick' => JS_OBJECT_NAME . ".command('import-messages', this.form)"))
      ) : '')
    )
  );
  $OUTPUT->add_gui_object('importform', $attrib['id'].'Frm');
  return $out;
}