Patch for mailto: link urlencoding

Jon Nathan <[email protected]>
Newsgroups gmane.mail.squirrelmail.devel
Message-ID <[email protected]>
We ran into an issue with squirrelmail 1.4.19.  When you click on
a mailto: link that has special characters (plus signs, etc), the
resulting compose.php pane replaces them with spaces.  That is, the
email addresses in mailto: links are not urlencoded.  This is painful
because the user has to go back in and fix the email address manually.

It only seems to be direct mailto: links, not email addresses that
squirrelmail finds and converts itself.

The patch below fixes the issue for me, but I'm neither a php programmer
nor a squirrelmail guru.  If this would be done better or somewhere else
in the code, feel free to modify it.


root@fox:/web/htdocs/mail/squirrelmail/functions> diff -u page_header.php.orig page_header.php.new
--- page_header.php.orig        2010-01-06 11:15:27.000000000 -0500
+++ page_header.php.new 2010-01-06 11:33:46.000000000 -0500
@@ -75,7 +75,20 @@
     if ($target != '') {
         $target = " target=\"$target\"";
     }
-    return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
+    // urlescape send_to email addresses in mailto: format 
+    // so special chars like '+' will pass through
+    // path: src/[email protected]
+    // text: mailto:[email protected]
+    if (preg_match("/mailto:/", $text, $matches)) {
+        if (preg_match("/send_to/", $path, $matches)) {
+            $parts = explode("=", $path); // split path on the equal sign
+            $base = $parts[0];
+            $email_addr = urlencode($parts[1]); // urlencode just the email addr
+            return '<a href="'.$base_uri.$base."=".$email_addr.'"'.$target.'>'.$text.'</a>';
+        }
+    } else {
+        return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
+    }
 }
 
 function displayInternalLink($path, $text, $target='') {
root@fox:/web/htdocs/mail/squirrelmail/functions> 



Please let me know what you think.

-Jon


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
-----
squirrelmail-devel mailing list
Posting guidelines: http://squirrelmail.org/postingguidelines
List address: [email protected]
List archives: http://news.gmane.org/gmane.mail.squirrelmail.devel
List info (subscribe/unsubscribe/change options): https://lists.sourceforge.net/lists/listinfo/squirrelmail-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.