From 5f314dafe9798b38c30301417cdfb70dfaca0fae Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Fri, 05 Sep 2008 07:38:09 -0400
Subject: [PATCH] Correctly handle options in mailto-links (#1485228)

---
 CHANGELOG                      |    1 +
 program/steps/mail/compose.inc |   41 ++++++++++++++++++++++++++++-------------
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index cbe7dcd..9eba187 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,7 @@
 - Allowed max. attachment size now indicated in compose screen (#1485030)
 - Also capture backspace key in list mode (#1484566)
 - Allow application/pgp parts to be displayed (#1484753)
+- Correctly handle options in mailto-links (#1485228)
 
 2008/09/04 (alec)
 ----------
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 62ee147..783ac98 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -65,6 +65,17 @@
   rcmail_compose_cleanup();
   $_SESSION['compose'] = array('id' => uniqid(rand()), 'param' => array_map('strip_tags', $_GET));
   
+  // process values like "mailto:foo@bar.com?subject=new+message&cc=another"
+  if ($_SESSION['compose']['param']['_to']) {
+    $mailto = explode('?', $_SESSION['compose']['param']['_to']);
+    if (count($mailto) > 1) {
+      $_SESSION['compose']['param']['_to'] = $mailto[0];
+      parse_str($mailto[1], $query);
+      foreach ($query as $f => $val)
+        $_SESSION['compose']['param']["_$f"] = $val;
+    }
+  }
+
   // redirect to a unique URL with all parameters stored in session
   $OUTPUT->redirect(array('_action' => 'compose', '_id' => $_SESSION['compose']['id']));
 }
@@ -143,9 +154,7 @@
       // we have a set of recipients stored is session
       if (($mailto_id = $_SESSION['compose']['param']['_mailto']) && $_SESSION['mailto'][$mailto_id])
         $fvalue = urldecode($_SESSION['mailto'][$mailto_id]);
-      else if (!empty($_SESSION['compose']['param']['_to']))
-        $fvalue = $_SESSION['compose']['param']['_to'];
-        
+      
     case 'cc':
       if (!$fname)
       {
@@ -168,11 +177,13 @@
       $fname = '_replyto';
       $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
       $field_type = 'html_inputfield';
-      break;    
+      break;
   }
  
   if ($fname && !empty($_POST[$fname]))
     $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE);
+  else if ($fname && !$fvalue && !empty($_SESSION['compose']['param'][$fname]))
+    $fvalue = $_SESSION['compose']['param'][$fname];
 
   else if ($header && $compose_mode == RCUBE_COMPOSE_REPLY)
   {
@@ -385,6 +396,10 @@
     // load draft message body
     else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
       $body = rcmail_create_draft_body($body, $isHtml);
+  }
+  else if (!empty($_SESSION['compose']['param']['_body']))
+  {
+    $body = $_SESSION['compose']['param']['_body'];
   }
 
   $lang = $tinylang = strtolower(substr($_SESSION['language'], 0, 2));
@@ -608,30 +623,30 @@
   $subject = '';
 
   // use subject from post
-  if (isset($_POST['_subject']))
+  if (isset($_POST['_subject'])) {
     $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE);
-    
+  }
   // create a reply-subject
-  else if ($compose_mode == RCUBE_COMPOSE_REPLY)
-  {
+  else if ($compose_mode == RCUBE_COMPOSE_REPLY) {
     if (eregi('^re:', $MESSAGE->subject))
       $subject = $MESSAGE->subject;
     else
       $subject = 'Re: '.$MESSAGE->subject;
   }
-
   // create a forward-subject
-  else if ($compose_mode == RCUBE_COMPOSE_FORWARD)
-  {
+  else if ($compose_mode == RCUBE_COMPOSE_FORWARD) {
     if (eregi('^fwd:', $MESSAGE->subject))
       $subject = $MESSAGE->subject;
     else
       $subject = 'Fwd: '.$MESSAGE->subject;
   }
-
   // creeate a draft-subject
-  else if ($compose_mode == RCUBE_COMPOSE_DRAFT)
+  else if ($compose_mode == RCUBE_COMPOSE_DRAFT) {
     $subject = $MESSAGE->subject;
+  }
+  else if (!empty($_SESSION['compose']['param']['_subject'])) {
+    $subject = $_SESSION['compose']['param']['_subject'];
+  }
   
   $out = $form_start ? "$form_start\n" : '';
   $out .= $textfield->show($subject);

--
Gitblit v1.9.1