Changeset 88ed237 in github
- Timestamp:
- Jun 4, 2009 6:27:19 AM (4 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- 0061e7b
- Parents:
- f042be3
- Location:
- program
- Files:
-
- 2 edited
-
include/rcube_string_replacer.php (modified) (2 diffs)
-
steps/mail/func.inc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
program/include/rcube_string_replacer.php
raa055c9 r88ed237 29 29 { 30 30 public static $pattern = '/##str_replacement\[([0-9]+)\]##/'; 31 31 public $mailto_pattern; 32 public $link_pattern; 32 33 private $values = array(); 33 34 35 36 function __construct() 37 { 38 $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:;'; 39 $url_chars_within = '\?\.~,!'; 40 41 $this->link_pattern = "/([\w]+:\/\/|\Wwww\.)([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/i"; 42 $this->mailto_pattern = "/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i"; 43 } 34 44 35 45 /** … … 65 75 $scheme = strtolower($matches[1]); 66 76 67 if ($scheme == 'http ' || $scheme == 'https' || $scheme == 'ftp') {68 $url = $matches[1] . '://' .$matches[2];69 $i = $this->add(html::a(array('href' => $url, 'target' => "_blank"), Q($url)));77 if ($scheme == 'http://' || $scheme == 'https://' || $scheme == 'ftp://') { 78 $url = $matches[1] . $matches[2]; 79 $i = $this->add(html::a(array('href' => $url, 'target' => '_blank'), Q($url))); 70 80 } 71 else if ( $matches[2] == 'www.') {72 $url = $matches[2] . $matches[3];73 $i = $this->add($m atches[1] . html::a(array('href' => 'http://' . $url, 'target' => "_blank"), Q($url)));81 else if (preg_match('/^(\W)www\.$/', $matches[1], $m)) { 82 $url = 'www.' . $matches[2]; 83 $i = $this->add($m[1] . html::a(array('href' => 'http://' . $url, 'target' => '_blank'), Q($url))); 74 84 } 75 85 -
program/steps/mail/func.inc
re54f6c7a r88ed237 777 777 unset($data['body']); 778 778 779 780 779 // plaintext postprocessing 781 780 if ($part->ctype_secondary == 'plain') { … … 783 782 $replacements = new rcube_string_replacer; 784 783 785 $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:;';786 $url_chars_within = '\?\.~,!';787 788 784 // search for patterns like links and e-mail addresses 789 $body = preg_replace_callback("/([\w]+):\/\/([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/i", array($replacements, 'link_callback'), $body); 790 $body = preg_replace_callback("/([^\/:]|\s)(www\.)([a-z0-9\-]{2,}[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/i", array($replacements, 'link_callback'), $body); 791 $body = preg_replace_callback('/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i', array($replacements, 'mailto_callback'), $body); 785 $body = preg_replace_callback($replacements->link_pattern, array($replacements, 'link_callback'), $body); 786 $body = preg_replace_callback($replacements->mailto_pattern, array($replacements, 'mailto_callback'), $body); 792 787 793 788 // split body into single lines 794 789 $a_lines = preg_split('/\r?\n/', $body); 790 $q_lines = array(); 795 791 $quote_level = 0; 796 792 797 // colorize quoted parts 798 for ($n=0; $n < count($a_lines); $n++) { 799 $line = $a_lines[$n]; 800 $quotation = ''; 793 // find/mark quoted lines... 794 for ($n=0, $cnt=count($a_lines); $n < $cnt; $n++) { 801 795 $q = 0; 802 796 803 if ( preg_match('/^(>+\s*)+/', $line, $regs)) {804 $q = strlen(preg_replace('/\s/', '', $regs[0]));805 $line = substr($line, strlen($regs[0]));797 if ($a_lines[$n][0] == '>' && preg_match('/^(>+\s*)+/', $a_lines[$n], $regs)) { 798 $q = strlen(preg_replace('/\s/', '', $regs[0])); 799 $a_lines[$n] = substr($a_lines[$n], strlen($regs[0])); 806 800 807 801 if ($q > $quote_level) 808 $q uotation = str_repeat('<blockquote>', $q - $quote_level);802 $q_lines[$n]['quote'] = $q - $quote_level; 809 803 else if ($q < $quote_level) 810 $ quotation = str_repeat("</blockquote>", $quote_level - $q);804 $eq_lines[$n]['endquote'] = $quote_level - $q; 811 805 } 812 806 else if ($quote_level > 0) 813 $q uotation = str_repeat("</blockquote>", $quote_level);807 $q_lines[$n]['endquote'] = $quote_level; 814 808 815 809 $quote_level = $q; 816 $a_lines[$n] = $quotation . Q($line, 'replace', false); // htmlquote plaintext 817 } 810 } 811 812 // quote plain text 813 $body = Q(join("\n", $a_lines), 'replace', false); 814 815 // ... colorize quoted lines 816 $a_lines = preg_split('/\n/', $body); 817 foreach ($q_lines as $i => $q) 818 if ($q['quote']) 819 $a_lines[$i] = str_repeat('<blockquote>', $q['quote']) . $a_lines[$i]; 820 else if ($q['endquote']) 821 $a_lines[$i] = str_repeat('</blockquote>', $q['endquote']) . $a_lines[$i]; 818 822 819 823 // insert the links for urls and mailtos 820 824 $body = $replacements->resolve(join("\n", $a_lines)); 821 825 } 822 826 823 827 // allow post-processing of the message body 824 828 $data = $RCMAIL->plugins->exec_hook('message_part_after', array('type' => $part->ctype_secondary, 'body' => $body) + $data); … … 991 995 $out .= html::div('message-part', html::tag('pre', array(), Q($MESSAGE->body))); 992 996 993 994 997 $ctype_primary = strtolower($MESSAGE->structure->ctype_primary); 995 998 $ctype_secondary = strtolower($MESSAGE->structure->ctype_secondary);
Note: See TracChangeset
for help on using the changeset viewer.
