2f7a92a531ee114739a4b263b93b26d721189cb8
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 (substr($haystack, -1) == $needle)
21 $haystack = substr($haystack, 0, strlen($haystack) - 1);
23 if (strrpos($haystack, $needle)) {
24 $pos = strrpos($haystack, $needle) +
1;
25 $data = substr($haystack, $pos, strlen($haystack));
32 // Wraps text at $wrap characters
33 function wordWrap($passed, $wrap) {
34 $passed = str_replace(">", ">", $passed);
35 $passed = str_replace("<", "<", $passed);
37 $words = explode(" ", trim($passed));
39 $line_len = strlen($words[$i])+
1;
41 while ($i < count($words)) {
42 while ($line_len < $wrap) {
43 $line = "$line$words[$i] ";
45 $line_len = $line_len +
strlen($words[$i])+
1;
47 $line_len = strlen($words[$i])+
1;
48 if ($line_len < $wrap) {
49 if ($i < count($words)) // don't <BR> the last line
52 $endline = $words[$i];
53 while ($line_len >= $wrap) {
54 $bigline = substr($endline, 0, $wrap);
55 $endline = substr($endline, $wrap, strlen($endline));
56 $line_len = strlen($endline);
57 $line = "$line$bigline<BR>";
59 $line = "$line$endline<BR>";
64 $line = str_replace(">", ">", $line);
65 $line = str_replace("<", "<", $line);
69 /** Returns an array of email addresses **/
70 function parseAddrs($text) {
71 if (trim($text) == "") {
74 $text = str_replace(" ", "", $text);
75 $text = str_replace(",", ";", $text);
76 $array = explode(";", $text);
80 /** Returns a line of comma separated email addresses from an array **/
81 function getLineOfAddrs($array) {
83 for ($i = 0; $i < count($array); $i++
) {
85 $to_line = "$to_line, $array[$i]";
87 $to_line = "$array[$i]";
92 function translateText($body, $wrap_at) {
93 /** Add any parsing you want to in here */
95 $body_ary = explode("\n", $body);
97 for ($i = 0; $i < count($body_ary); $i++
) {
98 $line = $body_ary[$i];
101 $line = str_replace(">", ">", $line);
102 $line = str_replace("<", "<", $line);
104 if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning
105 $line = wordWrap($line, $wrap_at);
107 $line = str_replace(" ", " ", $line);
108 $line = str_replace("\t", " ", $line);
109 $line = nl2br($line);
111 if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) {
112 $line = substr($line, 2, strlen($line));
113 $line = "<TT><FONT COLOR=FF0000>$line</FONT></TT><BR>\n";
114 } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) {
115 $line = substr($line, 2, strlen($line));
116 $line = "<TT><FONT COLOR=800000>$line</FONT></TT><BR>\n";
118 $line = substr($line, 2, strlen($line));
119 $line = "<TT><FONT COLOR=000000>$line</FONT></TT><BR>\n";
122 $new_body[$i] = "$line";
124 $bdy = implode("\n", $new_body);
128 /* SquirrelMail version number -- DO NOT CHANGE */
129 $version = "0.3pre1";
132 function find_mailbox_name ($mailbox) {
133 $mailbox = trim($mailbox);
134 if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") {
135 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
136 $pos = strrpos ($mailbox, "\"")+
1;
137 $box = substr($mailbox, $pos);
139 $box = substr($mailbox, strrpos($mailbox, " ")+
1, strlen($mailbox));
144 function replace_spaces ($string) {
145 return str_replace(" ", " ", $string);
148 function replace_escaped_spaces ($string) {
149 return str_replace(" ", " ", $string);