Aleksander Machniak
2012-08-14 c965c8abe1aa55a70844e2c95de9bb8d8293e9eb
program/steps/mail/compose.inc
@@ -17,9 +17,6 @@
 +-----------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
 +-----------------------------------------------------------------------+
 $Id$
*/
// define constants for message compose mode
@@ -29,7 +26,6 @@
define('RCUBE_COMPOSE_EDIT', 0x0109);
$MESSAGE_FORM = null;
$MESSAGE      = null;
$COMPOSE_ID   = get_input_value('_id', RCUBE_INPUT_GET);
$COMPOSE      = null;
@@ -119,7 +115,11 @@
  }
  // redirect to a unique URL with all parameters stored in session
  $OUTPUT->redirect(array('_action' => 'compose', '_id' => $COMPOSE['id']));
  $OUTPUT->redirect(array(
    '_action' => 'compose',
    '_id'     => $COMPOSE['id'],
    '_search' => $_REQUEST['_search'],
  ));
}
@@ -181,7 +181,7 @@
  $MESSAGE = new rcube_message($msg_uid);
  // make sure message is marked as read
  if ($MESSAGE && $MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN']))
  if ($MESSAGE->headers && empty($MESSAGE->headers->flags['SEEN']))
    $RCMAIL->storage->set_flag($msg_uid, 'SEEN');
  if (!empty($MESSAGE->headers->charset))
@@ -240,6 +240,9 @@
    if (!empty($COMPOSE['param']['attachment']))
      $MESSAGE->forward_attachment = true;
  }
}
else {
  $MESSAGE = new stdClass();
}
$MESSAGE->compose = array();
@@ -626,7 +629,8 @@
    if (!empty($MESSAGE->parts)) {
      foreach ($MESSAGE->parts as $part) {
        if ($part->type != 'content' || !$part->size) {
        // skip no-content and attachment parts (#1488557)
        if ($part->type != 'content' || !$part->size || $MESSAGE->is_attachment($part)) {
          continue;
        }
@@ -659,12 +663,12 @@
  unset($plugin);
  // add blocked.gif attachment (#1486516)
  if ($isHtml && preg_match('#<img src="\./program/blocked\.gif"#', $body)) {
    if ($attachment = rcmail_save_image('program/blocked.gif', 'image/gif')) {
  if ($isHtml && preg_match('#<img src="\./program/resources/blocked\.gif"#', $body)) {
    if ($attachment = rcmail_save_image('program/resources/blocked.gif', 'image/gif')) {
      $COMPOSE['attachments'][$attachment['id']] = $attachment;
      $body = preg_replace('#\./program/blocked\.gif#',
        $RCMAIL->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'].'&_id='.$COMPOSE['id'],
        $body);
      $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
        $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
      $body = preg_replace('#\./program/resources/blocked\.gif#', $url, $body);
    }
  }
@@ -764,7 +768,9 @@
  // If desired, set this textarea to be editable by TinyMCE
  if ($isHtml) {
    $MESSAGE_BODY = htmlentities($MESSAGE_BODY, ENT_NOQUOTES, RCMAIL_CHARSET);
    $attrib['class'] = 'mce_editor';
    $attrib['is_escaped'] = true;
    $textarea = new html_textarea($attrib);
    $out .= $textarea->show($MESSAGE_BODY);
  }
@@ -784,14 +790,14 @@
  // include HTML editor
  rcube_html_editor();
  // include GoogieSpell
  // Set language list
  if (!empty($CONFIG['enable_spellcheck'])) {
    $engine           = $RCMAIL->config->get('spellcheck_engine','googie');
    $dictionary       = (bool) $RCMAIL->config->get('spellcheck_dictionary');
    $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'));
            'pt'=>'Português', 'ru'=>'Русский', 'fi'=>'Suomi', 'sv'=>'Svenska'));
    // googie works only with two-letter codes
    if ($engine == 'googie') {
@@ -813,11 +819,15 @@
    if (!$spellcheck_langs[$lang])
      $lang = 'en';
    $OUTPUT->set_env('spell_langs', $spellcheck_langs);
    $OUTPUT->set_env('spell_lang', $lang);
    $editor_lang_set = array();
    foreach ($spellcheck_langs as $key => $name) {
      $editor_lang_set[] = ($key == $lang ? '+' : '') . JQ($name).'='.JQ($key);
    }
    // include GoogieSpell
    $OUTPUT->include_script('googiespell.js');
    $OUTPUT->add_script(sprintf(
      "var googie = new GoogieSpell('%s/images/googiespell/','%s&lang=', %s);\n".
@@ -829,11 +839,11 @@
      "googie.lang_learn_word = \"%s\";\n".
      "googie.setLanguages(%s);\n".
      "googie.setCurrentLanguage('%s');\n".
      "googie.setSpellContainer('spellcheck-control');\n".
      "googie.setDecoration(false);\n".
      "googie.decorateTextarea('%s');\n".
      "%s.set_env('spellcheck', googie);",
      $RCMAIL->output->get_skin_path(),
      $RCMAIL->url(array('_task' => 'utils', '_action' => 'spell')),
      $RCMAIL->url(array('_task' => 'utils', '_action' => 'spell', '_remote' => 1)),
      !empty($dictionary) ? 'true' : 'false',
      JQ(Q(rcube_label('checkspelling'))),
      JQ(Q(rcube_label('resumeediting'))),
@@ -850,7 +860,7 @@
    $OUTPUT->set_env('spellcheck_langs', join(',', $editor_lang_set));
  }
  $out .= "\n".'<iframe name="savetarget" src="program/blank.gif" style="width:0;height:0;border:none;visibility:hidden;"></iframe>';
  $out .= "\n".'<iframe name="savetarget" src="program/resources/blank.gif" style="width:0;height:0;border:none;visibility:hidden;"></iframe>';
  return $out;
}
@@ -949,18 +959,18 @@
        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>",
      rcube_label('subject'), Q($MESSAGE->subject),
      rcube_label('date'), Q($date),
      rcube_label('from'), htmlspecialchars(Q($MESSAGE->get_header('from'), 'replace'), ENT_COMPAT, $charset),
      rcube_label('to'), htmlspecialchars(Q($MESSAGE->get_header('to'), 'replace'), ENT_COMPAT, $charset));
      rcube_label('from'), Q($MESSAGE->get_header('from'), 'replace'),
      rcube_label('to'), Q($MESSAGE->get_header('to'), 'replace'));
    if ($MESSAGE->headers->cc)
      $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>",
        rcube_label('cc'),
        htmlspecialchars(Q($MESSAGE->get_header('cc'), 'replace'), ENT_COMPAT, $charset));
        Q($MESSAGE->get_header('cc'), 'replace'));
    if ($MESSAGE->headers->replyto && $MESSAGE->headers->replyto != $MESSAGE->headers->from)
      $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>",
        rcube_label('replyto'),
        htmlspecialchars(Q($MESSAGE->get_header('replyto'), 'replace'), ENT_COMPAT, $charset));
        Q($MESSAGE->get_header('replyto'), 'replace'));
    $prefix .= "</tbody></table><br>";
  }
