thomascube
2008-09-05 a6d7a9f791cb559dd1c0052f1ec709be017e6533
program/steps/mail/compose.inc
@@ -63,7 +63,10 @@
if (!is_array($_SESSION['compose']) || $_SESSION['compose']['id'] != get_input_value('_id', RCUBE_INPUT_GET))
{
  rcmail_compose_cleanup();
  $_SESSION['compose'] = array('id' => uniqid(rand()));
  $_SESSION['compose'] = array('id' => uniqid(rand()), 'param' => array_map('strip_tags', $_GET));
  // redirect to a unique URL with all parameters stored in session
  $OUTPUT->redirect(array('_action' => 'compose', '_id' => $_SESSION['compose']['id']));
}
// add some labels to client
@@ -74,13 +77,12 @@
// get reference message and set compose mode
if ($msg_uid = get_input_value('_reply_uid', RCUBE_INPUT_GET))
if ($msg_uid = $_SESSION['compose']['param']['_reply_uid'])
  $compose_mode = RCUBE_COMPOSE_REPLY;
else if ($msg_uid = get_input_value('_forward_uid', RCUBE_INPUT_GET))
else if ($msg_uid = $_SESSION['compose']['param']['_forward_uid'])
  $compose_mode = RCUBE_COMPOSE_FORWARD;
else if ($msg_uid = get_input_value('_draft_uid', RCUBE_INPUT_GET))
else if ($msg_uid = $_SESSION['compose']['param']['_draft_uid'])
  $compose_mode = RCUBE_COMPOSE_DRAFT;
if (!empty($msg_uid))
{
@@ -96,16 +98,23 @@
    $_SESSION['compose']['reply_msgid'] = $MESSAGE->headers->messageID;
    $_SESSION['compose']['references']  = trim($MESSAGE->headers->references . " " . $MESSAGE->headers->messageID);
    if (!empty($_GET['_all']))
    if (!empty($_SESSION['compose']['param']['_all']))
      $MESSAGE->reply_all = 1;
  }
  else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
  {
    if($MESSAGE->headers->in_reply_to)
    {
      // TODO: how to get reply_uid/forward_uid value, maybe we must set X-Reply-UID/X-Forward-UID
      // $_SESSION['compose']['reply_uid'] = ?
      // $_SESSION['compose']['forward_uid'] = ?
      $_SESSION['compose']['reply_msgid'] = '<'.$MESSAGE->headers->in_reply_to.'>';
    }
    $_SESSION['compose']['references']  = $MESSAGE->headers->references;
  }
  else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
  {
    $_SESSION['compose']['forward_uid'] = $msg_uid;
  }
  else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
  {
    $_SESSION['compose']['draft_uid'] = $msg_uid;
  }
}
@@ -132,10 +141,10 @@
      $header = 'to';
      
      // we have a set of recipients stored is session
      if (($mailto_id = get_input_value('_mailto', RCUBE_INPUT_GET)) && $_SESSION['mailto'][$mailto_id])
        $fvalue = $_SESSION['mailto'][$mailto_id];
      else if (!empty($_GET['_to']))
        $fvalue = get_input_value('_to', RCUBE_INPUT_GET);
      if (($mailto_id = $_SESSION['compose']['param']['_mailto']) && $_SESSION['mailto'][$mailto_id])
        $fvalue = urldecode($_SESSION['mailto'][$mailto_id]);
      else if (!empty($_SESSION['compose']['param']['_to']))
        $fvalue = $_SESSION['compose']['param']['_to'];
        
    case 'cc':
      if (!$fname)
@@ -378,13 +387,13 @@
      $body = rcmail_create_draft_body($body, $isHtml);
  }
  $tinylang = substr($_SESSION['language'], 0, 2);
  if (!file_exists('program/js/tiny_mce/langs/'.$tinylang.'.js'))
  $lang = $tinylang = strtolower(substr($_SESSION['language'], 0, 2));
  if (!file_exists(INSTALL_PATH . 'program/js/tiny_mce/langs/'.$tinylang.'.js'))
    $tinylang = 'en'; 
  $OUTPUT->include_script('tiny_mce/tiny_mce.js');
  $OUTPUT->include_script("editor.js");
  $OUTPUT->add_script('rcmail_editor_init("$__skin_path", "'.$tinylang.'");');
  $OUTPUT->add_script('rcmail_editor_init("$__skin_path", "'.JQ($tinylang).'", '.intval($CONFIG['enable_spellcheck']).');');
  $out = $form_start ? "$form_start\n" : '';
