Changeset 83a7636 in github


Ignore:
Timestamp:
Jun 14, 2008 8:23:08 AM (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:
fca66b0
Parents:
f0d4b72
Message:

More code cleanup

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • index.php

    r5e0045b r83a7636  
    33 +-------------------------------------------------------------------------+ 
    44 | RoundCube Webmail IMAP Client                                           | 
    5  | Version 0.1-20080506                                                    | 
     5 | Version 0.2-20080614                                                    | 
    66 |                                                                         | 
    77 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                   | 
     
    3333// define global vars 
    3434$OUTPUT_TYPE = 'html'; 
     35 
     36// init application and start session with requested task 
     37$RCMAIL = rcmail::get_instance(); 
     38 
     39// init output class 
     40$OUTPUT = !empty($_REQUEST['_remote']) ? $RCMAIL->init_json() : $RCMAIL->load_gui(!empty($_REQUEST['_framed'])); 
    3541 
    3642// set output buffering 
     
    4753} 
    4854 
    49  
    50 // init application and start session with requested task 
    51 $RCMAIL = rcmail::get_instance(); 
    52  
    53 // init output class 
    54 $OUTPUT = (!empty($_GET['_remote']) || !empty($_POST['_remote'])) ? $RCMAIL->init_json() : $RCMAIL->load_gui((!empty($_GET['_framed']) || !empty($_POST['_framed']))); 
    55  
    56  
    5755// check DB connections and exit on failure 
    5856if ($err_str = $DB->is_error()) { 
     
    128126 
    129127 
    130 // not logged in -> set task to 'login 
     128// check client X-header to verify request origin 
     129if ($OUTPUT->ajax_call) { 
     130  if ($RCMAIL->config->get('devel_mode') && !rc_request_header('X-RoundCube-Referer')) { 
     131    header('HTTP/1.1 404 Not Found'); 
     132    die("Invalid Request"); 
     133  } 
     134} 
     135 
     136 
     137// not logged in -> show login page 
    131138if (empty($RCMAIL->user->ID)) { 
     139   
    132140  if ($OUTPUT->ajax_call) 
    133141    $OUTPUT->remote_response("setTimeout(\"location.href='\"+this.env.comm_path+\"'\", 2000);"); 
    134142   
    135   $RCMAIL->set_task('login'); 
    136 } 
    137  
    138  
    139 // check client X-header to verify request origin 
    140 if ($OUTPUT->ajax_call) { 
    141   if (empty($CONFIG['devel_mode']) && !rc_request_header('X-RoundCube-Referer')) { 
    142     header('HTTP/1.1 404 Not Found'); 
    143     die("Invalid Request"); 
    144   } 
    145 } 
    146  
    147  
    148 // not logged in -> show login page 
    149 if (empty($RCMAIL->user->ID)) { 
    150143  // check if installer is still active 
    151   if ($CONFIG['enable_installer'] && is_readable('./installer/index.php')) { 
     144  if ($RCMAIL->config->get('enable_installer') && is_readable('./installer/index.php')) { 
    152145    $OUTPUT->add_footer(html::div(array('style' => "background:#ef9398; border:2px solid #dc5757; padding:0.5em; margin:2em auto; width:50em"), 
    153146      html::tag('h2', array('style' => "margin-top:0.2em"), "Installer script is still accessible") . 
     
    161154   
    162155  $OUTPUT->set_env('task', 'login'); 
    163   $OUTPUT->task = 'login'; 
    164156  $OUTPUT->send('login'); 
    165   exit; 
    166157} 
    167158 
     
    170161if ($RCMAIL->action=='keep-alive') { 
    171162  $OUTPUT->reset(); 
    172   $OUTPUT->send(''); 
    173   exit; 
     163  $OUTPUT->send(); 
    174164} 
    175165 
  • program/include/html.php

    r6025c83 r83a7636  
    572572     * @param string Cell content 
    573573     */ 
    574     private function add_header($attr, $cont) 
     574    public function add_header($attr, $cont) 
    575575    { 
    576576        if (is_string($attr)) 
     
    588588     * @param array Row attributes 
    589589     */ 
    590     private function add_row($attr = array()) 
     590    public function add_row($attr = array()) 
    591591    { 
    592592        $this->rowindex++; 
     
    613613            $rowcontent = ''; 
    614614            foreach ($this->header as $c => $col) { 
    615                 $rowcontent .= self::tag('th', $col->attrib, $col->content); 
     615                $rowcontent .= self::tag('td', $col->attrib, $col->content); 
    616616            } 
    617617            $thead = self::tag('thead', null, self::tag('tr', null, $rowcontent)); 
     
    625625 
    626626            if ($r < $this->rowindex || count($row->cells)) { 
    627                 $tbody .= self::tag('tr', $rows->attrib, $rowcontent); 
     627                $tbody .= self::tag('tr', $row->attrib, $rowcontent); 
    628628            } 
    629629        } 
  • program/include/iniset.php

    r197601e r83a7636  
    2323 
    2424// application constants 
    25 define('RCMAIL_VERSION', '0.1-trunk'); 
     25define('RCMAIL_VERSION', '0.2-trunk'); 
    2626define('RCMAIL_CHARSET', 'UTF-8'); 
    2727define('JS_OBJECT_NAME', 'rcmail'); 
  • program/include/main.inc

    r0be1bcbc r83a7636  
    103103  return rcmail::get_instance()->gettext($p); 
    104104} 
    105  
    106  
    107 /** 
    108  * Load virtuser table in array 
    109  * 
    110  * @return array Virtuser table entries 
    111  */ 
    112 function rcmail_getvirtualfile() 
    113   { 
    114   global $CONFIG; 
    115   if (empty($CONFIG['virtuser_file']) || !is_file($CONFIG['virtuser_file'])) 
    116     return FALSE; 
    117    
    118   // read file  
    119   $a_lines = file($CONFIG['virtuser_file']); 
    120   return $a_lines; 
    121   } 
    122  
    123  
    124 /** 
    125  * Find matches of the given pattern in virtuser table 
    126  *  
    127  * @param string Regular expression to search for 
    128  * @return array Matching entries 
    129  */ 
    130 function rcmail_findinvirtual($pattern) 
    131   { 
    132   $result = array(); 
    133   $virtual = rcmail_getvirtualfile(); 
    134   if ($virtual==FALSE) 
    135     return $result; 
    136  
    137   // check each line for matches 
    138   foreach ($virtual as $line) 
    139     { 
    140     $line = trim($line); 
    141     if (empty($line) || $line{0}=='#') 
    142       continue; 
    143        
    144     if (eregi($pattern, $line)) 
    145       $result[] = $line; 
    146     } 
    147  
    148   return $result; 
    149   } 
    150105 
    151106 
     
    575530function rcube_table_output($attrib, $table_data, $a_show_cols, $id_col) 
    576531  { 
    577   global $DB; 
    578    
    579   // allow the following attributes to be added to the <table> tag 
    580   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary')); 
    581    
    582   $table = '<table' . $attrib_str . ">\n"; 
     532  global $RCMAIL; 
     533   
     534  $table = new html_table(/*array('cols' => count($a_show_cols))*/); 
    583535     
    584   // add table title 
    585   $table .= "<thead><tr>\n"; 
    586  
     536  // add table header 
    587537  foreach ($a_show_cols as $col) 
    588     $table .= '<td class="'.$col.'">' . Q(rcube_label($col)) . "</td>\n"; 
    589  
    590   $table .= "</tr></thead>\n<tbody>\n"; 
     538    $table->add_header($col, Q(rcube_label($col))); 
    591539   
    592540  $c = 0; 
    593541  if (!is_array($table_data))  
    594     { 
    595     while ($table_data && ($sql_arr = $DB->fetch_assoc($table_data))) 
    596       { 
    597       $zebra_class = $c%2 ? 'even' : 'odd'; 
    598  
    599       $table .= sprintf('<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", $sql_arr[$id_col]); 
     542  { 
     543    $db = $RCMAIL->get_dbh(); 
     544    while ($table_data && ($sql_arr = $db->fetch_assoc($table_data))) 
     545    { 
     546      $zebra_class = $c % 2 ? 'even' : 'odd'; 
     547      $table->add_row(array('id' => 'rcmrow' . $sql_arr[$id_col], 'class' => "contact $zebra_class")); 
    600548 
    601549      // format each col 
    602550      foreach ($a_show_cols as $col) 
    603         { 
    604         $cont = Q($sql_arr[$col]); 
    605         $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
    606         } 
    607  
    608       $table .= "</tr>\n"; 
     551        $table->add($col, Q($sql_arr[$col])); 
     552       
    609553      $c++; 
    610       } 
    611     } 
     554    } 
     555  } 
    612556  else  
    613     { 
     557  { 
    614558    foreach ($table_data as $row_data) 
    615       { 
    616       $zebra_class = $c%2 ? 'even' : 'odd'; 
    617  
    618       $table .= sprintf('<tr id="rcmrow%s" class="contact '.$zebra_class.'">'."\n", $row_data[$id_col]); 
     559    { 
     560      $zebra_class = $c % 2 ? 'even' : 'odd'; 
     561      $table->add_row(array('id' => 'rcmrow' . $row_data[$id_col], 'class' => "contact $zebra_class")); 
    619562 
    620563      // format each col 
    621564      foreach ($a_show_cols as $col) 
    622         { 
    623         $cont = Q($row_data[$col]); 
    624         $table .= '<td class="'.$col.'">' . $cont . "</td>\n"; 
    625         } 
    626  
    627       $table .= "</tr>\n"; 
     565        $table->add($col, Q($row_data[$col])); 
     566         
    628567      $c++; 
    629       } 
    630     } 
    631  
    632   // complete message table 
    633   $table .= "</tbody></table>\n"; 
    634    
    635   return $table; 
     568    } 
     569  } 
     570 
     571  return $table->show($attrib); 
    636572  } 
    637573 
     
    671607          
    672608  return $out; 
    673   } 
    674  
    675  
    676 /** 
    677  * Return the mail domain configured for the given host 
    678  * 
    679  * @param string IMAP host 
    680  * @return string Resolved SMTP host 
    681  */ 
    682 function rcmail_mail_domain($host) 
    683   { 
    684   global $CONFIG; 
    685  
    686   $domain = $host; 
    687   if (is_array($CONFIG['mail_domain'])) 
    688     { 
    689     if (isset($CONFIG['mail_domain'][$host])) 
    690       $domain = $CONFIG['mail_domain'][$host]; 
    691     } 
    692   else if (!empty($CONFIG['mail_domain'])) 
    693     $domain = $CONFIG['mail_domain']; 
    694  
    695   return $domain; 
    696609  } 
    697610 
     
    744657  return $styles; 
    745658  } 
    746  
    747 /** 
    748  * Try to autodetect operating system and find the correct line endings 
    749  * 
    750  * @return string The appropriate mail header delimiter 
    751  */ 
    752 function rcmail_header_delm() 
    753 { 
    754   global $CONFIG; 
    755    
    756   // use the configured delimiter for headers 
    757   if (!empty($CONFIG['mail_header_delimiter'])) 
    758     return $CONFIG['mail_header_delimiter']; 
    759   else if (strtolower(substr(PHP_OS, 0, 3)=='win'))  
    760     return "\r\n"; 
    761   else if (strtolower(substr(PHP_OS, 0, 3)=='mac')) 
    762     return "\r\n"; 
    763   else     
    764     return "\n"; 
    765 } 
    766659 
    767660 
  • program/include/rcube_config.php

    r033478d r83a7636  
    178178   
    179179   
     180  /** 
     181   * Try to autodetect operating system and find the correct line endings 
     182   * 
     183   * @return string The appropriate mail header delimiter 
     184   */ 
     185  public function header_delimiter() 
     186  { 
     187    // use the configured delimiter for headers 
     188    if (!empty($this->prop['mail_header_delimiter'])) 
     189      return $this->prop['mail_header_delimiter']; 
     190    else if (strtolower(substr(PHP_OS, 0, 3) == 'win')) 
     191      return "\r\n"; 
     192    else if (strtolower(substr(PHP_OS, 0, 3) == 'mac')) 
     193      return "\r\n"; 
     194    else 
     195      return "\n"; 
     196  } 
     197 
     198   
     199   
     200  /** 
     201   * Return the mail domain configured for the given host 
     202   * 
     203   * @param string IMAP host 
     204   * @return string Resolved SMTP host 
     205   */ 
     206  public function mail_domain($host) 
     207  { 
     208    $domain = $host; 
     209     
     210    if (is_array($this->prop['mail_domain'])) { 
     211      if (isset($this->prop['mail_domain'][$host])) 
     212        $domain = $this->prop['mail_domain'][$host]; 
     213    } 
     214    else if (!empty($this->prop['mail_domain'])) 
     215      $domain = $this->prop['mail_domain']; 
     216     
     217    return $domain; 
     218  } 
     219 
     220 
    180221} 
    181222 
  • program/include/rcube_json_output.php

    ra4e6ed1 r83a7636  
    3535    private $commands = array(); 
    3636 
    37     public $task = ''; 
    3837    public $ajax_call = true; 
    3938     
     
    4443    public function __construct($task) 
    4544    { 
    46         $this->task   = $task; 
    4745        $this->config = rcmail::get_instance()->config; 
    4846    } 
  • program/include/rcube_template.php

    r23bba05 r83a7636  
    3333    var $app; 
    3434    var $config; 
    35     var $task = ''; 
    3635    var $framed = false; 
    3736    var $pagetitle = ''; 
     
    5756         
    5857        //$this->framed = $framed; 
    59         $this->task = $task; 
     58        $this->set_env('task', $task); 
    6059 
    6160        // add common javascripts 
     
    543542                } 
    544543                if ($object=='pagetitle') { 
    545                     $task  = $this->task; 
     544                    $task  = $this->env['task']; 
    546545                    $title = !empty($this->config['product_name']) ? $this->config['product_name'].' :: ' : ''; 
    547546 
  • program/include/rcube_user.php

    r45f56c1 r83a7636  
    363363    if ($user_id = $dbh->insert_id(get_sequence_name('users'))) 
    364364    { 
    365       $mail_domain = rcmail_mail_domain($host); 
     365      $mail_domain = $rcmail->config->mail_domain($host); 
    366366 
    367367      if ($user_email=='') 
     
    421421  { 
    422422    $user = $email; 
    423     $r = rcmail_findinvirtual("^$email"); 
     423    $r = self::findinvirtual("^$email"); 
    424424 
    425425    for ($i=0; $i<count($r); $i++) 
     
    447447  { 
    448448    $email = ""; 
    449     $r = rcmail_findinvirtual("$user$"); 
     449    $r = self::findinvirtual("$user$"); 
    450450 
    451451    for ($i=0; $i<count($r); $i++) 
     
    462462    return $email; 
    463463  } 
     464   
     465   
     466  /** 
     467   * Find matches of the given pattern in virtuser table 
     468   *  
     469   * @param string Regular expression to search for 
     470   * @return array Matching entries 
     471   */ 
     472  private static function findinvirtual($pattern) 
     473  { 
     474    $result = array(); 
     475    $virtual = null; 
     476     
     477    if ($virtuser_file = rcmail::get_instance()->config->get('virtuser_file')) 
     478      $virtual = file($virtuser_file); 
     479     
     480    if (empty($virtual)) 
     481      return $result; 
     482     
     483    // check each line for matches 
     484    foreach ($virtual as $line) 
     485    { 
     486      $line = trim($line); 
     487      if (empty($line) || $line{0}=='#') 
     488        continue; 
     489         
     490      if (eregi($pattern, $line)) 
     491        $result[] = $line; 
     492    } 
     493     
     494    return $result; 
     495  } 
     496 
    464497 
    465498} 
  • program/steps/mail/func.inc

    r32b7092 r83a7636  
    10411041function rcmail_send_mdn($uid) 
    10421042{ 
    1043   global $CONFIG, $USER, $IMAP; 
     1043  global $RCMAIL, $IMAP; 
    10441044 
    10451045  $message = new rcube_message($uid); 
     
    10471047  if ($message->headers->mdn_to && !$message->headers->mdn_sent) 
    10481048  { 
    1049     $identity = $USER->get_identity(); 
     1049    $identity = $RCMAIL->user->get_identity(); 
    10501050    $sender = format_email_recipient($identity['email'], $identity['name']); 
    10511051    $recipient = array_shift($IMAP->decode_address_list($message->headers->mdn_to)); 
    10521052    $mailto = $recipient['mailto']; 
    10531053 
    1054     $compose = new rcube_mail_mime(rcmail_header_delm()); 
     1054    $compose = new rcube_mail_mime($RCMAIL->config->header_delimiter()); 
    10551055    $compose->setParam(array( 
    10561056      'text_encoding' => 'quoted-printable', 
     
    10681068      'To'   => $message->headers->mdn_to, 
    10691069      'Subject' => rcube_label('receiptread') . ': ' . $message->subject, 
    1070       'Message-ID' => sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), rcmail_mail_domain($_SESSION['imap_host'])), 
     1070      'Message-ID' => sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host'])), 
    10711071      'X-Sender' => $identity['email'], 
    10721072      'Content-Type' => 'multipart/report; report-type=disposition-notification', 
    10731073    ); 
    10741074     
    1075     if (!empty($CONFIG['useragent'])) 
    1076       $headers['User-Agent'] = $CONFIG['useragent']; 
     1075    if ($agent = $RCMAIL->config->get('useragent')) 
     1076      $headers['User-Agent'] = $agent; 
    10771077 
    10781078    $body = rcube_label("yourmessage") . "\r\n\r\n" . 
    10791079      "\t" . rcube_label("to") . ': ' . rcube_imap::decode_mime_string($message->headers->to, $message->headers->charset) . "\r\n" . 
    10801080      "\t" . rcube_label("subject") . ': ' . $message->subject . "\r\n" . 
    1081       "\t" . rcube_label("sent") . ': ' . format_date($message->headers->date, $CONFIG['date_long']) . "\r\n" . 
     1081      "\t" . rcube_label("sent") . ': ' . format_date($message->headers->date, $RCMAIL->config->get('date_long')) . "\r\n" . 
    10821082      "\r\n" . rcube_label("receiptnote") . "\r\n"; 
    10831083     
    1084     $ua = !empty($CONFIG['useragent']) ? $CONFIG['useragent'] : "RoundCube Webmail (Version ".RCMAIL_VERSION.")"; 
     1084    $ua = $RCMAIL->config->get('useragent', "RoundCube Webmail (Version ".RCMAIL_VERSION.")"); 
    10851085    $report = "Reporting-UA: $ua\r\n"; 
    10861086     
  • program/steps/mail/sendmail.inc

    r197601e r83a7636  
    114114  $olddraftmessageid = get_input_value('_draft_saveid', RCUBE_INPUT_POST); 
    115115 
    116 $message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), rcmail_mail_domain($_SESSION['imap_host'])); 
     116$message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), $RCMAIL->config->mail_domain($_SESSION['imap_host'])); 
    117117$savedraft = !empty($_POST['_draft']) ? TRUE : FALSE; 
    118118 
     
    208208if ($CONFIG['http_received_header']) 
    209209{ 
    210   $nldlm = rcmail_header_delm() . "\t"; 
     210  $nldlm = $RCMAIL->config->header_delimiter() . "\t"; 
    211211  $headers['Received'] =  wordwrap('from ' . (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? 
    212212      gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']).' ['.$_SERVER['HTTP_X_FORWARDED_FOR'].']'.$nldlm.' via ' : '') . 
     
    233233 
    234234// create extended PEAR::Mail_mime instance 
    235 $MAIL_MIME = new rcube_mail_mime(rcmail_header_delm()); 
     235$MAIL_MIME = new rcube_mail_mime($RCMAIL->config->header_delimiter()); 
    236236 
    237237// For HTML-formatted messages, construct the MIME message with both 
Note: See TracChangeset for help on using the changeset viewer.