From fde466c58c004e8f7eff7b59c78f62eef250cde9 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Fri, 20 Jun 2008 07:40:05 -0400
Subject: [PATCH] Urlencode mail recipients for storing in session + little code cleanup

---
 program/include/main.inc              |   13 +------------
 program/steps/mail/compose.inc        |    2 +-
 program/include/rcube_json_output.php |    2 +-
 program/steps/addressbook/mailto.inc  |    4 ++--
 program/include/rcmail.php            |   13 ++++++++-----
 5 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/program/include/main.inc b/program/include/main.inc
index a29978a..d84ca89 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -128,18 +128,7 @@
 function rcmail_url($action, $p=array(), $task=null)
 {
   $app = rcmail::get_instance();
-  
-  $qstring = '';
-  $base = $app->comm_path;
-  
-  if ($task && in_array($task, rcmail::$main_tasks))
-    $base = ereg_replace('_task=[a-z]+', '_task='.$task, $app->comm_path);
-  
-  if (is_array($p))
-    foreach ($p as $key => $val)
-      $qstring .= '&'.urlencode($key).'='.urlencode($val);
-  
-  return $base . ($action ? '&_action='.$action : '') . $qstring;
+  return $app->url((array)$p + array('_action' => $action, 'task' => $task));
 }
 
 
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 7c12ef7..c2ad9cf 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -830,13 +830,16 @@
   public function url($p)
   {
     if (!is_array($p))
-      $p = array('action' => @func_get_arg(0));
-      
-    $url = $p['task'] ? './?_task=' . $p['task'] : $this->comm_path;
-    unset($p['task']);
+      $p = array('_action' => @func_get_arg(0));
     
+    if ($p['task'] && in_array($p['task'], rcmail::$main_tasks))
+      $url = './?_task='.$p['task'];
+    else
+      $url = $this->comm_path;
+    
+    unset($p['task']);
     foreach ($p as $par => $val)
-      $url .= sprintf('&%s=%s', urlencode($par), urlencode($val));
+      $url .= '&'.urlencode($par).'='.urlencode($val);
     
     return $url;
   }
diff --git a/program/include/rcube_json_output.php b/program/include/rcube_json_output.php
index 2f65c19..e170445 100644
--- a/program/include/rcube_json_output.php
+++ b/program/include/rcube_json_output.php
@@ -169,7 +169,7 @@
      * @param mixed Either a string with the action or url parameters as key-value pairs
      * @see rcmail::url()
      */
-    public function redirect($p = array(), $delay = 0)
+    public function redirect($p = array(), $delay = 1)
     {
         $location = rcmail::get_instance()->url($p);
         $this->remote_response("window.setTimeout(\"location.href='{$location}'\", $delay);");
diff --git a/program/steps/addressbook/mailto.inc b/program/steps/addressbook/mailto.inc
index 101b7c0..90a7796 100644
--- a/program/steps/addressbook/mailto.inc
+++ b/program/steps/addressbook/mailto.inc
@@ -37,8 +37,8 @@
 {
   $mailto_str = join(', ', $mailto);
   $mailto_id = substr(md5($mailto_str), 0, 16);
-  $_SESSION['mailto'][$mailto_id] = $mailto_str;
-  $OUTPUT->command('redirect', rcmail_url('compose', array('_mailto' => $mailto_id), 'mail'));
+  $_SESSION['mailto'][$mailto_id] = urlencode($mailto_str);
+  $OUTPUT->redirect(array('task' => 'mail', '_action' => 'compose', '_mailto' => $mailto_id));
 }
 else
   $OUTPUT->show_message('nocontactsfound', 'warning');
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 607cf9b..800a9de 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -135,7 +135,7 @@
       
       // we have a set of recipients stored is session
       if (($mailto_id = $_SESSION['compose']['param']['_mailto']) && $_SESSION['mailto'][$mailto_id])
-        $fvalue = $_SESSION['mailto'][$mailto_id];
+        $fvalue = urldecode($_SESSION['mailto'][$mailto_id]);
       else if (!empty($_SESSION['compose']['param']['_to']))
         $fvalue = $_SESSION['compose']['param']['_to'];
         

--
Gitblit v1.9.1