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 |
48 | function wordWrap($passed, $wrap) { |
a8648d75 |
49 | $passed = str_replace(">", ">", $passed); |
50 | $passed = str_replace("<", "<", $passed); |
51 | |
8467bf00 |
52 | $words = explode(" ", trim($passed)); |
53 | $i = 0; |
54 | $line_len = strlen($words[$i])+1; |
55 | $line = ""; |
d68a3926 |
56 | if (count($words) > 1) { |
57 | while ($i < count($words)-1) { |
58 | while ($line_len < $wrap) { |
59 | $line = "$line$words[$i] "; |
60 | $i++; |
61 | $line_len = $line_len + strlen($words[$i])+1; |
62 | } |
63 | $line_len = strlen($words[$i])+1; |
64 | if ($line_len < $wrap) { |
65 | if ($i < count($words)) // don't <BR> the last line |
66 | $line = "$line\n"; |
67 | } else { |
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>"; |
74 | } |
75 | $line = "$line$endline<BR>"; |
76 | $i++; |
b8ea4ed6 |
77 | } |
b8ea4ed6 |
78 | } |
d68a3926 |
79 | } else { |
80 | $line = $words[0]; |
e550d551 |
81 | } |
a8648d75 |
82 | |
83 | $line = str_replace(">", ">", $line); |
84 | $line = str_replace("<", "<", $line); |
8467bf00 |
85 | return $line; |
e550d551 |
86 | } |
40ee9452 |
87 | |
88 | /** Returns an array of email addresses **/ |
89 | function parseAddrs($text) { |
7831268e |
90 | if (trim($text) == "") { |
91 | return; |
92 | } |
40ee9452 |
93 | $text = str_replace(" ", "", $text); |
cf8758c7 |
94 | $text = ereg_replace( '"[^"]*"', "", $text); |
40ee9452 |
95 | $text = str_replace(",", ";", $text); |
96 | $array = explode(";", $text); |
af9404d7 |
97 | for ($i = 0; $i < count ($array); $i++) { |
98 | $array[$i] = eregi_replace ("^.*\<", "", $array[$i]); |
99 | $array[$i] = eregi_replace ("\>.*$", "", $array[$i]); |
100 | } |
40ee9452 |
101 | return $array; |
102 | } |
103 | |
104 | /** Returns a line of comma separated email addresses from an array **/ |
105 | function getLineOfAddrs($array) { |
106 | $to_line = ""; |
107 | for ($i = 0; $i < count($array); $i++) { |
108 | if ($to_line) |
109 | $to_line = "$to_line, $array[$i]"; |
110 | else |
111 | $to_line = "$array[$i]"; |
112 | } |
113 | return $to_line; |
114 | } |
7ce342dc |
115 | |
17ce8467 |
116 | function translateText($body, $wrap_at, $charset) { |
8442ac08 |
117 | if (!isset($url_parser_php)) { |
118 | include "../functions/url_parser.php"; |
119 | } |
120 | |
a8648d75 |
121 | $body_ary = explode("\n", $body); |
8442ac08 |
122 | for ($i=0; $i < count($body_ary); $i++) { |
a8648d75 |
123 | $line = $body_ary[$i]; |
17ce8467 |
124 | $line = charset_decode($charset, $line); |
8442ac08 |
125 | |
a8648d75 |
126 | $line = str_replace(" ", " ", $line); |
127 | $line = str_replace("\t", " ", $line); |
128 | $line = nl2br($line); |
129 | |
8442ac08 |
130 | $line = parseEmail ($line); |
131 | $line = parseUrl ($line); |
132 | |
133 | $line = "^^$line"; // gotta do this because if not, strpos() returns 0 |
134 | // which in PHP is the same as false. Now it returns 2 |
a8648d75 |
135 | if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) { |
8442ac08 |
136 | $line = substr($line, 2); |
137 | $line = "<FONT COLOR=FF0000>$line</FONT>\n"; |
a8648d75 |
138 | } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) { |
8442ac08 |
139 | $line = substr($line, 2); |
140 | $line = "<FONT COLOR=800000>$line</FONT>\n"; |
a8648d75 |
141 | } else { |
8442ac08 |
142 | $line = substr($line, 2); |
143 | } |
144 | |
145 | $body_ary[$i] = "<tt>$line</tt><br>"; |
a8648d75 |
146 | } |
8442ac08 |
147 | $body = implode("\n", $body_ary); |
148 | |
149 | return $body; |
78509c54 |
150 | } |
151 | |
7ce342dc |
152 | /* SquirrelMail version number -- DO NOT CHANGE */ |
cf59dc94 |
153 | $version = "0.5pre1"; |
d29aac0e |
154 | |
155 | |
156 | function find_mailbox_name ($mailbox) { |
157 | $mailbox = trim($mailbox); |
158 | if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") { |
159 | $mailbox = substr($mailbox, 0, strlen($mailbox) - 1); |
160 | $pos = strrpos ($mailbox, "\"")+1; |
161 | $box = substr($mailbox, $pos); |
162 | } else { |
163 | $box = substr($mailbox, strrpos($mailbox, " ")+1, strlen($mailbox)); |
164 | } |
165 | return $box; |
166 | } |
167 | |
168 | function replace_spaces ($string) { |
169 | return str_replace(" ", " ", $string); |
170 | } |
171 | |
172 | function replace_escaped_spaces ($string) { |
173 | return str_replace(" ", " ", $string); |
174 | } |
1195c340 |
175 | |
176 | function get_location () { |
177 | # This determines the location to forward to relative |
7e343a7d |
178 | # to your server. If this doesnt work correctly for |
1195c340 |
179 | # you (although it should), you can remove all this |
180 | # code except the last two lines, and change the header() |
181 | # function to look something like this, customized to |
182 | # the location of SquirrelMail on your server: |
183 | # |
184 | # http://www.myhost.com/squirrelmail/src/login.php |
185 | |
186 | global $PHP_SELF, $SERVER_NAME, $HTTPS, $HTTP_HOST; |
187 | |
188 | // Get the path |
189 | $path = substr($PHP_SELF, 0, strrpos($PHP_SELF, '/')); |
190 | |
191 | // Check if this is a HTTPS or regular HTTP request |
192 | $proto = "http://"; |
193 | if(isset($HTTPS) && $HTTPS == 'on' ) { |
194 | $proto = "https://"; |
195 | } |
196 | |
197 | // Get the hostname from the Host header or server config. |
198 | // Fallback is to omit the server name and use a relative URI, |
199 | // although this is not RFC 2616 compliant. |
200 | if(isset($HTTP_HOST) && !empty($HTTP_HOST)) { |
201 | $location = $proto . $HTTP_HOST . $path; |
202 | } else if(isset($SERVER_NAME) && !empty($SERVER_NAME)) { |
203 | $location = $proto . $SERVER_NAME . $path; |
204 | } else { |
205 | $location = $path; |
206 | } |
207 | return $location; |
208 | } |
3302d0d4 |
209 | ?> |