5 //*************************************************************************
6 // Count the number of occurances of $needle are in $haystack.
7 //*************************************************************************
8 function countCharInString($haystack, $needle) {
9 $len = strlen($haystack);
10 for ($i = 0; $i < $len; $i++
) {
11 if ($haystack[$i] == $needle)
17 //*************************************************************************
18 // Read from the back of $haystack until $needle is found, or the begining
19 // of the $haystack is reached.
20 //*************************************************************************
21 function readShortMailboxName($haystack, $needle) {
22 if (substr($haystack, -1) == $needle)
23 $haystack = substr($haystack, 0, strlen($haystack) - 1);
25 if (strrpos($haystack, $needle)) {
26 $pos = strrpos($haystack, $needle) +
1;
27 $data = substr($haystack, $pos, strlen($haystack));
34 // Wraps text at $wrap characters
35 function wordWrap($passed, $wrap) {
36 $passed = str_replace(">", ">", $passed);
37 $passed = str_replace("<", "<", $passed);
39 $words = explode(" ", trim($passed));
41 $line_len = strlen($words[$i])+
1;
43 while ($i < count($words)) {
44 while ($line_len < $wrap) {
45 $line = "$line$words[$i] ";
47 $line_len = $line_len +
strlen($words[$i])+
1;
49 $line_len = strlen($words[$i])+
1;
50 if ($line_len < $wrap) {
51 if ($i < count($words)) // don't <BR> the last line
54 $endline = $words[$i];
55 while ($line_len >= $wrap) {
56 $bigline = substr($endline, 0, $wrap);
57 $endline = substr($endline, $wrap, strlen($endline));
58 $line_len = strlen($endline);
59 $line = "$line$bigline<BR>";
61 $line = "$line$endline<BR>";
66 $line = str_replace(">", ">", $line);
67 $line = str_replace("<", "<", $line);
71 /** Returns an array of email addresses **/
72 function parseAddrs($text) {
73 if (trim($text) == "") {
76 $text = str_replace(" ", "", $text);
77 $text = str_replace(",", ";", $text);
78 $array = explode(";", $text);
82 /** Returns a line of comma separated email addresses from an array **/
83 function getLineOfAddrs($array) {
85 for ($i = 0; $i < count($array); $i++
) {
87 $to_line = "$to_line, $array[$i]";
89 $to_line = "$array[$i]";
94 function translateText($body, $wrap_at, $charset) {
95 include ("../functions/url_parser.php");
96 /** Add any parsing you want to in here */
98 $body_ary = explode("\n", $body);
100 for ($i = 0; $i < count($body_ary); $i++
) {
101 $line = $body_ary[$i];
104 //$line = str_replace(">", ">", $line);
105 //$line = str_replace("<", "<", $line);
106 //$line = htmlspecialchars($line);
108 if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning
109 $line = wordWrap($line, $wrap_at);
111 $line = charset_decode($charset, $line);
113 $line = str_replace(" ", " ", $line);
114 $line = str_replace("\t", " ", $line);
115 $line = nl2br($line);
117 if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) {
118 $line = substr($line, 2, strlen($line));
119 $line = "<TT><FONT COLOR=FF0000>$line</FONT></TT><BR>\n";
120 } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) {
121 $line = substr($line, 2, strlen($line));
122 $line = "<TT><FONT COLOR=800000>$line</FONT></TT><BR>\n";
124 $line = substr($line, 2, strlen($line));
125 $line = "<TT><FONT COLOR=000000>$line</FONT></TT><BR>\n";
128 $line = parseEmail ($line);
129 $line = parseUrl ($line);
130 $new_body[$i] = "$line";
132 $bdy = implode("\n", $new_body);
136 /* SquirrelMail version number -- DO NOT CHANGE */
137 $version = "0.4pre1";
140 function find_mailbox_name ($mailbox) {
141 $mailbox = trim($mailbox);
142 if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") {
143 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
144 $pos = strrpos ($mailbox, "\"")+
1;
145 $box = substr($mailbox, $pos);
147 $box = substr($mailbox, strrpos($mailbox, " ")+
1, strlen($mailbox));
152 function replace_spaces ($string) {
153 return str_replace(" ", " ", $string);
156 function replace_escaped_spaces ($string) {
157 return str_replace(" ", " ", $string);