@@ -1040,7 +1050,8 @@
      if (!$skip && ($attachment = rcmail_save_attachment($message, $pid))) {
        $COMPOSE['attachments'][$attachment['id']] = $attachment;
        if ($bodyIsHtml && ($part->content_id || $part->content_location)) {
          $url = $RCMAIL->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'].'&_id='.$COMPOSE['id'];
          $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
            $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
          if ($part->content_id)
            $cid_map['cid:'.$part->content_id] = $url;
          else
@@ -1065,7 +1076,8 @@
    if (($part->content_id || $part->content_location) && $part->filename) {
      if ($attachment = rcmail_save_attachment($message, $pid)) {
        $COMPOSE['attachments'][$attachment['id']] = $attachment;
        $url = $RCMAIL->comm_path.'&_action=display-attachment&_file=rcmfile'.$attachment['id'].'&_id='.$COMPOSE['id'];
          $url = sprintf('%s&_id=%s&_action=display-attachment&_file=rcmfile%s',
            $RCMAIL->comm_path, $COMPOSE['id'], $attachment['id']);
        if ($part->content_id)
          $cid_map['cid:'.$part->content_id] = $url;
        else
@@ -1152,10 +1164,22 @@
    $data = $message->get_part_content($pid);
  }
  $mimetype = $part->ctype_primary . '/' . $part->ctype_secondary;
  $filename = $part->filename;
  if (!strlen($filename)) {
    if ($mimetype == 'text/html') {
      $filename = rcube_label('htmlmessage');
    }
    else {
      $filename = 'Part_'.$pid;
    }
    $filename .= '.' . $part->ctype_secondary;
  }
  $attachment = array(
    'group' => $COMPOSE['id'],
    'name' => $part->filename ? $part->filename : 'Part_'.$pid.'.'.$part->ctype_secondary,
    'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
    'name' => $filename,
    'mimetype' => $mimetype,
    'content_id' => $part->content_id,
    'data' => $data,
    'path' => $path,
@@ -1392,7 +1416,7 @@
  $attrib['value'] = '1';
  $checkbox = new html_checkbox($attrib);
  if ($MESSAGE && in_array($compose_mode, array(RCUBE_COMPOSE_DRAFT, RCUBE_COMPOSE_EDIT)))
  if (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');
@@ -1501,6 +1525,7 @@
    $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
    $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
    $hiddenfields->add(array('name' => '_id', 'value' => $COMPOSE['id']));
    $hiddenfields->add(array('name' => '_attachments'));
    $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
    $form_start .= $hiddenfields->show();
@@ -1518,7 +1543,7 @@
}
function rcmail_adressbook_list($attrib = array())
function rcmail_addressbook_list($attrib = array())
{
    global $RCMAIL, $OUTPUT;
@@ -1547,7 +1572,7 @@
            $js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
    }
    $OUTPUT->add_gui_object('adressbookslist', $attrib['id']);
    $OUTPUT->add_gui_object('addressbookslist', $attrib['id']);
    return html::tag('ul', $attrib, $out, html::$common_attrib);
}
@@ -1569,6 +1594,19 @@
}
/**
 * Register a certain container as active area to drop files onto
 */
function compose_file_drop_area($attrib)
{
    global $OUTPUT;
    if ($attrib['id']) {
        $OUTPUT->add_gui_object('filedrop', $attrib['id']);
        $OUTPUT->set_env('filedrop', array('action' => 'upload', 'fieldname' => '_attachments'));
    }
}
// register UI objects
$OUTPUT->add_handlers(array(
@@ -1578,12 +1616,13 @@
  'composeattachmentlist' => 'rcmail_compose_attachment_list',
  'composeattachmentform' => 'rcmail_compose_attachment_form',
  'composeattachment' => 'rcmail_compose_attachment_field',
  'filedroparea'    => 'compose_file_drop_area',
  'priorityselector' => 'rcmail_priority_selector',
  'editorselector' => 'rcmail_editor_selector',
  'receiptcheckbox' => 'rcmail_receipt_checkbox',
  'dsncheckbox' => 'rcmail_dsn_checkbox',
  'storetarget' => 'rcmail_store_target_selection',
  'adressbooks' => 'rcmail_adressbook_list',
  'addressbooks' => 'rcmail_addressbook_list',
  'addresslist' => 'rcmail_contacts_list',
));