2 /* URL Passing code to allow links from with in emails */
4 $url_parser_php = true;
6 function replaceBlock ($in, $replace, $start, $end) {
7 $begin = substr($in,0,$start);
8 $end = substr($in,$end,strlen($in)-$end);
9 $ret = $begin.$replace.$end;
13 function parseEmail (&$body) {
15 $Size = strlen($body);
17 // Having this defined in just one spot could help when changes need
18 // to be made to the pattern
19 // Make sure that the expression is evaluated case insensitively
21 // Here's pretty sophisticated IP matching:
22 // $IPMatch = '(2[0-5][0-9]|1?[0-9]{1,2})';
23 // $IPMatch = '\[?' . $IPMatch . '(\.' . $IPMatch . '){3}\]?';
26 $IPMatch = '\[?[0-9]{1,3}(\.[0-9]{1,3}){3}\]?';
27 $Host = '(' . $IPMatch . '|[0-9a-z]([-.]?[0-9a-z])*\.[a-wyz][a-z](g|l|m|pa|t|u|v)?)';
28 $Expression = '[0-9a-z]([-_.]?[0-9a-z])*(%' . $Host . ')?@' . $Host;
31 This is here in case we ever decide to use highlighting of searched
32 text. this does it for email addresses
34 if ($what && ($where == "BODY" || $where == "TEXT")) {
35 eregi ($Expression, $body, $regs);
38 $newaddr = eregi_replace ($what, "<b><font color=\"$color[2]\">$what</font></font></b>", $oldaddr);
39 $body = str_replace ($oldaddr, "<a href=\"../src/compose.php?send_to=$oldaddr\">$newaddr</a>", $body);
42 $body = eregi_replace ($Expression, "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body);
46 $body = eregi_replace ($Expression, "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body);
48 // If there are any changes, it'll just get bigger.
49 if ($Size != strlen($body))
55 function parseUrl (&$body)
61 'telnet:', // Special case -- doesn't need the slashes
65 $poss_ends = array(' ', '\n', '\r', '<', '>', '.\r', '.\n', '. ',
66 ' ', ')', '(', '"', '<', '>', '.<', ']', '[', '{',
70 $target_pos = strlen($body);
72 while ($start != $target_pos)
76 // Find the first token to replace
77 foreach ($url_tokens as $the_token)
79 $pos = strpos(strtolower($body), $the_token, $start);
80 if (is_int($pos) && $pos < $target_pos)
83 $target_token = $the_token;
87 // Look for email addresses between $start and $target_pos
88 $check_str = substr($body, $start, $target_pos);
90 if (parseEmail($check_str))
92 $body = replaceBlock($body, $check_str, $start, $target_pos);
93 $target_pos = strlen($check_str) +
$start;
96 // If there was a token to replace, replace it
97 if ($target_token != '')
99 // Find the end of the URL
101 foreach ($poss_ends as $key => $val)
103 $enda = strpos($body,$val,$target_pos);
104 if (is_int($enda) && $enda < $end)
109 $url = substr($body, $target_pos, $end-$target_pos);
111 // Replace URL with HyperLinked Url, requires 1 char in link
112 if ($url != '' && $url != $target_token)
114 $url_str = "<a href=\"$url\" target=\"_blank\">$url</a>";
115 $body = replaceBlock($body,$url_str,$target_pos,$end);
116 $target_pos +
= strlen($url_str);
120 // Not quite a valid link, skip ahead to next chance
121 $target_pos +
= strlen($target_token);
126 $start = $target_pos;
127 $target_pos = strlen($body);