2 /********************************************************************************
3 * include/misc.inc.php : Misc functions
4 * -------------------------
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
10 function _headerdecode($charset, $c, $str) {
11 $s = ($c == 'Q') ?
quoted_printable_decode($str) : base64_decode($str);
12 $s = iconv($charset, 'iso-8859-15', $s);
13 return str_replace('_', ' ', $s);
16 function headerDecode($value) {
17 $val = preg_replace('/(=\?[^?]*\?[BQ]\?[^?]*\?=) (=\?[^?]*\?[BQ]\?[^?]*\?=)/', '\1\2', $value);
18 return preg_replace('/=\?([^?]*)\?([BQ])\?([^?]*)\?=/e', '_headerdecode("\1", "\2", "\3")', $val);
21 function formatFrom($text) {
22 # From: mark@cbosgd.ATT.COM
23 # From: mark@cbosgd.ATT.COM (Mark Horton)
24 # From: Mark Horton <mark@cbosgd.ATT.COM>
25 $mailto = '<a href="mailto:';
27 $result = htmlentities($text);
28 if (preg_match("/^([^ ]+)@([^ ]+)$/",$text,$regs)) {
29 $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[1]."@".$regs[2])."</a>";
31 if (preg_match("/^([^ ]+)@([^ ]+) \((.*)\)$/",$text,$regs)) {
32 $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[3])."</a>";
34 if (preg_match("/^\"?([^<>\"]+)\"? +<(.+)@(.+)>$/",$text,$regs)) {
35 $result="$mailto{$regs[2]}@{$regs[3]}\">".htmlentities($regs[1])."</a>";
37 return preg_replace("/\\\(\(|\))/","\\1",$result);
40 function wrap($text, $_prefix="", $_length=72)
42 $parts = preg_split("/\n-- ?\n/", $text);
43 if (count($parts) >1) {
44 $sign = "\n-- \n" . array_pop($parts);
45 $text = join("\n-- \n", $parts);
51 $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$_length, all=>1 };'";
54 return $_prefix.join("\n$_prefix", $result).($_prefix ?
'' : $sign);
57 function formatbody($_text) {
59 $res = "\n\n" . htmlentities(wrap($_text, "", $news['wrap']))."\n\n";
60 $res = preg_replace("/(<|>|")/", " \\1 ", $res);
61 $res = preg_replace('/(["\[])?((https?|ftp|news):\/\/[a-z@0-9.~%$£µ&i#\-+=_\/\?]*)(["\]])?/i', "\\1<a href=\"\\2\">\\2</a>\\4", $res);
62 $res = preg_replace("/ (<|>|") /", "\\1", $res);
64 $parts = preg_split("/\n-- ?\n/", $res);
66 if (count($parts) > 1) {
67 $sign = "</pre><hr style='width: 100%; margin: 1em 0em; ' /><pre>" . array_pop($parts);
68 return join("\n-- \n", $parts).$sign;