@@ -404,11 +413,15 @@
  $out .= $form_end ? "\n$form_end" : '';
  // include GoogieSpell
  if (!empty($CONFIG['enable_spellcheck']) && !$isHtml)
    {
    $lang_set = '';
    if (!empty($CONFIG['spellcheck_languages']) && is_array($CONFIG['spellcheck_languages']))
      $lang_set = "googie.setLanguages(".array2js($CONFIG['spellcheck_languages']).");\n";
  if (!empty($CONFIG['enable_spellcheck'])) {
    $spellcheck_langs = (array)$RCMAIL->config->get('spellcheck_languages', array('da'=>'Dansk', 'de'=>'Deutsch', 'en' => 'English', 'es'=>'Español', 'fr'=>'Français', 'it'=>'Italiano', 'nl'=>'Nederlands', 'pl'=>'Polski', 'pt'=>'Português', 'fi'=>'Suomi', 'sv'=>'Svenska'));
    if (!$spellcheck_langs[$lang])
      $lang = 'en';
    $editor_lang_set = array();
    foreach ($spellcheck_langs as $key => $name) {
      $editor_lang_set[] = ($key == $lang ? '+' : '') . JQ($name).'='.JQ($key);
    }
    
    $OUTPUT->include_script('googiespell.js');
    $OUTPUT->add_script(sprintf(
@@ -417,7 +430,8 @@
      "googie.lang_rsm_edt = \"%s\";\n".
      "googie.lang_close = \"%s\";\n".
      "googie.lang_revert = \"%s\";\n".
      "googie.lang_no_error_found = \"%s\";\n%s".
      "googie.lang_no_error_found = \"%s\";\n".
      "googie.setLanguages(%s);\n".
      "googie.setCurrentLanguage('%s');\n".
      "googie.decorateTextarea('%s');\n".
      "%s.set_env('spellcheck', googie);",
@@ -427,15 +441,16 @@
      JQ(Q(rcube_label('close'))),
      JQ(Q(rcube_label('revertto'))),
      JQ(Q(rcube_label('nospellerrors'))),
      $lang_set,
      substr($_SESSION['language'], 0, 2),
      json_serialize($spellcheck_langs),
      $lang,
      $attrib['id'],
      JS_OBJECT_NAME), 'foot');
    rcube_add_label('checking');
    }
    $OUTPUT->set_env('spellcheck_langs', join(',', $editor_lang_set));
  }
 
  $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>';
  $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;border:none;visibility:hidden;"></iframe>';
  return $out;
}
@@ -443,7 +458,7 @@
function rcmail_create_reply_body($body, $bodyIsHtml)
{
  global $IMAP, $MESSAGE;
  global $IMAP, $MESSAGE, $OUTPUT;
  if (! $bodyIsHtml)
  {
@@ -481,7 +496,7 @@
  {
    $prefix = sprintf("<br /><br />On %s, %s wrote:<br />\n",
      $MESSAGE->headers->date,
      Q($MESSAGE->get_header('from')));
      htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true));
    $prefix .= '<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">';
    $suffix = "</blockquote>";
  }
