Changeset 9800a82 in github


Ignore:
Timestamp:
May 6, 2010 3:39:57 AM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
69729855
Parents:
1f019c8
Message:
  • improve performance and consistency by setting all list-related env data in list action only
Location:
program
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • program/js/app.js

    r1f019c8 r9800a82  
    166166        if (this.gui_objects.messagelist) { 
    167167 
    168           this.message_list = new rcube_list_widget(this.gui_objects.messagelist, 
    169             {multiselect:true, multiexpand:true, draggable:true, keyboard:true, 
    170             column_movable:this.env.col_movable, column_fixed:0, dblclick_time:this.dblclick_time}); 
     168          this.message_list = new rcube_list_widget(this.gui_objects.messagelist, { 
     169            multiselect:true, multiexpand:true, draggable:true, keyboard:true, 
     170            column_movable:this.env.col_movable, column_fixed:0, dblclick_time:this.dblclick_time 
     171            }); 
    171172          this.message_list.row_init = function(o){ p.init_message_row(o); }; 
    172173          this.message_list.addEventListener('dblclick', function(o){ p.msglist_dbl_click(o); }); 
     
    187188 
    188189          // load messages 
    189           if (this.env.messagecount) 
    190             this.command('list'); 
     190          this.command('list'); 
    191191        } 
    192192 
     
    247247        else if (this.env.action == 'print') 
    248248          window.print(); 
    249  
    250         if (this.env.messagecount) { 
    251           this.enable_command('select-all', 'select-none', 'expunge', true); 
    252           this.enable_command('expand-all', 'expand-unread', 'collapse-all', this.env.threading); 
    253         } 
    254  
    255         if (this.purge_mailbox_test()) 
    256           this.enable_command('purge', true); 
    257  
    258         this.set_page_buttons(); 
    259249 
    260250        // get unread count for each mailbox 
  • program/steps/mail/func.inc

    rb62c486 r9800a82  
    8989      { 
    9090      $search_request = md5($mbox_name.$_SESSION['search_filter']); 
    91    
     91 
    9292      $IMAP->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $_SESSION['sort_col']); 
    9393      $_SESSION['search'][$search_request] = $IMAP->get_search_set(); 
    9494      $OUTPUT->set_env('search_request', $search_request); 
    9595      } 
    96      
     96 
    9797      $search_mods = $RCMAIL->config->get('search_mods', $SEARCH_MODS_DEFAULT); 
    9898      $OUTPUT->set_env('search_mods', $search_mods); 
    99        
    100       // make sure the message count is refreshed (for default view) 
    101       $IMAP->messagecount($mbox_name, $IMAP->threading ? 'THREADS' : 'ALL', true); 
    102     } 
    103          
     99    } 
     100 
    104101  // set current mailbox and some other vars in client environment 
    105102  $OUTPUT->set_env('mailbox', $mbox_name); 
     
    166163  // save some variables for use in ajax list 
    167164  $_SESSION['list_attrib'] = $attrib; 
    168    
     165 
    169166  $mbox = $IMAP->get_mailbox_name(); 
    170167  $delim = $IMAP->get_hierarchy_delimiter(); 
     
    176173 
    177174  $skin_path = $_SESSION['skin_path'] = $CONFIG['skin_path']; 
    178   $message_count = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL'); 
    179    
     175 
    180176  // set client env 
    181177  $OUTPUT->add_gui_object('messagelist', $attrib['id']); 
    182178  $OUTPUT->set_env('autoexpand_threads', intval($CONFIG['autoexpand_threads'])); 
    183   $OUTPUT->set_env('messagecount', $message_count); 
    184   $OUTPUT->set_env('current_page', $IMAP->list_page); 
    185   $OUTPUT->set_env('pagecount', ceil($message_count/$IMAP->page_size)); 
    186179  $OUTPUT->set_env('sort_col', $_SESSION['sort_col']); 
    187180  $OUTPUT->set_env('sort_order', $_SESSION['sort_order']); 
    188    
     181 
    189182  if ($attrib['messageicon']) 
    190183    $OUTPUT->set_env('messageicon', $skin_path . $attrib['messageicon']); 
     
    207200  if ($attrib['unreadchildrenicon']) 
    208201    $OUTPUT->set_env('unreadchildrenicon', $skin_path . $attrib['unreadchildrenicon']); 
    209    
     202 
    210203  $OUTPUT->set_env('messages', array()); 
    211204  $OUTPUT->set_env('coltypes', $a_show_cols); 
    212    
    213   if (!$message_count) 
    214     $OUTPUT->show_message('nomessagesfound', 'notice'); 
    215    
     205 
    216206  $OUTPUT->include_script('list.js'); 
    217    
     207 
    218208  $thead = ''; 
    219209  foreach (rcmail_message_list_head($attrib, $a_show_cols) as $cell) 
    220210    $thead .= html::tag('td', array('class' => $cell['className'], 'id' => $cell['id']), $cell['html']); 
    221    
     211 
    222212  return html::tag('table', 
    223213    $attrib, 
     
    243233  $mbox = $IMAP->get_mailbox_name(); 
    244234  $delim = $IMAP->get_hierarchy_delimiter(); 
    245    
     235 
    246236  // show 'to' instead of 'from' in sent/draft messages 
    247237  if ((strpos($mbox.$delim, $CONFIG['sent_mbox'].$delim)===0 || strpos($mbox.$delim, $CONFIG['drafts_mbox'].$delim)===0) 
     
    250240 
    251241  $thead = $head_replace ? rcmail_message_list_head($_SESSION['list_attrib'], $a_show_cols) : NULL; 
    252    
     242 
    253243  $OUTPUT->command('set_message_coltypes', $a_show_cols, $thead); 
    254244 
     
    270260    $a_msg_cols = array(); 
    271261    $a_msg_flags = array(); 
    272      
     262 
    273263    if (empty($header)) 
    274264      continue; 
     
    293283      else 
    294284        $cont = Q($header->$col); 
    295            
     285 
    296286      $a_msg_cols[$col] = $cont; 
    297287      } 
     
    347337  // define sortable columns 
    348338  $a_sort_cols = array('subject', 'date', 'from', 'to', 'size', 'cc'); 
    349    
     339 
    350340  if (!empty($attrib['optionsmenuicon'])) 
    351341    $list_menu = html::a( 
     
    392382  { 
    393383  global $OUTPUT; 
    394    
     384 
    395385  if (empty($attrib['id'])) 
    396386    $attrib['id'] = 'rcmailcontentwindow'; 
     
    408398  { 
    409399  global $IMAP, $OUTPUT; 
    410    
     400 
    411401  if (!$attrib['id']) 
    412402    $attrib['id'] = 'rcmcountdisplay'; 
     
    429419 
    430420  $OUTPUT->add_gui_object('quotadisplay', $attrib['id']); 
    431    
     421 
    432422  $quota = rcmail_quota_content($attrib); 
    433    
     423 
    434424  if (is_array($quota)) { 
    435425    $OUTPUT->add_script('$(document).ready(function(){ 
     
    437427    $quota = ''; 
    438428    } 
    439    
     429 
    440430  return html::span($attrib, $quota); 
    441431  } 
     
    458448    if (!isset($quota['percent'])) 
    459449      $quota['percent'] = min(100, round(($quota['used']/max(1,$quota['total']))*100)); 
    460      
     450 
    461451    $quota_result = sprintf('%s / %s (%.0f%%)', 
    462452        show_bytes($quota['used'] * 1024), show_bytes($quota['total'] * 1024), 
     
    484474function rcmail_get_messagecount_text($count=NULL, $page=NULL) 
    485475  { 
    486   global $IMAP, $MESSAGE; 
    487    
     476  global $RCMAIL, $IMAP, $MESSAGE; 
     477 
    488478  if (isset($MESSAGE->index)) 
    489479    { 
     
    495485  if ($page===NULL) 
    496486    $page = $IMAP->list_page; 
    497      
     487 
    498488  $start_msg = ($page-1) * $IMAP->page_size + 1; 
    499   $max = $count!==NULL ? $count : $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL'); 
     489 
     490  if ($count!==NULL) 
     491    $max = $count; 
     492  else if ($RCMAIL->action) 
     493    $max = $IMAP->messagecount(NULL, $IMAP->threading ? 'THREADS' : 'ALL'); 
    500494 
    501495  if ($max==0) 
     
    534528{ 
    535529  global $RCMAIL; 
    536      
     530 
    537531  $old_unseen = $_SESSION['unseen_count'][$mbox_name]; 
    538532  $unseen = $RCMAIL->imap->messagecount($mbox_name, 'UNSEEN', $force); 
     
    543537  // @TODO: this data is doubled (session and cache tables) if caching is enabled 
    544538  $_SESSION['unseen_count'][$mbox_name] = $unseen; 
    545      
     539 
    546540  return $unseen; 
    547541} 
     
    642636    $wash_opts['html_attribs'] = array('rel','type'); 
    643637  } 
    644      
     638 
    645639  $washer = new washtml($wash_opts); 
    646640  $washer->add_callback('form', 'rcmail_washtml_callback'); 
     
    667661{ 
    668662  global $RCMAIL; 
    669    
     663 
    670664  // trigger plugin hook 
    671665  $data = $RCMAIL->plugins->exec_hook('message_part_before', 
     
    694688    $part->ctype_secondary = $data['type'] = 'plain'; 
    695689  } 
    696    
     690 
    697691  // free some memory (hopefully) 
    698692  unset($data['body']); 
     
    719713  // make links and email-addresses clickable 
    720714  $replacements = new rcube_string_replacer; 
    721      
     715 
    722716  // search for patterns like links and e-mail addresses 
    723717  $body = preg_replace_callback($replacements->link_pattern, array($replacements, 'link_callback'), $body); 
     
    793787      $out = html::div('form', $content); 
    794788      break; 
    795        
     789 
    796790    case 'style': 
    797791      // decode all escaped entities and reduce to ascii strings 
    798792      $stripped = preg_replace('/[^a-zA-Z\(:]/', '', rcmail_xss_entity_decode($content)); 
    799        
     793 
    800794      // now check for evil strings like expression, behavior or url() 
    801795      if (!preg_match('/expression|behavior|url\(|import/', $stripped)) { 
     
    803797        break; 
    804798      } 
    805      
     799 
    806800    default: 
    807801      $out = ''; 
    808802  } 
    809    
     803 
    810804  return $out; 
    811805} 
     
    835829  global $IMAP, $OUTPUT, $MESSAGE, $PRINT_MODE, $RCMAIL; 
    836830  static $sa_attrib; 
    837    
     831 
    838832  // keep header table attrib 
    839833  if (is_array($attrib) && !$sa_attrib) 
     
    841835  else if (!is_array($attrib) && is_array($sa_attrib)) 
    842836    $attrib = $sa_attrib; 
    843    
     837 
    844838  if (!isset($MESSAGE)) 
    845839    return FALSE; 
     
    875869    else 
    876870      $header_value = trim($IMAP->decode_header($headers[$hkey])); 
    877        
     871 
    878872    $output_headers[$hkey] = array('title' => rcube_label($hkey), 'value' => $header_value, 'raw' => $headers[$hkey]); 
    879873  } 
    880      
     874 
    881875  $plugin = $RCMAIL->plugins->exec_hook('message_headers_output', array('output' => $output_headers, 'headers' => $MESSAGE->headers)); 
    882    
     876 
    883877  // compose html table 
    884878  $table = new html_table(array('cols' => 2)); 
    885    
     879 
    886880  foreach ($plugin['output'] as $hkey => $row) { 
    887881    $table->add(array('class' => 'header-title'), Q($row['title'])); 
     
    913907  if (!is_array($MESSAGE->parts) && empty($MESSAGE->body)) 
    914908    return ''; 
    915      
     909 
    916910  if (!$attrib['id']) 
    917911    $attrib['id'] = 'rcmailMsgBody'; 
     
    919913  $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']); 
    920914  $out = ''; 
    921    
     915 
    922916  $header_attrib = array(); 
    923917  foreach ($attrib as $attr => $value) 
     
    973967    } 
    974968  } 
    975    
     969 
    976970  // tell client that there are blocked remote objects 
    977971  if ($REMOTE_OBJECTS && !$safe_mode) 
     
    10061000  $last_style_pos = 0; 
    10071001  $body_lc = strtolower($body); 
    1008    
     1002 
    10091003  // find STYLE tags 
    10101004  while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos))) 
     
    10691063{ 
    10701064  global $EMAIL_ADDRESS_PATTERN; 
    1071    
     1065 
    10721066  $tag = $matches[1]; 
    10731067  $attrib = parse_attrib_string($matches[2]); 
     
    11511145        $out .= (strlen($out) ? ' ' : '') . sprintf('&lt;%s&gt;', Q($part['mailto'])); 
    11521146    } 
    1153        
     1147 
    11541148    if ($c>$j) 
    11551149      $out .= ','.($max ? '&nbsp;' : ' '); 
    1156          
     1150 
    11571151    if ($max && $j==$max && $c>$j) { 
    11581152      $out .= '...'; 
     
    11601154    } 
    11611155  } 
    1162      
     1156 
    11631157  return $out; 
    11641158} 
     
    12051199    $out .= $line . "\n"; 
    12061200  } 
    1207    
     1201 
    12081202  return $out; 
    12091203} 
     
    12151209  foreach ($p as $key => $val) 
    12161210    $parts[] = $key . '=' . ($key == 'folder' ? base64_encode($val) : $val); 
    1217    
     1211 
    12181212  return join('; ', $parts); 
    12191213} 
     
    12291223    $info[$key] = $val; 
    12301224  } 
    1231    
     1225 
    12321226  return $info; 
    12331227} 
     
    12371231  { 
    12381232  global $MESSAGE; 
    1239    
     1233 
    12401234  $part = asciiwords(get_input_value('_part', RCUBE_INPUT_GPC)); 
    12411235  if (!is_object($MESSAGE) || !is_array($MESSAGE->parts) || !($_GET['_uid'] && $_GET['_part']) || !$MESSAGE->mime_parts[$part]) 
    12421236    return ''; 
    1243      
     1237 
    12441238  $part = $MESSAGE->mime_parts[$part]; 
    12451239  $table = new html_table(array('cols' => 3)); 
    1246    
     1240 
    12471241  if (!empty($part->filename)) { 
    12481242    $table->add('title', Q(rcube_label('filename'))); 
     
    12501244    $table->add(null, '[' . html::a('?'.str_replace('_frame=', '_download=', $_SERVER['QUERY_STRING']), Q(rcube_label('download'))) . ']'); 
    12511245  } 
    1252    
     1246 
    12531247  if (!empty($part->size)) { 
    12541248    $table->add('title', Q(rcube_label('filesize'))); 
    12551249    $table->add(null, Q(show_bytes($part->size))); 
    12561250  } 
    1257    
     1251 
    12581252  return $table->show($attrib); 
    12591253  } 
     
    12641258  { 
    12651259  global $MESSAGE; 
    1266    
     1260 
    12671261  $part = $MESSAGE->mime_parts[asciiwords(get_input_value('_part', RCUBE_INPUT_GPC))]; 
    12681262  $ctype_primary = strtolower($part->ctype_primary); 
     
    12861280  $rcmail->session->remove('compose'); 
    12871281  } 
    1288    
     1282 
    12891283 
    12901284/** 
     
    13091303    // generate list of recipients 
    13101304    $a_recipients = array($mailto); 
    1311    
     1305 
    13121306    if (strlen($headers['Cc'])) 
    13131307      $a_recipients[] = $headers['Cc']; 
    13141308    if (strlen($headers['Bcc'])) 
    13151309      $a_recipients[] = $headers['Bcc']; 
    1316    
     1310 
    13171311    // clean Bcc from header for recipients 
    13181312    $send_headers = $headers; 
     
    13421336    if (!is_object($RCMAIL->smtp)) 
    13431337      $RCMAIL->smtp_init(true); 
    1344       
     1338 
    13451339    $sent = $RCMAIL->smtp->send_mail($from, $a_recipients, $smtp_headers, $msg_body); 
    13461340    $smtp_response = $RCMAIL->smtp->get_response(); 
     
    13621356    $headers_php = $message->_headers; 
    13631357    unset($headers_php['To'], $headers_php['Subject']); 
    1364      
     1358 
    13651359    // reset stored headers and overwrite 
    13661360    $message->_headers = array(); 
    13671361    $header_str = $message->txtHeaders($headers_php); 
    1368      
     1362 
    13691363    // #1485779 
    13701364    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 
     
    13731367        } 
    13741368      } 
    1375      
     1369 
    13761370    $msg_body = $message->get(); 
    13771371 
     
    13861380      $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from"); 
    13871381  } 
    1388    
     1382 
    13891383  if ($sent) { 
    13901384    $RCMAIL->plugins->exec_hook('message_sent', array('headers' => $headers, 'body' => $msg_body)); 
    1391      
     1385 
    13921386    // remove MDN headers after sending 
    13931387    unset($headers['Return-Receipt-To'], $headers['Disposition-Notification-To']); 
    1394      
     1388 
    13951389    if ($CONFIG['smtp_log']) { 
    13961390      write_log('sendmail', sprintf("User %s [%s]; Message for %s; %s", 
     
    14041398  $message->_headers = array(); 
    14051399  $message->headers($headers); 
    1406    
     1400 
    14071401  return $sent; 
    14081402} 
     
    14141408 
    14151409  $message = new rcube_message($uid); 
    1416    
     1410 
    14171411  if ($message->headers->mdn_to && !$message->headers->mdn_sent && 
    14181412    ($IMAP->check_permflag('MDNSENT') || $IMAP->check_permflag('*'))) 
     
    14311425    $compose->setParam('html_charset', RCMAIL_CHARSET); 
    14321426    $compose->setParam('text_charset', RCMAIL_CHARSET); 
    1433      
     1427 
    14341428    // compose headers array 
    14351429    $headers = array( 
     
    14421436      'References' => trim($message->headers->references . ' ' . $message->headers->messageID), 
    14431437    ); 
    1444      
     1438 
    14451439    if ($agent = $RCMAIL->config->get('useragent')) 
    14461440      $headers['User-Agent'] = $agent; 
     
    14511445      "\t" . rcube_label("sent") . ': ' . format_date($message->headers->date, $RCMAIL->config->get('date_long')) . "\r\n" . 
    14521446      "\r\n" . rcube_label("receiptnote") . "\r\n"; 
    1453      
     1447 
    14541448    $ua = $RCMAIL->config->get('useragent', "RoundCube Webmail (Version ".RCMAIL_VERSION.")"); 
    14551449    $report = "Reporting-UA: $ua\r\n"; 
    1456      
     1450 
    14571451    if ($message->headers->to) 
    14581452        $report .= "Original-Recipient: {$message->headers->to}\r\n"; 
    1459      
     1453 
    14601454    $report .= "Final-Recipient: rfc822; {$identity['email']}\r\n" . 
    14611455               "Original-Message-ID: {$message->headers->messageID}\r\n" . 
    14621456               "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; 
    1463      
     1457 
    14641458    $compose->headers($headers); 
    14651459    $compose->setContentType('multipart/report', array('report-type'=> 'disposition-notification')); 
     
    14751469    } 
    14761470  } 
    1477    
     1471 
    14781472  return false; 
    14791473} 
     
    14871481 
    14881482  $attrib['onchange'] = JS_OBJECT_NAME.'.filter_mailbox(this.value)'; 
    1489    
     1483 
    14901484  /* 
    14911485    RFC3501 (6.4.4): 'ALL', 'RECENT',  
     
    15081502  $OUTPUT->add_gui_object('search_filter', $attrib['id']); 
    15091503 
    1510   return $out;                                                                           
     1504  return $out; 
    15111505} 
    15121506 
     
    15291523 
    15301524?> 
     1525 
  • program/steps/mail/list.inc

    rb62c486 r9800a82  
    7979$OUTPUT->set_env('pagecount', $pages); 
    8080$OUTPUT->set_env('threading', (bool) $IMAP->threading); 
     81$OUTPUT->set_env('current_page', $IMAP->list_page); 
    8182$OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($count)); 
    8283$OUTPUT->command('set_mailboxname', rcmail_get_mailbox_name_text()); 
     
    9899 
    99100?> 
     101 
Note: See TracChangeset for help on using the changeset viewer.