Changeset 4d4264c in github


Ignore:
Timestamp:
Aug 10, 2006 3:07:43 AM (7 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
a06be98
Parents:
c0e9128
Message:

Fixed charset problems with folder renaming

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    rfa4cd20 r4d4264c  
    11CHANGELOG RoundCube Webmail 
    22--------------------------- 
     3 
     42006/08/10 (thomasb) 
     5---------- 
     6- Fixed charset problems with folder renaming 
     7 
    38 
    492006/08/04 (thomasb) 
  • program/include/main.inc

    raade7b9 r4d4264c  
    910910  if ($from=='UTF-7') 
    911911    $str = rcube_charset_convert(UTF7DecodeString($str), 'ISO-8859-1'); 
    912   else if ($from=='ISO-8859-1' && function_exists('utf8_encode')) 
     912  else if (($from=='ISO-8859-1') && function_exists('utf8_encode')) 
    913913    $str = utf8_encode($str); 
    914914  else if ($from!='UTF-8') 
     
    920920  // encode string for output 
    921921  if ($to=='UTF-7') 
    922     return UTF7EncodeString($str); 
     922    return UTF7EncodeString(rcube_charset_convert($str, 'UTF-8', 'ISO-8859-1')); 
    923923  else if ($to=='ISO-8859-1' && function_exists('utf8_decode')) 
    924924    return utf8_decode($str); 
  • program/include/rcube_imap.inc

    r42000a5 r4d4264c  
    2727require_once('lib/imap.inc'); 
    2828require_once('lib/mime.inc'); 
    29 require_once('lib/utf7.inc'); 
    3029 
    3130 
     
    836835      $results = $this->_search_index($mailbox, $search); 
    837836 
    838       // try search without charset (probably not supported by server) 
    839       if (empty($results)) 
    840         $results = $this->_search_index($mailbox, "$criteria $str"); 
     837      // try search with ISO charset (should be supported by server) 
     838      if (empty($results) && !empty($charset) && $charset!='ISO-8859-1') 
     839        $results = $this->search($mbox_name, $criteria, rcube_charset_convert($str, $charset, 'ISO-8859-1'), 'ISO-8859-1'); 
    841840       
    842841      return $results; 
     
    12321231 
    12331232  /** 
    1234    * create a new mailbox on the server and register it in local cache 
     1233   * Create a new mailbox on the server and register it in local cache 
     1234   * 
     1235   * @param string  New mailbox name (as utf-7 string) 
     1236   * @param boolean True if the new mailbox should be subscribed 
     1237   * @param string  Name of the created mailbox, false on error 
    12351238   */ 
    12361239  function create_mailbox($name, $subscribe=FALSE) 
     
    12411244    $name = preg_replace('/[\\\]+/', '-', $name); 
    12421245 
    1243     $name_enc = UTF7EncodeString($name); 
    1244  
    12451246    // reduce mailbox name to 100 chars 
    1246     $name_enc = substr($name_enc, 0, 100); 
    1247  
    1248     $abs_name = $this->_mod_mailbox($name_enc); 
     1247    $name = substr($name, 0, 100); 
     1248 
     1249    $abs_name = $this->_mod_mailbox($name); 
    12491250    $a_mailbox_cache = $this->get_cache('mailboxes'); 
    12501251 
     
    12541255    // try to subscribe it 
    12551256    if ($subscribe) 
    1256       $this->subscribe($name_enc); 
     1257      $this->subscribe($name); 
    12571258 
    12581259    return $result ? $name : FALSE; 
     
    12611262 
    12621263  /** 
    1263    * set a new name to an existing mailbox 
     1264   * Set a new name to an existing mailbox 
     1265   * 
     1266   * @param string Mailbox to rename (as utf-7 string) 
     1267   * @param string New mailbox name (as utf-7 string) 
     1268   * @param string Name of the renames mailbox, false on error 
    12641269   */ 
    12651270  function rename_mailbox($mbox_name, $new_name) 
     
    12711276         
    12721277    // encode mailbox name and reduce it to 100 chars 
    1273     $name_enc = substr(UTF7EncodeString($new_name), 0, 100); 
     1278    $name = substr($new_name, 0, 100); 
    12741279 
    12751280    // make absolute path 
    12761281    $mailbox = $this->_mod_mailbox($mbox_name); 
    1277     $abs_name = $this->_mod_mailbox($name_enc); 
    1278      
     1282    $abs_name = $this->_mod_mailbox($name); 
     1283 
    12791284    if (strlen($abs_name)) 
    12801285      $result = iil_C_RenameFolder($this->conn, $mailbox, $abs_name); 
    1281      
     1286 
    12821287    // clear cache 
    12831288    if ($result) 
     
    12861291      $this->clear_cache('mailboxes'); 
    12871292      } 
     1293       
     1294    // try to subscribe it 
     1295    $this->subscribe($name); 
    12881296 
    12891297    return $result ? $name : FALSE; 
  • program/js/app.js

    raade7b9 r4d4264c  
    712712              { 
    713713              this.set_busy(true); 
    714               location.href = this.env.comm_path+'&_action=compose&_draft_uid='+uid+'&_mbox='+escape(this.env.mailbox); 
     714              location.href = this.env.comm_path+'&_action=compose&_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox); 
    715715              } 
    716716            else 
     
    881881          var uid; 
    882882          if (uid = this.get_single_uid()) 
    883             url += '&_draft_uid='+uid+'&_mbox='+escape(this.env.mailbox); 
     883            url += '&_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox); 
    884884          }  
    885885        // modify url if we're in addressbook 
     
    993993          { 
    994994          this.set_busy(true); 
    995           location.href = this.env.comm_path+'&_action=compose&_reply_uid='+uid+'&_mbox='+escape(this.env.mailbox)+(command=='reply-all' ? '&_all=1' : ''); 
     995          location.href = this.env.comm_path+'&_action=compose&_reply_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(command=='reply-all' ? '&_all=1' : ''); 
    996996          } 
    997997        break;       
     
    10021002          { 
    10031003          this.set_busy(true); 
    1004           location.href = this.env.comm_path+'&_action=compose&_forward_uid='+uid+'&_mbox='+escape(this.env.mailbox); 
     1004          location.href = this.env.comm_path+'&_action=compose&_forward_uid='+uid+'&_mbox='+urlencode(this.env.mailbox); 
    10051005          } 
    10061006        break; 
     
    10101010        if (uid = this.get_single_uid()) 
    10111011          { 
    1012           this.printwin = window.open(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+escape(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : '')); 
     1012          this.printwin = window.open(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : '')); 
    10131013          if (this.printwin) 
    10141014            setTimeout(this.ref+'.printwin.focus()', 20); 
     
    10201020        if (uid = this.get_single_uid()) 
    10211021          {           
    1022           this.sourcewin = window.open(this.env.comm_path+'&_action=viewsource&_uid='+this.env.uid+'&_mbox='+escape(this.env.mailbox)); 
     1022          this.sourcewin = window.open(this.env.comm_path+'&_action=viewsource&_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox)); 
    10231023          if (this.sourcewin) 
    10241024            setTimeout(this.ref+'.sourcewin.focus()', 20); 
     
    10351035          props = this.gui_objects.qsearchbox.value; 
    10361036        if (props) 
    1037           this.qsearch(escape(props), this.env.mailbox); 
     1037          this.qsearch(urlencode(props), this.env.mailbox); 
    10381038        break; 
    10391039 
     
    12621262        { 
    12631263        this.set_busy(true); 
    1264         location.href = this.env.comm_path+'&_action=compose&_draft_uid='+id+'&_mbox='+escape(this.env.mailbox); 
     1264        location.href = this.env.comm_path+'&_action=compose&_draft_uid='+id+'&_mbox='+urlencode(this.env.mailbox); 
    12651265        } 
    12661266      else 
     
    15221522      { 
    15231523      this.set_busy(true, 'loading'); 
    1524       target.location.href = this.env.comm_path+'&_action=show&_uid='+id+'&_mbox='+escape(this.env.mailbox)+add_url; 
     1524      target.location.href = this.env.comm_path+'&_action=show&_uid='+id+'&_mbox='+urlencode(this.env.mailbox)+add_url; 
    15251525      } 
    15261526    }; 
     
    15941594      { 
    15951595      this.set_busy(true, 'loading'); 
    1596       target.location.href = this.env.comm_path+'&_mbox='+escape(mbox)+(page ? '&_page='+page : '')+add_url; 
     1596      target.location.href = this.env.comm_path+'&_mbox='+urlencode(mbox)+(page ? '&_page='+page : '')+add_url; 
    15971597      } 
    15981598    }; 
     
    16061606 
    16071607    // send request to server 
    1608     var url = '_mbox='+escape(mbox)+(page ? '&_page='+page : ''); 
     1608    var url = '_mbox='+urlencode(mbox)+(page ? '&_page='+page : ''); 
    16091609    this.set_busy(true, 'loading'); 
    16101610    this.http_request('list', url+add_url, true); 
     
    16581658 
    16591659    // send request to server 
    1660     var url = '_mbox='+escape(mbox); 
     1660    var url = '_mbox='+urlencode(mbox); 
    16611661    this.http_request('expunge', url+add_url, lock); 
    16621662    }; 
     
    16801680 
    16811681    // send request to server 
    1682     var url = '_mbox='+escape(mbox); 
     1682    var url = '_mbox='+urlencode(mbox); 
    16831683    this.http_request('purge', url+add_url, lock); 
    16841684    return true; 
     
    17371737      } 
    17381738    // send request to server 
    1739     this.http_request('moveto', '_uid='+a_uids.join(',')+'&_mbox='+escape(this.env.mailbox)+'&_target_mbox='+escape(mbox)+'&_from='+(this.env.action ? this.env.action : ''), lock); 
     1739    this.http_request('moveto', '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+'&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : ''), lock); 
    17401740    }; 
    17411741 
     
    17681768 
    17691769    // send request to server 
    1770     this.http_request('delete', '_uid='+a_uids.join(',')+'&_mbox='+escape(this.env.mailbox)+'&_from='+(this.env.action ? this.env.action : '')); 
     1770    this.http_request('delete', '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+'&_from='+(this.env.action ? this.env.action : '')); 
    17711771  } 
    17721772     
     
    22102210    { 
    22112211    if (name) 
    2212       this.http_request('remove-attachment', '_file='+escape(name)); 
     2212      this.http_request('remove-attachment', '_file='+urlencode(name)); 
    22132213 
    22142214    return true; 
     
    27232723 
    27242724    if (name) 
    2725       this.http_request('create-folder', '_name='+escape(name), true); 
     2725      this.http_request('create-folder', '_name='+urlencode(name), true); 
    27262726    else if (form.elements['_folder_name']) 
    27272727      form.elements['_folder_name'].focus(); 
     
    27462746 
    27472747    if (oldname && newname) 
    2748       this.http_request('rename-folder', '_folder_oldname='+escape(oldname)+'&_folder_newname='+escape(newname)); 
     2748      this.http_request('rename-folder', '_folder_oldname='+urlencode(oldname)+'&_folder_newname='+urlencode(newname)); 
    27492749    }; 
    27502750 
     
    27682768      { 
    27692769      this.name_input = document.createElement('INPUT'); 
    2770       this.name_input.value = this.env.subscriptionrows[id]; 
     2770      this.name_input.value = this.env.subscriptionrows[id][1]; 
    27712771      this.name_input.style.width = '100%'; 
    27722772      this.name_input.onkeypress = function(e){ rcmail.name_input_keypress(e); }; 
     
    27872787    var cell = this.name_input ? this.name_input.parentNode : null; 
    27882788    if (cell && this.edit_folder) 
    2789       cell.innerHTML = this.env.subscriptionrows[this.edit_folder]; 
     2789      cell.innerHTML = this.env.subscriptionrows[this.edit_folder][1]; 
    27902790       
    27912791    this.edit_folder = null; 
     
    28032803      var newname = this.name_input ? this.name_input.value : null; 
    28042804      if (this.edit_folder && newname) 
    2805         this.http_request('rename-folder', '_folder_oldname='+escape(this.env.subscriptionrows[this.edit_folder])+'&_folder_newname='+escape(newname));         
     2805        this.http_request('rename-folder', '_folder_oldname='+urlencode(this.env.subscriptionrows[this.edit_folder][0])+'&_folder_newname='+urlencode(newname));         
    28062806      } 
    28072807    // escape 
     
    28182818     
    28192819    if (folder) 
    2820       this.http_request('delete-folder', '_mboxes='+escape(folder)); 
     2820      this.http_request('delete-folder', '_mboxes='+urlencode(folder)); 
    28212821    }; 
    28222822 
    28232823 
    28242824  // add a new folder to the subscription list by cloning a folder row 
    2825   this.add_folder_row = function(name, replace) 
     2825  this.add_folder_row = function(name, display_name, replace) 
    28262826    { 
    28272827    name = name.replace('\\',""); 
     
    28542854 
    28552855    // add to folder/row-ID map 
    2856     this.env.subscriptionrows[row.id] = name; 
     2856    this.env.subscriptionrows[row.id] = [name, display_name]; 
    28572857 
    28582858    // set folder name 
    2859     row.cells[0].innerHTML = name; 
     2859    row.cells[0].innerHTML = display_name; 
    28602860    if (row.cells[1] && row.cells[1].firstChild.tagName=='INPUT') 
    28612861      { 
     
    28822882 
    28832883  // replace an existing table row with a new folder line 
    2884   this.replace_folder_row = function(newfolder, oldfolder) 
     2884  this.replace_folder_row = function(oldfolder, newfolder, display_name) 
    28852885    { 
    28862886    var id = this.get_folder_row_id(oldfolder); 
     
    28882888     
    28892889    // replace an existing table row (if found) 
    2890     this.add_folder_row(newfolder, row); 
     2890    this.add_folder_row(newfolder, display_name, row); 
    28912891    this.env.subscriptionrows[id] = null; 
    28922892     
     
    28992899        if (elm.options[i].value == oldfolder) 
    29002900          { 
    2901           elm.options[i].text = newfolder; 
     2901          elm.options[i].text = display_name; 
    29022902          elm.options[i].value = newfolder; 
    29032903          break; 
     
    29442944      this.change_subscription('_unsubscribed', '_subscribed', 'subscribe'); 
    29452945    else if (folder) 
    2946       this.http_request('subscribe', '_mboxes='+escape(folder)); 
     2946      this.http_request('subscribe', '_mboxes='+urlencode(folder)); 
    29472947    }; 
    29482948 
     
    29542954      this.change_subscription('_subscribed', '_unsubscribed', 'unsubscribe'); 
    29552955    else if (folder) 
    2956       this.http_request('unsubscribe', '_mboxes='+escape(folder)); 
     2956      this.http_request('unsubscribe', '_mboxes='+urlencode(folder)); 
    29572957    }; 
    29582958     
     
    29882988          } 
    29892989           
    2990         this.http_request(action, '_mboxes='+escape(a_folders.join(','))); 
     2990        this.http_request(action, '_mboxes='+urlencode(a_folders.join(','))); 
    29912991        } 
    29922992      } 
     
    29982998    { 
    29992999    for (var id in this.env.subscriptionrows) 
    3000       if (this.env.subscriptionrows[id]==folder) 
     3000      if (this.env.subscriptionrows[id] && this.env.subscriptionrows[id][0] == folder) 
    30013001        break; 
    30023002         
     
    35233523    if (request_obj) 
    35243524      { 
    3525       // prompt('request', this.env.comm_path+'&_action='+escape(action)+'&'+querystring); 
    3526       console('HTTP request: '+this.env.comm_path+'&_action='+escape(action)+'&'+querystring); 
     3525      // prompt('request', this.env.comm_path+'&_action='+urlencode(action)+'&'+querystring); 
     3526      console('HTTP request: '+this.env.comm_path+'&_action='+action+'&'+querystring); 
    35273527 
    35283528      if (lock) 
     
    35333533      request_obj.onerror = function(o){ rcube_webmail_client.http_error(o); }; 
    35343534      request_obj.oncomplete = function(o){ rcube_webmail_client.http_response(o); }; 
    3535       request_obj.GET(this.env.comm_path+'&_action='+escape(action)+'&'+querystring); 
     3535      request_obj.GET(this.env.comm_path+'&_action='+action+'&'+querystring); 
    35363536      } 
    35373537    }; 
  • program/js/common.js

    r2c57622 r4d4264c  
    344344 
    345345 
     346// make a string URL safe 
     347function urlencode(str) 
     348{ 
     349  return window.encodeURI ? encodeURI(str).replace(/&/g, '%26') : escape(str); 
     350} 
     351 
     352 
    346353// get any type of html objects by id/name 
    347354function rcube_find_object(id, d) 
  • program/steps/mail/search.inc

    r42000a5 r4d4264c  
    2020$_SESSION['page'] = 1; 
    2121 
    22 // search query comes in with ISO encoding because javascript escape() 
    23 // uses ISO-8859-1. Better handling for that will follow. 
    24 $imap_charset = 'ISO-8859-1'; 
     22// using encodeURI with javascript "should" give us 
     23// a correctly UTF-8 encoded query string 
     24$imap_charset = 'UTF-8'; 
    2525 
    2626// get search string 
  • program/steps/settings/manage_folders.inc

    rf9c107a r4d4264c  
    4848  { 
    4949  if (!empty($_GET['_name'])) 
    50     $create = $IMAP->create_mailbox(trim(get_input_value('_name', RCUBE_INPUT_GET)), TRUE); 
     50    $create = $IMAP->create_mailbox(trim(get_input_value('_name', RCUBE_INPUT_GET, FALSE, 'UTF-7')), TRUE); 
    5151 
    5252  if ($create && $REMOTE_REQUEST) 
    5353    { 
    54     $commands = sprintf("this.add_folder_row('%s')", rep_specialchars_output($create, 'js')); 
     54    $commands = sprintf("this.add_folder_row('%s','%s')", 
     55                        rep_specialchars_output($create, 'js'), 
     56                        rep_specialchars_output(rcube_charset_convert($create, 'UTF-7'), 'js')); 
    5557    rcube_remote_response($commands); 
    5658    } 
     
    6870  { 
    6971  if (!empty($_GET['_folder_oldname']) && !empty($_GET['_folder_newname'])) 
    70     $rename = $IMAP->rename_mailbox(get_input_value('_folder_oldname', RCUBE_INPUT_GET), trim(get_input_value('_folder_newname', RCUBE_INPUT_GET))); 
    71  
     72    $rename = $IMAP->rename_mailbox(get_input_value('_folder_oldname', RCUBE_INPUT_GET), trim(get_input_value('_folder_newname', RCUBE_INPUT_GET, FALSE, 'UTF-7'))); 
     73     
    7274  if ($rename && $REMOTE_REQUEST) 
    7375    { 
    74     $commands = sprintf("this.replace_folder_row('%s','%s');", 
    75                         addslashes(rep_specialchars_output($rename, 'js')), 
    76                         rep_specialchars_output($_GET['_folder_oldname'], 'js')); 
     76    $commands = sprintf("this.replace_folder_row('%s','%s','%s');", 
     77                        rep_specialchars_output($_GET['_folder_oldname'], 'js'), 
     78                        rep_specialchars_output($rename, 'js'), 
     79                        rep_specialchars_output(rcube_charset_convert($rename, 'UTF-7'), 'js')); 
     80                         
    7781    rcube_remote_response($commands); 
    7882    } 
     
    136140 
    137141  // get folders from server 
     142  $IMAP->clear_cache('mailboxes'); 
     143 
    138144  $a_unsubscribed = $IMAP->list_unsubscribed(); 
    139145  $a_subscribed = $IMAP->list_mailboxes(); 
     
    155161  foreach ($a_unsubscribed as $i => $folder) 
    156162    { 
     163    $subscribed = in_array($folder, $a_subscribed); 
    157164    $protected = ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders'])); 
    158165    $zebra_class = $i%2 ? 'even' : 'odd'; 
    159166    $folder_js = rep_specialchars_output($folder, 'js'); 
     167    $folder_js_enc = rep_specialchars_output(rcube_charset_convert($folder, 'UTF-7'), 'js'); 
    160168     
    161169    if (!$protected) 
    162       $a_js_folders['rcmrow'.($i+1)] = $folder_js; 
    163  
    164     $out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td><td>%s</td>', 
     170      $a_js_folders['rcmrow'.($i+1)] = array($folder_js, $folder_js_enc); 
     171 
     172    $out .= sprintf('<tr id="rcmrow%d" class="%s"><td>%s</td>', 
    165173                    $i+1, 
    166174                    $zebra_class, 
    167                     rep_specialchars_output(rcube_charset_convert($folder, 'UTF-7', 'UTF-8'), 'html', 'all'), 
    168                     $checkbox_subscribe->show(in_array($folder, $a_subscribed)?$folder:'', array('value' => $folder, 'disabled' => $protected))); 
     175                    rep_specialchars_output(rcube_charset_convert($folder, 'UTF-7'), 'html', 'all')); 
     176                     
     177    if ($protected) 
     178      $out .= '<td>&nbsp;'.($subscribed ? '&#x2022;' : '-').'</td>'; 
     179    else 
     180      $out .= '<td>'.$checkbox_subscribe->show($subscribed?$folder:'', array('value' => $folder)).'</td>'; 
    169181 
    170182    // add rename and delete buttons 
Note: See TracChangeset for help on using the changeset viewer.