@@ -492,13 +507,13 @@
function rcmail_create_forward_body($body, $bodyIsHtml)
{
  global $IMAP, $MESSAGE;
  global $IMAP, $MESSAGE, $OUTPUT;
  if (!$bodyIsHtml)
  {
    // soft-wrap message first
    $body = wordwrap($body, 80);
    $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n",
      $MESSAGE->subject,
      $MESSAGE->headers->date,
@@ -517,13 +532,13 @@
        "</tbody></table><br>",
      Q($MESSAGE->subject),
      Q($MESSAGE->headers->date),
      Q($MESSAGE->get_header('from')),
      Q($MESSAGE->get_header('to')));
      htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true),
      htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $OUTPUT->get_charset(), true));
  }
  // add attachments
  if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE->mime_parts))
    rcmail_write_compose_attachments($MESSAGE);
    rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
    
  return $prefix.$body;
}
@@ -540,13 +555,13 @@
  if (!isset($_SESSION['compose']['forward_attachments'])
      && is_array($MESSAGE->mime_parts)
      && count($MESSAGE->mime_parts) > 0)
    rcmail_write_compose_attachments($MESSAGE);
    rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
  return $body;
}
  
  
function rcmail_write_compose_attachments(&$message)
function rcmail_write_compose_attachments(&$message, $bodyIsHtml)
{
  global $RCMAIL, $IMAP;
@@ -557,7 +572,7 @@
  
  foreach ((array)$message->mime_parts as $pid => $part)
  {
    if ($part->ctype_primary != 'message' &&
    if (($part->ctype_primary != 'message' || !$bodyIsHtml) &&
        ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
         (empty($part->disposition) && $part->filename)))
    {
@@ -647,12 +662,17 @@
      $button = Q(rcube_label('delete'));
    foreach ($_SESSION['compose']['attachments'] as $id => $a_prop)
    {
      if (empty($a_prop))
        continue;
      $out .= html::tag('li', array('id' => "rcmfile".$id),
        html::a(array(
            'href' => "#delete",
            'title' => rcube_label('delete'),
              'onclick' => sprintf("return %s.command(\'remove-attachment\',\'rcmfile%d\', this)", JS_OBJECT_NAME, $id)),
            'onclick' => sprintf("return %s.command('remove-attachment','rcmfile%d', this)", JS_OBJECT_NAME, $id)),
          $button) . Q($a_prop['name']));
    }
  }
  $OUTPUT->add_gui_object('attachmentlist', $attrib['id']);
@@ -723,7 +743,7 @@
function rcmail_receipt_checkbox($attrib)
{
  global $MESSAGE;
  global $MESSAGE, $compose_mode;
  
  list($form_start, $form_end) = get_form_tags($attrib);
  unset($attrib['form']);
@@ -736,7 +756,8 @@
  $checkbox = new html_checkbox($attrib);
  $out = $form_start ? "$form_start\n" : '';
  $out .= $checkbox->show($MESSAGE->headers->mdn_to ? 1 : 0);
  $out .= $checkbox->show(
    $compose_mode == RCUBE_COMPOSE_DRAFT && $MESSAGE->headers->mdn_to ? 1 : 0);
  $out .= $form_end ? "\n$form_end" : '';
  return $out;
@@ -769,6 +790,14 @@
  }
  return $selector;
}
function rcmail_store_target_selection($attrib)
{
  $attrib['name'] = '_store_target';
  $select = rcmail_mailbox_select(array('noselection' => '- '.rcube_label('dontsave').' -'));
  return $select->show(rcmail::get_instance()->config->get('sent_mbox'), $attrib);
}
@@ -809,6 +838,7 @@
  'priorityselector' => 'rcmail_priority_selector',
  'editorselector' => 'rcmail_editor_selector',
  'receiptcheckbox' => 'rcmail_receipt_checkbox',
  'storetarget' => 'rcmail_store_target_selection',
));
/****** get contacts for this user and add them to client scripts ********/
@@ -824,15 +854,16 @@
    if ($sql_arr['email'])
      $a_contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
  }
if (isset($CONFIG['ldap_public']))
if (!empty($CONFIG['ldap_public']) && is_array($CONFIG['ldap_public']))
  {
  /* LDAP autocompletion */ 
  foreach ($CONFIG['ldap_public'] as $ldapserv_config) 
    { 
    if ($ldapserv_config['fuzzy_search'] != 1)
    if ($ldapserv_config['fuzzy_search'] != 1 ||
        $ldapserv_config['global_search'] != 1)
      { 
      continue; 
      }
      }
    
    $LDAP = new rcube_ldap($ldapserv_config); 
    $LDAP->connect(); 
@@ -856,6 +887,8 @@
if ($a_contacts) 
  { 
    $OUTPUT->set_env('contacts', $a_contacts); 
  }
  }
$OUTPUT->send('compose');
?>