0cb53d5d68943b2a1c5fd0c29015d2a51ee98279
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 // Searches for the next position in a string minus white space
35 function next_pos_minus_white ($haystack, $pos) {
36 while (substr($haystack, $pos, 1) == " " ||
37 substr($haystack, $pos, 1) == "\t" ||
38 substr($haystack, $pos, 1) == "\n" ||
39 substr($haystack, $pos, 1) == "\r") {
40 if ($pos >= strlen($haystack))
47 // Wraps text at $wrap characters
48 function wordWrap($passed, $wrap) {
49 $passed = str_replace(">", ">", $passed);
50 $passed = str_replace("<", "<", $passed);
52 $words = explode(" ", trim($passed));
54 $line_len = strlen($words[$i])+
1;
56 while ($i < count($words)) {
57 while ($line_len < $wrap) {
58 $line = "$line$words[$i] ";
60 $line_len = $line_len +
strlen($words[$i])+
1;
62 $line_len = strlen($words[$i])+
1;
63 if ($line_len < $wrap) {
64 if ($i < count($words)) // don't <BR> the last line
67 $endline = $words[$i];
68 while ($line_len >= $wrap) {
69 $bigline = substr($endline, 0, $wrap);
70 $endline = substr($endline, $wrap, strlen($endline));
71 $line_len = strlen($endline);
72 $line = "$line$bigline<BR>";
74 $line = "$line$endline<BR>";
79 $line = str_replace(">", ">", $line);
80 $line = str_replace("<", "<", $line);
84 /** Returns an array of email addresses **/
85 function parseAddrs($text) {
86 if (trim($text) == "") {
89 $text = str_replace(" ", "", $text);
90 $text = ereg_replace( '"[^"]*"', "", $text);
91 $text = str_replace(",", ";", $text);
92 $array = explode(";", $text);
93 for ($i = 0; $i < count ($array); $i++
) {
94 $array[$i] = eregi_replace ("^.*\<", "", $array[$i]);
95 $array[$i] = eregi_replace ("\>.*$", "", $array[$i]);
100 /** Returns a line of comma separated email addresses from an array **/
101 function getLineOfAddrs($array) {
103 for ($i = 0; $i < count($array); $i++
) {
105 $to_line = "$to_line, $array[$i]";
107 $to_line = "$array[$i]";
112 function translateText($body, $wrap_at, $charset) {
113 include ("../functions/url_parser.php");
114 /** Add any parsing you want to in here */
115 $body_ary = explode("\n", $body);
117 for ($i = 0; $i < count($body_ary); $i++
) {
118 $line = $body_ary[$i];
121 //$line = str_replace(">", ">", $line);
122 //$line = str_replace("<", "<", $line);
123 //$line = htmlspecialchars($line);
125 if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning
126 $line = wordWrap($line, $wrap_at);
128 $line = charset_decode($charset, $line);
130 $line = str_replace(" ", " ", $line);
131 $line = str_replace("\t", " ", $line);
132 $line = nl2br($line);
134 if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) {
135 $line = substr($line, 2, strlen($line));
136 $line = "<TT><FONT COLOR=FF0000>$line</FONT></TT><BR>\n";
137 } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) {
138 $line = substr($line, 2, strlen($line));
139 $line = "<TT><FONT COLOR=800000>$line</FONT></TT><BR>\n";
141 $line = substr($line, 2, strlen($line));
142 $line = "<TT><FONT COLOR=000000>$line</FONT></TT><BR>\n";
145 $line = parseEmail ($line);
146 $line = parseUrl ($line);
147 $new_body[$i] = "$line";
149 $bdy = implode("\n", $new_body);
153 /* SquirrelMail version number -- DO NOT CHANGE */
154 $version = "0.5pre1";
157 function find_mailbox_name ($mailbox) {
158 $mailbox = trim($mailbox);
159 if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") {
160 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
161 $pos = strrpos ($mailbox, "\"")+
1;
162 $box = substr($mailbox, $pos);
164 $box = substr($mailbox, strrpos($mailbox, " ")+
1, strlen($mailbox));
169 function replace_spaces ($string) {
170 return str_replace(" ", " ", $string);
173 function replace_escaped_spaces ($string) {
174 return str_replace(" ", " ", $string);