alecpl
2010-09-30 13ffa2810eaef30a0f69fc3af6ecbb5bc9dd0bdc
program/steps/mail/compose.inc
@@ -4,8 +4,8 @@
 +-----------------------------------------------------------------------+
 | program/steps/mail/compose.inc                                        |
 |                                                                       |
 | This file is part of the RoundCube Webmail client                     |
 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                 |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland                 |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | PURPOSE:                                                              |
@@ -227,14 +227,12 @@
        $fvalue = urldecode($_SESSION['mailto'][$mailto_id]);
    case 'cc':
      if (!$fname)
      {
      if (!$fname) {
        $fname = '_cc';
        $header = $param = 'cc';
      }
    case 'bcc':
      if (!$fname)
      {
      if (!$fname) {
        $fname = '_bcc';
        $header = $param = 'bcc';
      }
@@ -251,7 +249,7 @@
      $field_type = 'html_inputfield';
      break;
  }
  if ($fname && !empty($_POST[$fname])) {
    $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE);
  }
@@ -262,13 +260,10 @@
    // get recipent address(es) out of the message headers
    if ($header=='to' && !empty($MESSAGE->headers->replyto))
      $fvalue = $MESSAGE->headers->replyto;
    else if ($header=='to' && !empty($MESSAGE->headers->from))
      $fvalue = $MESSAGE->headers->from;
    // add recipent of original message if reply to all
    else if ($header=='cc' && !empty($MESSAGE->reply_all))
    {
    else if ($header=='cc' && !empty($MESSAGE->reply_all)) {
      if ($v = $MESSAGE->headers->to)
        $fvalue .= $v;
@@ -277,39 +272,58 @@
    }
    // split recipients and put them back together in a unique way
    if (!empty($fvalue))
    {
    if (!empty($fvalue)) {
      $to_addresses = $IMAP->decode_address_list($fvalue);
      $fvalue = '';
      foreach ($to_addresses as $addr_part)
      {
        if (!empty($addr_part['mailto'])
            && !in_array($addr_part['mailto'], $sa_recipients)
      foreach ($to_addresses as $addr_part) {
        if (empty($addr_part['mailto']))
          continue;
        $mailto = idn_to_utf8($addr_part['mailto']);
        if (!in_array($mailto, $sa_recipients)
            && (!$MESSAGE->compose_from
                || !in_array_nocase($addr_part['mailto'], $MESSAGE->compose_from)
                || (count($to_addresses)==1 && $header=='to'))) // allow reply to yourself
        {
          $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
                || !in_array_nocase($mailto, $MESSAGE->compose_from)
                || (count($to_addresses)==1 && $header=='to')) // allow reply to yourself
        ) {
          if ($addr_part['name'] && $addr_part['mailto'] != $addr_part['name'])
            $string = format_email_recipient($mailto, $addr_part['name']);
          else
            $string = $mailto;
          $fvalue .= (strlen($fvalue) ? ', ':'') . $string;
          $sa_recipients[] = $addr_part['mailto'];
        }
      }
    }
  }
  else if ($header && in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT)))
  {
  else if ($header && in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))) {
    // get drafted headers
    if ($header=='to' && !empty($MESSAGE->headers->to))
      $fvalue = $MESSAGE->get_header('to');
    if ($header=='cc' && !empty($MESSAGE->headers->cc))
    else if ($header=='cc' && !empty($MESSAGE->headers->cc))
      $fvalue = $MESSAGE->get_header('cc');
    if ($header=='bcc' && !empty($MESSAGE->headers->bcc))
    else if ($header=='bcc' && !empty($MESSAGE->headers->bcc))
      $fvalue = $MESSAGE->get_header('bcc');
    $addresses = $IMAP->decode_address_list($fvalue);
    $fvalue = '';
    foreach ($addresses as $addr_part) {
      if (empty($addr_part['mailto']))
        continue;
      $mailto = idn_to_utf8($addr_part['mailto']);
      if ($addr_part['name'] && $addr_part['mailto'] != $addr_part['name'])
        $string = format_email_recipient($mailto, $addr_part['name']);
      else
        $string = $mailto;
      $fvalue .= (strlen($fvalue) ? ', ':'') . $string;
    }
  }
  if ($fname && $field_type)
  {
    // pass the following attributes to the form class
@@ -326,7 +340,7 @@
  if ($form_start)
    $out = $form_start.$out;
  return $out;
  return $out;
}
@@ -350,7 +364,7 @@
    foreach ($a_to as $addr)
    {
      if (!empty($addr['mailto']))
        $a_recipients[] = mb_strtolower($addr['mailto']);
        $a_recipients[] = mb_strtolower(idn_to_utf8($addr['mailto']));
    }
    if (!empty($MESSAGE->headers->cc))
