thomascube
2005-11-18 fbf77b4493f1b77c99751d8a86365c712ae3fb1b
program/steps/mail/compose.inc
@@ -32,6 +32,10 @@
  $_SESSION['compose'] = array('id' => uniqid(rand()));
// add some labels to client
rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'sendingmessage');
if ($_GET['_reply_uid'] || $_GET['_forward_uid'])
  {
  $msg_uid = $_GET['_reply_uid'] ? $_GET['_reply_uid'] : $_GET['_forward_uid'];
@@ -46,15 +50,18 @@
  $MESSAGE['structure'] = $mmd->decode(array('include_bodies' => TRUE,
                                             'decode_headers' => TRUE,
                                             'decode_bodies' => FALSE));
  $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject);
  $MESSAGE['parts'] = $mmd->getMimeNumbers($MESSAGE['structure']);
  
  if ($_GET['_reply_uid'])
    {
    $REPLY_MESSAGE = $MESSAGE;
    $REPLY_MESSAGE = &$MESSAGE;
    $_SESSION['compose']['reply_uid'] = $_GET['_reply_uid'];
    $_SESSION['compose']['reply_msgid'] = $REPLY_MESSAGE['headers']->messageID;
    if ($_GET['_all'])
      $REPLY_MESSAGE['reply_all'] = 1;
    }
  else
    {
@@ -71,6 +78,7 @@
function rcmail_compose_headers($attrib)
  {
  global $IMAP, $REPLY_MESSAGE, $DB;
  static $sa_recipients = array();
  list($form_start, $form_end) = get_form_tags($attrib);
  
@@ -83,17 +91,15 @@
      // pass the following attributes to the form class
      $field_attrib = array('name' => '_from');
      foreach ($attrib as $attr => $value)
        if (in_array($attr, array('id', 'class', 'style', 'size')))
        if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex')))
          $field_attrib[$attr] = $value;
    
      // get this user's identities
      $sql_result = $DB->query(sprintf("SELECT identity_id, name, email
                                        FROM   %s
                                        WHERE  user_id=%d
                                        AND    del!='1'
                                        ORDER BY `default` DESC, name ASC",
                                       get_table_name('identities'),
                                       $_SESSION['user_id']));
      $sql_result = $DB->query("SELECT identity_id, name, email
                                FROM   ".get_table_name('identities')." WHERE  user_id=?
                                AND    del<>'1'
                                ORDER BY ".$DB->quoteIdentifier('default')." DESC, name ASC",
                                $_SESSION['user_id']);
                                   
      if ($DB->num_rows($sql_result))
        {        
@@ -120,17 +126,14 @@
      $header = 'to';
      
      // we have contact id's as get parameters
      if (strlen($_GET['_to']) && preg_match('/[0-9]+,?/', $_GET['_to']))
      if (!empty($_GET['_to']) && preg_match('/[0-9]+,?/', $_GET['_to']))
        {
        $a_recipients = array();
        $sql_result = $DB->query(sprintf("SELECT name, email
                                          FROM   %s
                                          WHERE  user_id=%d
                                          AND    del!='1'
                                          AND    contact_id IN (%s)",
                                         get_table_name('contacts'),
                                         $_SESSION['user_id'],
                                         $_GET['_to']));
        $sql_result = $DB->query("SELECT name, email
                                  FROM ".get_table_name('contacts')." WHERE user_id=?
                                  AND    del<>'1'
                                  AND    contact_id IN (".$_GET['_to'].")",
                                  $_SESSION['user_id']);
                                         
        while ($sql_arr = $DB->fetch_assoc($sql_result))
          $a_recipients[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
@@ -138,34 +141,34 @@
        if (sizeof($a_recipients))
          $fvalue = join(', ', $a_recipients);
        }
      else if (strlen($_GET['_to']))
      else if (!empty($_GET['_to']))
        $fvalue = $_GET['_to'];
        
    case 'cc':
      if (!$fname)
        {
        $fname = '_cc';
        //$header = 'cc';
        $header = 'cc';
        }
    case 'bcc':
      if (!$fname)
        $fname = '_bcc';
        
      $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'wrap');
      $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'wrap', 'tabindex');
      $field_type = 'textarea';            
      break;
    case 'replyto':
    case 'reply-to':
      $fname = '_replyto';
      $allow_attrib = array('id', 'class', 'style', 'size');
      $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
      $field_type = 'textfield';
      break;
    
    }
    
  if ($fname && $_POST[$fname])
  if ($fname && !empty($_POST[$fname]))
    $fvalue = $_POST[$fname];
  else if ($header && is_object($REPLY_MESSAGE['headers']))
    {
@@ -174,14 +177,37 @@
      $fvalue = $IMAP->decode_header($REPLY_MESSAGE['headers']->replyto);
    else if ($header=='to' && $REPLY_MESSAGE['headers']->from)
      $fvalue = $IMAP->decode_header($REPLY_MESSAGE['headers']->from);
    // add recipent of original message if reply to all
    else if ($header=='cc' && $REPLY_MESSAGE['reply_all'])
      {
      if ($IMAP->decode_header($REPLY_MESSAGE['headers']->to))
        $fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->to);
      if ($IMAP->decode_header($REPLY_MESSAGE['headers']->cc))
        {
        if($fvalue)
          $fvalue .= ', ';
        $fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->cc);
        }
      }
    // split recipients and put them back together in a unique way
    $to_addresses = $IMAP->decode_address_list($fvalue);
    $fvalue = '';
    foreach ($to_addresses as $addr_part)
      $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
    if (!empty($fvalue))
      {
      $to_addresses = $IMAP->decode_address_list($fvalue);
      $fvalue = '';
      foreach ($to_addresses as $addr_part)
        {
        if (!in_array($addr_part['mailto'], $sa_recipients))
          {
          $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
          $sa_recipients[] = $addr_part['mailto'];
          }
        }
      }
    }
        
  if ($fname && $field_type)
    {
@@ -282,7 +308,7 @@
  $body = '';
  
  // use posted message body
  if ($_POST['_message'])
  if (!empty($_POST['_message']))
    $body = stripslashes($_POST['_message']);
    
  // compose reply-body
@@ -352,6 +378,34 @@
                   $IMAP->decode_header($FORWARD_MESSAGE['headers']->from),
                   $IMAP->decode_header($FORWARD_MESSAGE['headers']->to));
  // add attachments
  if (!isset($_SESSION['compose']['forward_attachments']) && is_array($FORWARD_MESSAGE['parts']) && sizeof($FORWARD_MESSAGE['parts'])>1)
    {
    $temp_dir = rcmail_create_compose_tempdir();
    if (!is_array($_SESSION['compose']['attachments']))
      $_SESSION['compose']['attachments'] = array();
    foreach ($FORWARD_MESSAGE['parts'] as $part)
      {
      if ($part->disposition != 'attachment')
        continue;
      $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
      if ($fp = fopen($tmp_path, 'w'))
        {
        fwrite($fp, $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding']));
        fclose($fp);
        $_SESSION['compose']['attachments'][] = array('name' => $part->d_parameters['filename'],
                                                      'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
                                                      'path' => $tmp_path);
        }
      }
    $_SESSION['compose']['forward_attachments'] = TRUE;
    }
  return $prefix.$body;
  }
