c3f2e4c0ad6f18857482efb404a88d8e6b502ba1
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 if (count($words) > 1) {
57 while ($i < count($words)-1) {
58 while ($line_len < $wrap) {
59 $line = "$line$words[$i] ";
61 $line_len = $line_len +
strlen($words[$i])+
1;
63 $line_len = strlen($words[$i])+
1;
64 if ($line_len < $wrap) {
65 if ($i < count($words)) // don't <BR> the last line
68 $endline = $words[$i];
69 while ($line_len >= $wrap) {
70 $bigline = substr($endline, 0, $wrap);
71 $endline = substr($endline, $wrap, strlen($endline));
72 $line_len = strlen($endline);
73 $line = "$line$bigline<BR>";
75 $line = "$line$endline<BR>";
83 $line = str_replace(">", ">", $line);
84 $line = str_replace("<", "<", $line);
88 /** Returns an array of email addresses **/
89 function parseAddrs($text) {
90 if (trim($text) == "") {
93 $text = str_replace(" ", "", $text);
94 $text = ereg_replace( '"[^"]*"', "", $text);
95 $text = str_replace(",", ";", $text);
96 $array = explode(";", $text);
97 for ($i = 0; $i < count ($array); $i++
) {
98 $array[$i] = eregi_replace ("^.*\<", "", $array[$i]);
99 $array[$i] = eregi_replace ("\>.*$", "", $array[$i]);
104 /** Returns a line of comma separated email addresses from an array **/
105 function getLineOfAddrs($array) {
107 for ($i = 0; $i < count($array); $i++
) {
109 $to_line = "$to_line, $array[$i]";
111 $to_line = "$array[$i]";
116 function translateText($body, $wrap_at, $charset) {
117 global $where, $what; // from searching
119 if (!isset($url_parser_php)) {
120 include "../functions/url_parser.php";
123 $body_ary = explode("\n", $body);
124 for ($i=0; $i < count($body_ary); $i++
) {
125 $line = $body_ary[$i];
126 $line = charset_decode($charset, $line);
128 $line = str_replace(" ", " ", $line);
129 $line = str_replace("\t", " ", $line);
130 $line = nl2br($line);
132 $line = parseEmail ($line);
133 $line = parseUrl ($line);
135 $line = "^^$line"; // gotta do this because if not, strpos() returns 0
136 // which in PHP is the same as false. Now it returns 2
137 if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) {
138 $line = substr($line, 2);
139 $line = "<FONT COLOR=FF0000>$line</FONT>\n";
140 } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) {
141 $line = substr($line, 2);
142 $line = "<FONT COLOR=800000>$line</FONT>\n";
144 $line = substr($line, 2);
147 $body_ary[$i] = "<tt>$line</tt><br>";
149 $body = implode("\n", $body_ary);
154 /* SquirrelMail version number -- DO NOT CHANGE */
155 $version = "0.5pre1";
158 function find_mailbox_name ($mailbox) {
159 $mailbox = trim($mailbox);
160 if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") {
161 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
162 $pos = strrpos ($mailbox, "\"")+
1;
163 $box = substr($mailbox, $pos);
165 $box = substr($mailbox, strrpos($mailbox, " ")+
1, strlen($mailbox));
170 function replace_spaces ($string) {
171 return str_replace(" ", " ", $string);
174 function replace_escaped_spaces ($string) {
175 return str_replace(" ", " ", $string);
178 function get_location () {
179 # This determines the location to forward to relative
180 # to your server. If this doesnt work correctly for
181 # you (although it should), you can remove all this
182 # code except the last two lines, and change the header()
183 # function to look something like this, customized to
184 # the location of SquirrelMail on your server:
186 # http://www.myhost.com/squirrelmail/src/login.php
188 global $PHP_SELF, $SERVER_NAME, $HTTPS, $HTTP_HOST;
191 $path = substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'));
193 // Check if this is a HTTPS or regular HTTP request
195 if(isset($HTTPS) && $HTTPS == 'on' ) {
199 // Get the hostname from the Host header or server config.
200 // Fallback is to omit the server name and use a relative URI,
201 // although this is not RFC 2616 compliant.
202 if(isset($HTTP_HOST) && !empty($HTTP_HOST)) {
203 $location = $proto . $HTTP_HOST . $path;
204 } else if(isset($SERVER_NAME) && !empty($SERVER_NAME)) {
205 $location = $proto . $SERVER_NAME . $path;