@@ -359,7 +373,7 @@
      foreach ($a_cc as $addr)
      {
        if (!empty($addr['mailto']))
          $a_recipients[] = mb_strtolower($addr['mailto']);
          $a_recipients[] = mb_strtolower(idn_to_utf8($addr['mailto']));
      }
    }
  }
@@ -377,6 +391,7 @@
    foreach ($user_identities as $sql_arr)
    {
      $sql_arr['email'] = mb_strtolower(idn_to_utf8($sql_arr['email']));
      $identity_id = $sql_arr['identity_id'];
      $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $identity_id);
@@ -401,7 +416,7 @@
        if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE->headers->from, $sql_arr['email']))
          $from_id = $sql_arr['identity_id'];
        // set identity if it's one of the reply-message recipients (with prio for default identity)
        else if (in_array(mb_strtolower($sql_arr['email']), $a_recipients) && (empty($from_id) || $sql_arr['standard']))
        else if (in_array($sql_arr['email'], $a_recipients) && (empty($from_id) || $sql_arr['standard']))
          $from_id = $sql_arr['identity_id'];
      }
    }
@@ -610,14 +625,24 @@
  global $RCMAIL, $MESSAGE, $LINE_LENGTH;
  if (!$bodyIsHtml) {
    $body = preg_replace('/\r?\n/', "\n", $body);
    // try to remove the signature
    if ($RCMAIL->config->get('strip_existing_sig', true) && ($sp = strrpos($body, '-- ')) !== false && ($sp == 0 || $body{$sp-1} == "\n")) {
      if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
        $body = substr($body, 0, max(0, $sp-1));
    if ($RCMAIL->config->get('strip_existing_sig', true)) {
      $len = strlen($body);
      while (($sp = strrpos($body, "-- \n", $sp ? -$len+$sp-1 : 0)) !== false) {
        if ($sp == 0 || $body[$sp-1] == "\n") {
          // do not touch blocks with more that X lines
          if (substr_count($body, "\n", $sp) < $RCMAIL->config->get('sig_max_lines', 15)) {
            $body = substr($body, 0, max(0, $sp-1));
          }
          break;
        }
      }
    }
    // soft-wrap and quote message text
    $body = rcmail_wrap_and_quote(rtrim($body, "\r\n"), $LINE_LENGTH);
    $body = rcmail_wrap_and_quote(rtrim($body, "\n"), $LINE_LENGTH);
    // add title line(s)
    $prefix = sprintf("On %s, %s wrote:\n",
@@ -915,7 +940,7 @@
  $out = $form_start ? "$form_start\n" : '';
  $out .= $textfield->show($subject);
  $out .= $form_end ? "\n$form_end" : '';
  return $out;
}
@@ -990,11 +1015,11 @@
  $button = new html_inputfield(array('type' => 'button'));
  
  $out = html::div($attrib,
    $OUTPUT->form_tag(array('name' => 'form', 'method' => 'post', 'enctype' => 'multipart/form-data'),
    $OUTPUT->form_tag(array('name' => 'uploadform', 'method' => 'post', 'enctype' => 'multipart/form-data'),
      html::div(null, rcmail_compose_attachment_field(array('size' => $attrib[attachmentfieldsize]))) .
      html::div('hint', rcube_label(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize)))) .
      html::div('buttons',
//        $button->show(rcube_label('close'), array('class' => 'button', 'onclick' => "$('#$attrib[id]').hide()")) . ' ' .
        $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('send-attachment', this.form)"))
      )
    )
@@ -1048,7 +1073,7 @@
function rcmail_receipt_checkbox($attrib)
{
  global $MESSAGE, $compose_mode;
  global $RCMAIL, $MESSAGE, $compose_mode;
  list($form_start, $form_end) = get_form_tags($attrib);
  unset($attrib['form']);
@@ -1060,9 +1085,13 @@
  $attrib['value'] = '1';
  $checkbox = new html_checkbox($attrib);
  if ($MESSAGE && in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT)))
    $mdn_default = (bool) $MESSAGE->headers->mdn_to;
  else
    $mdn_default = $RCMAIL->config->get('mdn_default');
  $out = $form_start ? "$form_start\n" : '';
  $out .= $checkbox->show(in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT))
   && $MESSAGE->headers->mdn_to ? 1 : 0);
  $out .= $checkbox->show($mdn_default);
  $out .= $form_end ? "\n$form_end" : '';
  return $out;