3 //*************************************************************************
4 // Count the number of occurances of $needle are in $haystack.
5 //*************************************************************************
6 function countCharInString($haystack, $needle) {
7 $len = strlen($haystack);
8 for ($i = 0; $i < $len; $i++
) {
9 if ($haystack[$i] == $needle)
15 //*************************************************************************
16 // Read from the back of $haystack until $needle is found, or the begining
17 // of the $haystack is reached.
18 //*************************************************************************
19 function readShortMailboxName($haystack, $needle) {
20 if (strpos($haystack, $needle)) {
21 $pos = strrpos($haystack, $needle) +
1;
22 $data = substr($haystack, $pos, strlen($haystack));
29 // Wraps text at $wrap characters
30 function wordWrap($passed, $wrap) {
31 $passed = str_replace(">", ">", $passed);
32 $passed = str_replace("<", "<", $passed);
34 $words = explode(" ", trim($passed));
36 $line_len = strlen($words[$i])+
1;
38 while ($i < count($words)) {
39 while ($line_len < $wrap) {
40 $line = "$line$words[$i] ";
42 $line_len = $line_len +
strlen($words[$i])+
1;
44 $line_len = strlen($words[$i])+
1;
45 if ($line_len < $wrap) {
46 if ($i < count($words)) // don't <BR> the last line
49 $endline = $words[$i];
50 while ($line_len >= $wrap) {
51 $bigline = substr($endline, 0, $wrap);
52 $endline = substr($endline, $wrap, strlen($endline));
53 $line_len = strlen($endline);
54 $line = "$line$bigline<BR>";
56 $line = "$line$endline<BR>";
61 $line = str_replace(">", ">", $line);
62 $line = str_replace("<", "<", $line);
66 /** Returns an array of email addresses **/
67 function parseAddrs($text) {
68 if (trim($text) == "") {
71 $text = str_replace(" ", "", $text);
72 $text = str_replace(",", ";", $text);
73 $array = explode(";", $text);
77 /** Returns a line of comma separated email addresses from an array **/
78 function getLineOfAddrs($array) {
80 for ($i = 0; $i < count($array); $i++
) {
82 $to_line = "$to_line, $array[$i]";
84 $to_line = "$array[$i]";
89 function translateText($body, $wrap_at) {
90 /** Add any parsing you want to in here */
92 $body_ary = explode("\n", $body);
94 for ($i = 0; $i < count($body_ary); $i++
) {
95 $line = $body_ary[$i];
98 $line = str_replace(">", ">", $line);
99 $line = str_replace("<", "<", $line);
101 if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning
102 $line = wordWrap($line, $wrap_at);
104 $line = str_replace(" ", " ", $line);
105 $line = str_replace("\t", " ", $line);
106 $line = nl2br($line);
108 if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) {
109 $line = substr($line, 2, strlen($line));
110 $line = "<TT><FONT COLOR=FF0000>$line</FONT></TT><BR>\n";
111 } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) {
112 $line = substr($line, 2, strlen($line));
113 $line = "<TT><FONT COLOR=800000>$line</FONT></TT><BR>\n";
115 $line = substr($line, 2, strlen($line));
116 $line = "<TT><FONT COLOR=000000>$line</FONT></TT><BR>\n";
119 $new_body[$i] = "$line";
121 $bdy = implode("\n", $new_body);
125 /* SquirrelMail version number -- DO NOT CHANGE */
126 $version = "0.3pre1";