From: pdontthink Date: Fri, 21 Sep 2018 17:21:03 +0000 (+0000) Subject: Fix broken mailto links created by some (Microsoft?) clients X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=7196da62c367f48f8840828e53187db824c3f1f4;ds=sidebyside Fix broken mailto links created by some (Microsoft?) clients git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14779 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/mime.php b/functions/mime.php index 332a4860..a140f7bc 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -2685,19 +2685,25 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX', $take_mailto_links if ($take_mailto_links) { // parseUrl($trusted); // this even parses URLs inside of tags... too aggressive global $MailTo_PReg_Match; - $MailTo_PReg_Match = '/mailto:' . substr($MailTo_PReg_Match, 1) ; + // some mailers (Microsoft, surprise surprise) produce mailto strings without being + // inside an anchor (link) tag, so we have to make sure the regex looks for the + // quote before mailto, and we'll also try to convert the non-links back into links + $MailTo_PReg_Match = '/([\'"])?mailto:' . substr($MailTo_PReg_Match, 1) ; if ((preg_match_all($MailTo_PReg_Match, $trusted, $regs)) && ($regs[0][0] != '')) { foreach ($regs[0] as $i => $mailto_before) { - $mailto_params = $regs[10][$i]; + $mailto_params = $regs[11][$i]; + + // get rid of any leading quote we may have captured but don't care about + // + $mailto_before = ltrim($mailto_before, '"\''); + // get rid of any tailing quote since we have to add send_to to the end // - if (substr($mailto_before, strlen($mailto_before) - 1) == '"') - $mailto_before = substr($mailto_before, 0, strlen($mailto_before) - 1); - if (substr($mailto_params, strlen($mailto_params) - 1) == '"') - $mailto_params = substr($mailto_params, 0, strlen($mailto_params) - 1); + $mailto_before = rtrim($mailto_before, '"\''); + $mailto_params = rtrim($mailto_params, '"\''); - if ($regs[1][$i]) { //if there is an email addr before '?', we need to merge it with the params - $to = 'to=' . $regs[1][$i]; + if ($regs[2][$i]) { //if there is an email addr before '?', we need to merge it with the params + $to = 'to=' . $regs[2][$i]; if (strpos($mailto_params, 'to=') > -1) //already a 'to=' $mailto_params = str_replace('to=', $to . '%2C%20', $mailto_params); else { @@ -2722,8 +2728,12 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX', $take_mailto_links // remove