@@ -370,16 +424,26 @@
  $subject = '';
  // use subject from post
  if ($_POST['_subject'])
  if (isset($_POST['_subject']))
    $subject = stripslashes($_POST['_subject']);
    
  // create a reply-subject
  else if (isset($REPLY_MESSAGE['subject']))
    $subject = 'Re: '.$REPLY_MESSAGE['subject'];
    {
    if (eregi('^re:', $REPLY_MESSAGE['subject']))
      $subject = $REPLY_MESSAGE['subject'];
    else
      $subject = 'Re: '.$REPLY_MESSAGE['subject'];
    }
  // create a forward-subject
  else if (isset($FORWARD_MESSAGE['subject']))
    $subject = 'Fwd: '.$FORWARD_MESSAGE['subject'];
    {
    if (eregi('^fwd:', $REPLY_MESSAGE['subject']))
      $subject = $FORWARD_MESSAGE['subject'];
    else
      $subject = 'Fwd: '.$FORWARD_MESSAGE['subject'];
    }
  
  $out = $form_start ? "$form_start\n" : '';
@@ -471,9 +535,9 @@
                       rcube_label('normal'),
                       rcube_label('high'),
                       rcube_label('highest')),
                 array(1, 2, 0, 4, 5));
                 array(5, 4, 0, 2, 1));
                 
  $sel = $_POST['_priority'] ? $_POST['_priority'] : 0;
  $sel = isset($_POST['_priority']) ? $_POST['_priority'] : 0;
  $out = $form_start ? "$form_start\n" : '';
  $out .= $selector->show($sel);
@@ -493,13 +557,13 @@
    $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
    $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
    
    $form_start = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
    $form_start = empty($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
    $form_start .= "\n$SESS_HIDDEN_FIELD\n";
    $form_start .= $hiddenfields->show();
    }
    
  $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
  $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';
  $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
  
  if (!strlen($MESSAGE_FORM))
    $OUTPUT->add_script("$JS_OBJECT_NAME.gui_object('messageform', '$form_name');");
@@ -519,14 +583,20 @@
  }
function rcmail_charset_pulldown($selected='ISO-8859-1')
  {
  $select = new select();
  return $select->show($selected);
  }
/****** get contacts for this user and add them to client scripts ********/
$sql_result = $DB->query(sprintf("SELECT name, email
                                  FROM   %s
                                  WHERE  user_id=%d
                                  AND    del!='1'",
                                 get_table_name('contacts'),
                                 $_SESSION['user_id']));
$sql_result = $DB->query("SELECT name, email
                          FROM ".get_table_name('contacts')." WHERE  user_id=?
                          AND  del<>'1'",$_SESSION['user_id']);
                                   
if ($DB->num_rows($sql_result))
  {