Changeset 8fa58e7 in github for program/steps/mail/compose.inc


Ignore:
Timestamp:
May 17, 2008 1:46:43 PM (5 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
26539d5f
Parents:
e2f958c
Message:

New class rcube_message representing a mail message; changed global $MESSAGE from array to object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/steps/mail/compose.inc

    r885ebb8 r8fa58e7  
    66 |                                                                       | 
    77 | This file is part of the RoundCube Webmail client                     | 
    8  | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 | 
     8 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                 | 
    99 | Licensed under the GNU GPL                                            | 
    1010 |                                                                       | 
     
    8686{ 
    8787  // similar as in program/steps/mail/show.inc 
    88   $MESSAGE = array('UID' => $msg_uid); 
    89   $MESSAGE['headers'] = &$IMAP->get_headers($msg_uid); 
    90   $MESSAGE['structure'] = &$IMAP->get_structure($msg_uid); 
    91    
    92   if (!empty($MESSAGE['headers']->charset)) 
    93     $IMAP->set_charset($MESSAGE['headers']->charset); 
     88  $MESSAGE = new rcube_message($msg_uid); 
     89   
     90  if (!empty($MESSAGE->headers->charset)) 
     91    $IMAP->set_charset($MESSAGE->headers->charset); 
    9492     
    95   $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject); 
    96   $MESSAGE['parts'] = $IMAP->get_mime_numbers($MESSAGE['structure']); 
    97    
    9893  if ($compose_mode == RCUBE_COMPOSE_REPLY) 
    9994  { 
    10095    $_SESSION['compose']['reply_uid'] = $msg_uid; 
    101     $_SESSION['compose']['reply_msgid'] = $MESSAGE['headers']->messageID; 
    102     $_SESSION['compose']['references']  = trim($MESSAGE['headers']->references . " " . $MESSAGE['headers']->messageID); 
     96    $_SESSION['compose']['reply_msgid'] = $MESSAGE->headers->messageID; 
     97    $_SESSION['compose']['references']  = trim($MESSAGE->headers->references . " " . $MESSAGE->headers->messageID); 
    10398 
    10499    if (!empty($_GET['_all'])) 
    105       $MESSAGE['reply_all'] = 1; 
     100      $MESSAGE->reply_all = 1; 
    106101  } 
    107102  else if ($compose_mode == RCUBE_COMPOSE_FORWARD) 
     
    174169  { 
    175170    // get recipent address(es) out of the message headers 
    176     if ($header=='to' && !empty($MESSAGE['headers']->replyto)) 
    177       $fvalue = $MESSAGE['headers']->replyto; 
    178  
    179     else if ($header=='to' && !empty($MESSAGE['headers']->from)) 
    180       $fvalue = $MESSAGE['headers']->from; 
     171    if ($header=='to' && !empty($MESSAGE->headers->replyto)) 
     172      $fvalue = $MESSAGE->headers->replyto; 
     173 
     174    else if ($header=='to' && !empty($MESSAGE->headers->from)) 
     175      $fvalue = $MESSAGE->headers->from; 
    181176 
    182177    // add recipent of original message if reply to all 
    183     else if ($header=='cc' && !empty($MESSAGE['reply_all'])) 
    184     { 
    185       if ($v = $MESSAGE['headers']->to) 
     178    else if ($header=='cc' && !empty($MESSAGE->reply_all)) 
     179    { 
     180      if ($v = $MESSAGE->headers->to) 
    186181        $fvalue .= $v; 
    187182 
    188       if ($v = $MESSAGE['headers']->cc) 
     183      if ($v = $MESSAGE->headers->cc) 
    189184        $fvalue .= (!empty($fvalue) ? ', ' : '') . $v; 
    190185    } 
     
    197192      foreach ($to_addresses as $addr_part) 
    198193      { 
    199         if (!empty($addr_part['mailto']) && !in_array($addr_part['mailto'], $sa_recipients) && (!$MESSAGE['FROM'] || !in_array($addr_part['mailto'], $MESSAGE['FROM']))) 
     194        if (!empty($addr_part['mailto']) && !in_array($addr_part['mailto'], $sa_recipients) && (!$MESSAGE->compose_from || !in_array($addr_part['mailto'], $MESSAGE->compose_from))) 
    200195        { 
    201196          $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string']; 
     
    208203  { 
    209204    // get drafted headers 
    210     if ($header=='to' && !empty($MESSAGE['headers']->to)) 
    211       $fvalue = $IMAP->decode_header($MESSAGE['headers']->to); 
    212  
    213     if ($header=='cc' && !empty($MESSAGE['headers']->cc)) 
    214       $fvalue = $IMAP->decode_header($MESSAGE['headers']->cc); 
    215  
    216     if ($header=='bcc' && !empty($MESSAGE['headers']->bcc)) 
    217       $fvalue = $IMAP->decode_header($MESSAGE['headers']->bcc); 
     205    if ($header=='to' && !empty($MESSAGE->headers->to)) 
     206      $fvalue = $MESSAGE->get_header('to'); 
     207 
     208    if ($header=='cc' && !empty($MESSAGE->headers->cc)) 
     209      $fvalue = $MESSAGE->get_header('cc'); 
     210 
     211    if ($header=='bcc' && !empty($MESSAGE->headers->bcc)) 
     212      $fvalue = $MESSAGE->get_header('bcc'); 
    218213  } 
    219214 
     
    242237function rcmail_compose_header_from($attrib) 
    243238{ 
    244   global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $CONFIG, $compose_mode; 
     239  global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $compose_mode; 
    245240     
    246241  // pass the following attributes to the form class 
     
    252247  // extract all recipients of the reply-message 
    253248  $a_recipients = array(); 
    254   if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE['headers'])) 
    255   { 
    256     $MESSAGE['FROM'] = array(); 
    257  
    258     $a_to = $IMAP->decode_address_list($MESSAGE['headers']->to); 
     249  if ($compose_mode == RCUBE_COMPOSE_REPLY && is_object($MESSAGE->headers)) 
     250  { 
     251    $MESSAGE->compose_from = array(); 
     252 
     253    $a_to = $IMAP->decode_address_list($MESSAGE->headers->to); 
    259254    foreach ($a_to as $addr) 
    260255    { 
     
    263258    } 
    264259 
    265     if (!empty($MESSAGE['headers']->cc)) 
    266     { 
    267       $a_cc = $IMAP->decode_address_list($MESSAGE['headers']->cc); 
     260    if (!empty($MESSAGE->headers->cc)) 
     261    { 
     262      $a_cc = $IMAP->decode_address_list($MESSAGE->headers->cc); 
    268263      foreach ($a_cc as $addr) 
    269264      { 
     
    307302        $from_id = $sql_arr['identity_id']; 
    308303 
    309       if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE['FROM'])) 
    310         $MESSAGE['FROM'][] = $sql_arr['email']; 
    311  
    312       if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE['headers']->from, $sql_arr['email'])) 
     304      if ($compose_mode == RCUBE_COMPOSE_REPLY && is_array($MESSAGE->compose_from)) 
     305        $MESSAGE->compose_from[] = $sql_arr['email']; 
     306 
     307      if ($compose_mode == RCUBE_COMPOSE_DRAFT && strstr($MESSAGE->headers->from, $sql_arr['email'])) 
    313308        $from_id = $sql_arr['identity_id']; 
    314309    } 
     
    357352  // use posted message body 
    358353  if (!empty($_POST['_message'])) 
    359     { 
    360     $body = get_input_value('_message', RCUBE_INPUT_POST, TRUE); 
    361     } 
    362   // compose reply-body 
    363   else if ($compose_mode == RCUBE_COMPOSE_REPLY) 
    364     { 
    365     $hasHtml = rcmail_has_html_part($MESSAGE['parts']);  
    366     if ($hasHtml && $CONFIG['htmleditor']) 
    367       { 
    368       $body = rcmail_first_html_part($MESSAGE); 
     354  { 
     355    $body = get_input_value('_message', RCUBE_INPUT_POST, true); 
     356  } 
     357  else if ($compose_mode) 
     358  { 
     359    if ($isHtml && $MESSAGE->has_html_part()) 
     360    { 
     361      $body = $MESSAGE->first_html_part(); 
    369362      $isHtml = true; 
    370       } 
     363    } 
    371364    else 
    372       { 
    373       $body = rcmail_first_text_part($MESSAGE); 
     365    { 
     366      $body = $MESSAGE->first_text_part(); 
    374367      $isHtml = false; 
    375       } 
    376  
    377     $body = rcmail_create_reply_body($body, $isHtml); 
    378     } 
    379   // forward message body inline 
    380   else if ($compose_mode == RCUBE_COMPOSE_FORWARD) 
    381     { 
    382     $hasHtml = rcmail_has_html_part($MESSAGE['parts']); 
    383     if ($hasHtml && $CONFIG['htmleditor']) 
    384       { 
    385       $body = rcmail_first_html_part($MESSAGE); 
    386       $isHtml = true; 
    387       } 
    388     else 
    389       { 
    390       $body = rcmail_first_text_part($MESSAGE); 
    391       $isHtml = false; 
    392       } 
    393  
    394     $body = rcmail_create_forward_body($body, $isHtml); 
    395     } 
    396   else if ($compose_mode == RCUBE_COMPOSE_DRAFT) 
    397     { 
    398     $hasHtml = rcmail_has_html_part($MESSAGE['parts']); 
    399     if ($hasHtml && $CONFIG['htmleditor']) 
    400       { 
    401       $body = rcmail_first_html_part($MESSAGE); 
    402       $isHtml = true; 
    403       } 
    404     else 
    405       { 
    406       $body = rcmail_first_text_part($MESSAGE); 
    407       $isHtml = false; 
    408       } 
    409  
    410     $body = rcmail_create_draft_body($body, $isHtml); 
    411     } 
     368    } 
     369     
     370    // compose reply-body 
     371    if ($compose_mode == RCUBE_COMPOSE_REPLY) 
     372      $body = rcmail_create_reply_body($body, $isHtml); 
     373    // forward message body inline 
     374    else if ($compose_mode == RCUBE_COMPOSE_FORWARD) 
     375      $body = rcmail_create_forward_body($body, $isHtml); 
     376    // load draft message body 
     377    else if ($compose_mode == RCUBE_COMPOSE_DRAFT) 
     378      $body = rcmail_create_draft_body($body, $isHtml); 
     379  } 
    412380 
    413381  $tinylang = substr($_SESSION['language'], 0, 2); 
    414382  if (!file_exists('program/js/tiny_mce/langs/'.$tinylang.'.js')) 
    415     {  
    416383    $tinylang = 'en';  
    417     }  
    418384 
    419385  $OUTPUT->include_script('tiny_mce/tiny_mce.js'); 
     
    423389  $out = $form_start ? "$form_start\n" : ''; 
    424390 
    425   $saveid = new html_hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE['headers']->messageID) : '')); 
     391  $saveid = new html_hiddenfield(array('name' => '_draft_saveid', 'value' => $compose_mode==RCUBE_COMPOSE_DRAFT ? str_replace(array('<','>'), "", $MESSAGE->headers->messageID) : '')); 
    426392  $out .= $saveid->show(); 
    427393 
     
    501467    // add title line 
    502468    $prefix = sprintf("\n\n\nOn %s, %s wrote:\n", 
    503              $MESSAGE['headers']->date, 
    504              $IMAP->decode_header($MESSAGE['headers']->from)); 
     469      $MESSAGE->headers->date, 
     470      $MESSAGE->get_header('from')); 
    505471 
    506472    // try to remove the signature 
     
    514480  else 
    515481  { 
    516     $prefix = sprintf("<br><br>On %s, %s wrote:<br><blockquote type=\"cite\" " . 
    517                       "style=\"padding-left: 5px; border-left: #1010ff 2px solid; " . 
    518                       "margin-left: 5px; width: 100%%\">", 
    519                       $MESSAGE['headers']->date, 
    520                       $IMAP->decode_header($MESSAGE['headers']->from)); 
    521  
     482    $prefix = sprintf("<br /><br />On %s, %s wrote:<br />\n", 
     483      $MESSAGE->headers->date, 
     484      Q($MESSAGE->get_header('from'))); 
     485    $prefix .= '<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">'; 
    522486    $suffix = "</blockquote>"; 
    523487  } 
     
    531495  global $IMAP, $MESSAGE; 
    532496 
    533   if (! $bodyIsHtml) 
     497  if (!$bodyIsHtml) 
    534498  { 
    535499    // soft-wrap message first 
     
    537501   
    538502    $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n", 
    539                      $MESSAGE['subject'], 
    540                      $MESSAGE['headers']->date, 
    541                      $IMAP->decode_header($MESSAGE['headers']->from), 
    542                      $IMAP->decode_header($MESSAGE['headers']->to)); 
     503      $MESSAGE->subject, 
     504      $MESSAGE->headers->date, 
     505      $MESSAGE->get_header('from'), 
     506      $MESSAGE->get_header('to')); 
    543507  } 
    544508  else 
    545509  { 
    546510    $prefix = sprintf( 
    547         "<br><br>-------- Original Message --------" . 
     511      "<br><br>-------- Original Message --------" . 
    548512        "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" . 
    549513        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">Subject: </th><td>%s</td></tr>" . 
     
    552516        "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">To: </th><td>%s</td></tr>" . 
    553517        "</tbody></table><br>", 
    554                      Q($MESSAGE['subject']), 
    555                      Q($MESSAGE['headers']->date), 
    556                      Q($IMAP->decode_header($MESSAGE['headers']->from)), 
    557                      Q($IMAP->decode_header($MESSAGE['headers']->to))); 
     518      Q($MESSAGE->subject), 
     519      Q($MESSAGE->headers->date), 
     520      Q($MESSAGE->get_header('from')), 
     521      Q($MESSAGE->get_header('to'))); 
    558522  } 
    559523 
    560524  // add attachments 
    561   if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE['parts'])) 
     525  if (!isset($_SESSION['compose']['forward_attachments']) && is_array($MESSAGE->mime_parts)) 
    562526    rcmail_write_compose_attachments($MESSAGE); 
    563527     
     
    568532function rcmail_create_draft_body($body, $bodyIsHtml) 
    569533{ 
    570   global $IMAP, $MESSAGE; 
     534  global $MESSAGE; 
    571535   
    572536  /** 
    573537   * add attachments 
    574    * sizeof($MESSAGE['parts'] can be 1 - e.g. attachment, but no text! 
     538   * sizeof($MESSAGE->mime_parts can be 1 - e.g. attachment, but no text! 
    575539   */ 
    576540  if (!isset($_SESSION['compose']['forward_attachments']) 
    577       && is_array($MESSAGE['parts']) 
    578       && count($MESSAGE['parts']) > 0) 
     541      && is_array($MESSAGE->mime_parts) 
     542      && count($MESSAGE->mime_parts) > 0) 
    579543    rcmail_write_compose_attachments($MESSAGE); 
    580544 
     
    585549function rcmail_write_compose_attachments(&$message) 
    586550{ 
    587   global $IMAP, $CONFIG; 
    588  
    589   $temp_dir = unslashify($CONFIG['temp_dir']); 
     551  global $RCMAIL, $IMAP; 
     552 
     553  $temp_dir = unslashify($RCMAIL->config->get('temp_dir')); 
    590554 
    591555  if (!is_array($_SESSION['compose']['attachments'])) 
    592556    $_SESSION['compose']['attachments'] = array(); 
    593557   
    594   foreach ($message['parts'] as $pid => $part) 
     558  foreach ((array)$message->mime_parts as $pid => $part) 
    595559  { 
    596560    if ($part->ctype_primary != 'message' && 
     
    601565      if ($fp = fopen($tmp_path, 'w')) 
    602566      { 
    603         fwrite($fp, $IMAP->get_message_part($message['UID'], $pid, $part->encoding)); 
     567        fwrite($fp, $message->get_part_content($pid)); 
    604568        fclose($fp); 
    605569         
     
    613577  } 
    614578         
    615   $_SESSION['compose']['forward_attachments'] = TRUE; 
     579  $_SESSION['compose']['forward_attachments'] = true; 
    616580} 
    617581 
     
    619583function rcmail_compose_subject($attrib) 
    620584{ 
    621   global $CONFIG, $MESSAGE, $compose_mode; 
     585  global $MESSAGE, $compose_mode; 
    622586   
    623587  list($form_start, $form_end) = get_form_tags($attrib); 
     
    636600  else if ($compose_mode == RCUBE_COMPOSE_REPLY) 
    637601  { 
    638     if (eregi('^re:', $MESSAGE['subject'])) 
    639       $subject = $MESSAGE['subject']; 
     602    if (eregi('^re:', $MESSAGE->subject)) 
     603      $subject = $MESSAGE->subject; 
    640604    else 
    641       $subject = 'Re: '.$MESSAGE['subject']; 
     605      $subject = 'Re: '.$MESSAGE->subject; 
    642606  } 
    643607 
     
    645609  else if ($compose_mode == RCUBE_COMPOSE_FORWARD) 
    646610  { 
    647     if (eregi('^fwd:', $MESSAGE['subject'])) 
    648       $subject = $MESSAGE['subject']; 
     611    if (eregi('^fwd:', $MESSAGE->subject)) 
     612      $subject = $MESSAGE->subject; 
    649613    else 
    650       $subject = 'Fwd: '.$MESSAGE['subject']; 
     614      $subject = 'Fwd: '.$MESSAGE->subject; 
    651615  } 
    652616 
    653617  // creeate a draft-subject 
    654618  else if ($compose_mode == RCUBE_COMPOSE_DRAFT) 
    655     $subject = $MESSAGE['subject']; 
     619    $subject = $MESSAGE->subject; 
    656620   
    657621  $out = $form_start ? "$form_start\n" : ''; 
     
    671635    $attrib['id'] = 'rcmAttachmentList'; 
    672636   
    673   // allow the following attributes to be added to the <ul> tag 
    674   $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style')); 
    675   
    676   $out = '<ul'. $attrib_str . ">\n"; 
     637  $out = "\n"; 
    677638   
    678639  if (is_array($_SESSION['compose']['attachments'])) 
    679640  { 
    680641    if ($attrib['deleteicon']) 
    681       $button = sprintf('<img src="%s%s" alt="%s" border="0" style="padding-right:2px;vertical-align:middle" />', 
    682                         $CONFIG['skin_path'], 
    683                         $attrib['deleteicon'], 
    684                         rcube_label('delete')); 
     642      $button = html::img(array( 
     643        'src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 
     644        'alt' => rcube_label('delete'), 
     645        'style' => "border:0;padding-right:2px;vertical-align:middle")); 
    685646    else 
    686       $button = rcube_label('delete'); 
     647      $button = Q(rcube_label('delete')); 
    687648 
    688649    foreach ($_SESSION['compose']['attachments'] as $id => $a_prop) 
    689       $out .= sprintf('<li id="rcmfile%d"><a href="#delete" onclick="return %s.command(\'remove-attachment\',\'rcmfile%d\', this)" title="%s">%s</a>%s</li>', 
    690                       $id, 
    691                       JS_OBJECT_NAME, 
    692                       $id, 
    693                       Q(rcube_label('delete')), 
    694                       $button, 
    695                       Q($a_prop['name'])); 
     650      $out .= html::tag('li', array('id' => "rcmfile".$id), 
     651        html::a(array( 
     652            'href' => "#delete", 
     653            'title' => rcube_label('delete'), 
     654              'onclick' => sprintf("return %s.command(\'remove-attachment\',\'rcmfile%d\', this)", JS_OBJECT_NAME, $id)), 
     655          $button) . Q($a_prop['name'])); 
    696656  } 
    697657 
    698658  $OUTPUT->add_gui_object('attachmentlist', $attrib['id']); 
    699659     
    700   $out .= '</ul>'; 
    701   return $out; 
     660  return html::tag('ul', $attrib, $out, html::$common_attrib); 
    702661} 
    703662 
     
    753712                 array(5, 4, 0, 2, 1)); 
    754713                  
    755   $sel = isset($_POST['_priority']) ? $_POST['_priority'] : intval($MESSAGE['headers']->priority); 
     714  $sel = isset($_POST['_priority']) ? $_POST['_priority'] : intval($MESSAGE->headers->priority); 
    756715 
    757716  $out = $form_start ? "$form_start\n" : ''; 
     
    778737 
    779738  $out = $form_start ? "$form_start\n" : ''; 
    780   $out .= $checkbox->show($MESSAGE['headers']->mdn_to ? 1 : 0); 
     739  $out .= $checkbox->show($MESSAGE->headers->mdn_to ? 1 : 0); 
    781740  $out .= $form_end ? "\n$form_end" : ''; 
    782741 
     
    794753  ); 
    795754 
    796   // determine whether HTML or plain text should be checked  
    797   if ($CONFIG['htmleditor']) 
    798     { 
    799     $useHtml = true; 
    800     } 
    801   else 
    802     { 
    803     $useHtml = false; 
    804     } 
    805  
    806   if ($compose_mode == RCUBE_COMPOSE_REPLY || 
    807       $compose_mode == RCUBE_COMPOSE_FORWARD || 
    808       $compose_mode == RCUBE_COMPOSE_DRAFT) 
    809   { 
    810     $hasHtml = rcmail_has_html_part($MESSAGE['parts']); 
    811     $useHtml = ($hasHtml && $CONFIG['htmleditor']); 
    812   } 
    813  
     755  // determine whether HTML or plain text should be checked 
     756  $useHtml = $CONFIG['htmleditor'] ? true : false; 
     757 
     758  if ($compose_mode) 
     759    $useHtml = ($useHtml && $MESSAGE->has_html_part()); 
     760 
     761  $selector = ''; 
    814762  $chosenvalue = $useHtml ? 'html' : 'plain'; 
    815  
    816   $selector = ''; 
    817    
    818   $attrib['name'] = '_editorSelect'; 
    819   $attrib['onclick'] = 'return rcmail_toggle_editor(this)'; 
     763  $radio = new html_radiobutton(array('name' => '_editorSelect', 'onclick' => 'return rcmail_toggle_editor(this)')); 
    820764  foreach ($choices as $value => $text) 
    821765  { 
    822766    $attrib['id'] = '_' . $value; 
    823767    $attrib['value'] = $value; 
    824     $rb = new html_radiobutton($attrib); 
    825     $selector .= sprintf("%s<label for=\"%s\">%s</label>", 
    826                          $rb->show($chosenvalue), 
    827                          $attrib['id'], 
    828                          rcube_label($text)); 
     768    $selector .= $radio->show($chosenvalue, $attrib) . html::label($attrib['id'], Q(rcube_label($text))); 
    829769  } 
    830770 
Note: See TracChangeset for help on using the changeset viewer.