59177427 |
1 | <?php |
7ce342dc |
2 | |
d068c0ec |
3 | $strings_php = true; |
4 | |
3302d0d4 |
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) |
12 | $count++; |
13 | } |
14 | return $count; |
15 | } |
16 | |
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) { |
91f999f6 |
22 | if (substr($haystack, -1) == $needle) |
23 | $haystack = substr($haystack, 0, strlen($haystack) - 1); |
24 | |
d29aac0e |
25 | if (strrpos($haystack, $needle)) { |
d92b6f31 |
26 | $pos = strrpos($haystack, $needle) + 1; |
27 | $data = substr($haystack, $pos, strlen($haystack)); |
28 | } else { |
29 | $data = $haystack; |
3302d0d4 |
30 | } |
d92b6f31 |
31 | return $data; |
3302d0d4 |
32 | } |
33 | |
8beafbbc |
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)) |
41 | return -1; |
42 | $pos++; |
43 | } |
44 | return $pos; |
45 | } |
46 | |
8467bf00 |
47 | // Wraps text at $wrap characters |
d76f6440 |
48 | function sqWordWrap($passed, $wrap) { |
a8648d75 |
49 | $passed = str_replace("<", "<", $passed); |
7aaa81fc |
50 | $passed = str_replace(">", ">", $passed); |
a8648d75 |
51 | |
7aaa81fc |
52 | preg_match("/^(\s|>)+/", $passed, $regs); |
53 | $beginning_spaces = $regs[0]; |
54 | |
55 | $words = explode(" ", $passed); |
56 | $i = -1; |
57 | $line_len = strlen($words[0])+1; |
8467bf00 |
58 | $line = ""; |
d68a3926 |
59 | if (count($words) > 1) { |
7aaa81fc |
60 | while ($i++ < count($words)) { |
d68a3926 |
61 | while ($line_len < $wrap) { |
62 | $line = "$line$words[$i] "; |
63 | $i++; |
7aaa81fc |
64 | $line_len = $line_len + strlen($words[$i]) + 1; |
d68a3926 |
65 | } |
66 | $line_len = strlen($words[$i])+1; |
7aaa81fc |
67 | if ($line_len <= $wrap) { |
68 | if (strlen($beginning_spaces) +2 >= $wrap) |
69 | $beginning_spaces = ""; |
70 | if ($i < count($words)) { // don't <BR> the last line |
71 | $line = "$line\n$beginning_spaces"; |
72 | } |
73 | $line = "$line$words[$i] "; |
74 | $line_len = strlen($beginning_spaces) + strlen($words[$i]) + 1; |
d68a3926 |
75 | } else { |
7aaa81fc |
76 | /* |
d68a3926 |
77 | $endline = $words[$i]; |
78 | while ($line_len >= $wrap) { |
79 | $bigline = substr($endline, 0, $wrap); |
80 | $endline = substr($endline, $wrap, strlen($endline)); |
81 | $line_len = strlen($endline); |
82 | $line = "$line$bigline<BR>"; |
83 | } |
7aaa81fc |
84 | */ |
85 | if (strlen($line) > $wrap) |
86 | $line = "$line\n$words[$i]"; |
87 | else |
88 | $line = "$line$words[$i]"; |
89 | $line_len = strlen($words[$i]); |
b8ea4ed6 |
90 | } |
b8ea4ed6 |
91 | } |
d68a3926 |
92 | } else { |
93 | $line = $words[0]; |
e550d551 |
94 | } |
a8648d75 |
95 | |
96 | $line = str_replace(">", ">", $line); |
97 | $line = str_replace("<", "<", $line); |
8467bf00 |
98 | return $line; |
e550d551 |
99 | } |
40ee9452 |
100 | |
101 | /** Returns an array of email addresses **/ |
102 | function parseAddrs($text) { |
7831268e |
103 | if (trim($text) == "") { |
104 | return; |
105 | } |
40ee9452 |
106 | $text = str_replace(" ", "", $text); |
cf8758c7 |
107 | $text = ereg_replace( '"[^"]*"', "", $text); |
40ee9452 |
108 | $text = str_replace(",", ";", $text); |
109 | $array = explode(";", $text); |
af9404d7 |
110 | for ($i = 0; $i < count ($array); $i++) { |
111 | $array[$i] = eregi_replace ("^.*\<", "", $array[$i]); |
112 | $array[$i] = eregi_replace ("\>.*$", "", $array[$i]); |
113 | } |
40ee9452 |
114 | return $array; |
115 | } |
116 | |
117 | /** Returns a line of comma separated email addresses from an array **/ |
118 | function getLineOfAddrs($array) { |
b676ba7e |
119 | if (is_array($array)) { |
120 | $to_line = implode(", ", $array); |
121 | $to_line = trim(ereg_replace(",,+", ",", $to_line)); |
122 | } else { |
123 | $to_line = ""; |
40ee9452 |
124 | } |
125 | return $to_line; |
126 | } |
7ce342dc |
127 | |
17ce8467 |
128 | function translateText($body, $wrap_at, $charset) { |
9297917e |
129 | global $where, $what; // from searching |
130 | |
8442ac08 |
131 | if (!isset($url_parser_php)) { |
132 | include "../functions/url_parser.php"; |
133 | } |
134 | |
a8648d75 |
135 | $body_ary = explode("\n", $body); |
8442ac08 |
136 | for ($i=0; $i < count($body_ary); $i++) { |
a8648d75 |
137 | $line = $body_ary[$i]; |
17ce8467 |
138 | $line = charset_decode($charset, $line); |
7aaa81fc |
139 | $line = str_replace("\t", " ", $line); |
8442ac08 |
140 | |
a37f3771 |
141 | if (strlen($line) - 2 >= $wrap_at) { |
d76f6440 |
142 | $line = sqWordWrap($line, $wrap_at); |
a37f3771 |
143 | } |
144 | |
a8648d75 |
145 | $line = str_replace(" ", " ", $line); |
a8648d75 |
146 | $line = nl2br($line); |
147 | |
8442ac08 |
148 | $line = parseEmail ($line); |
149 | $line = parseUrl ($line); |
150 | |
151 | $line = "^^$line"; // gotta do this because if not, strpos() returns 0 |
152 | // which in PHP is the same as false. Now it returns 2 |
a8648d75 |
153 | if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) { |
8442ac08 |
154 | $line = substr($line, 2); |
155 | $line = "<FONT COLOR=FF0000>$line</FONT>\n"; |
a8648d75 |
156 | } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) { |
8442ac08 |
157 | $line = substr($line, 2); |
158 | $line = "<FONT COLOR=800000>$line</FONT>\n"; |
a8648d75 |
159 | } else { |
8442ac08 |
160 | $line = substr($line, 2); |
161 | } |
162 | |
163 | $body_ary[$i] = "<tt>$line</tt><br>"; |
a8648d75 |
164 | } |
8442ac08 |
165 | $body = implode("\n", $body_ary); |
166 | |
167 | return $body; |
78509c54 |
168 | } |
169 | |
7ce342dc |
170 | /* SquirrelMail version number -- DO NOT CHANGE */ |
f7042e37 |
171 | $version = "0.5pre2"; |
d29aac0e |
172 | |
173 | |
174 | function find_mailbox_name ($mailbox) { |
175 | $mailbox = trim($mailbox); |
176 | if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") { |
177 | $mailbox = substr($mailbox, 0, strlen($mailbox) - 1); |
178 | $pos = strrpos ($mailbox, "\"")+1; |
179 | $box = substr($mailbox, $pos); |
180 | } else { |
181 | $box = substr($mailbox, strrpos($mailbox, " ")+1, strlen($mailbox)); |
182 | } |
183 | return $box; |
184 | } |
185 | |
186 | function replace_spaces ($string) { |
187 | return str_replace(" ", " ", $string); |
188 | } |
189 | |
190 | function replace_escaped_spaces ($string) { |
191 | return str_replace(" ", " ", $string); |
192 | } |
1195c340 |
193 | |
194 | function get_location () { |
195 | # This determines the location to forward to relative |
7e343a7d |
196 | # to your server. If this doesnt work correctly for |
1195c340 |
197 | # you (although it should), you can remove all this |
198 | # code except the last two lines, and change the header() |
199 | # function to look something like this, customized to |
200 | # the location of SquirrelMail on your server: |
201 | # |
202 | # http://www.myhost.com/squirrelmail/src/login.php |
203 | |
204 | global $PHP_SELF, $SERVER_NAME, $HTTPS, $HTTP_HOST; |
205 | |
206 | // Get the path |
207 | $path = substr($PHP_SELF, 0, strrpos($PHP_SELF, '/')); |
208 | |
209 | // Check if this is a HTTPS or regular HTTP request |
210 | $proto = "http://"; |
211 | if(isset($HTTPS) && $HTTPS == 'on' ) { |
212 | $proto = "https://"; |
213 | } |
214 | |
215 | // Get the hostname from the Host header or server config. |
216 | // Fallback is to omit the server name and use a relative URI, |
217 | // although this is not RFC 2616 compliant. |
218 | if(isset($HTTP_HOST) && !empty($HTTP_HOST)) { |
219 | $location = $proto . $HTTP_HOST . $path; |
220 | } else if(isset($SERVER_NAME) && !empty($SERVER_NAME)) { |
221 | $location = $proto . $SERVER_NAME . $path; |
222 | } else { |
223 | $location = $path; |
224 | } |
225 | return $location; |
226 | } |
7aaa81fc |
227 | |
228 | function sqStripSlashes($string) { |
229 | if (get_magic_quotes_gpc()) { |
230 | $string = stripslashes($string); |
231 | } |
232 | return $string; |
233 | } |
3302d0d4 |
234 | ?> |