3302d0d4 |
1 | <? |
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 | |
8467bf00 |
34 | // Wraps text at $wrap characters |
35 | function wordWrap($passed, $wrap) { |
a8648d75 |
36 | $passed = str_replace(">", ">", $passed); |
37 | $passed = str_replace("<", "<", $passed); |
38 | |
8467bf00 |
39 | $words = explode(" ", trim($passed)); |
40 | $i = 0; |
41 | $line_len = strlen($words[$i])+1; |
42 | $line = ""; |
43 | while ($i < count($words)) { |
44 | while ($line_len < $wrap) { |
a8648d75 |
45 | $line = "$line$words[$i] "; |
8467bf00 |
46 | $i++; |
47 | $line_len = $line_len + strlen($words[$i])+1; |
e550d551 |
48 | } |
8467bf00 |
49 | $line_len = strlen($words[$i])+1; |
b8ea4ed6 |
50 | if ($line_len < $wrap) { |
51 | if ($i < count($words)) // don't <BR> the last line |
a8648d75 |
52 | $line = "$line\n"; |
b8ea4ed6 |
53 | } else { |
54 | $endline = $words[$i]; |
55 | while ($line_len >= $wrap) { |
56 | $bigline = substr($endline, 0, $wrap); |
57 | $endline = substr($endline, $wrap, strlen($endline)); |
58 | $line_len = strlen($endline); |
59 | $line = "$line$bigline<BR>"; |
60 | } |
61 | $line = "$line$endline<BR>"; |
62 | $i++; |
63 | } |
e550d551 |
64 | } |
a8648d75 |
65 | |
66 | $line = str_replace(">", ">", $line); |
67 | $line = str_replace("<", "<", $line); |
8467bf00 |
68 | return $line; |
e550d551 |
69 | } |
40ee9452 |
70 | |
71 | /** Returns an array of email addresses **/ |
72 | function parseAddrs($text) { |
7831268e |
73 | if (trim($text) == "") { |
74 | return; |
75 | } |
40ee9452 |
76 | $text = str_replace(" ", "", $text); |
77 | $text = str_replace(",", ";", $text); |
78 | $array = explode(";", $text); |
79 | return $array; |
80 | } |
81 | |
82 | /** Returns a line of comma separated email addresses from an array **/ |
83 | function getLineOfAddrs($array) { |
84 | $to_line = ""; |
85 | for ($i = 0; $i < count($array); $i++) { |
86 | if ($to_line) |
87 | $to_line = "$to_line, $array[$i]"; |
88 | else |
89 | $to_line = "$array[$i]"; |
90 | } |
91 | return $to_line; |
92 | } |
7ce342dc |
93 | |
a8648d75 |
94 | function translateText($body, $wrap_at) { |
95 | /** Add any parsing you want to in here */ |
96 | $body = trim($body); |
97 | $body_ary = explode("\n", $body); |
98 | |
99 | for ($i = 0; $i < count($body_ary); $i++) { |
100 | $line = $body_ary[$i]; |
101 | $line = "^^$line"; |
102 | |
103 | $line = str_replace(">", ">", $line); |
104 | $line = str_replace("<", "<", $line); |
105 | |
106 | if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning |
107 | $line = wordWrap($line, $wrap_at); |
108 | |
109 | $line = str_replace(" ", " ", $line); |
110 | $line = str_replace("\t", " ", $line); |
111 | $line = nl2br($line); |
112 | |
113 | if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) { |
114 | $line = substr($line, 2, strlen($line)); |
115 | $line = "<TT><FONT COLOR=FF0000>$line</FONT></TT><BR>\n"; |
116 | } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) { |
117 | $line = substr($line, 2, strlen($line)); |
118 | $line = "<TT><FONT COLOR=800000>$line</FONT></TT><BR>\n"; |
119 | } else { |
120 | $line = substr($line, 2, strlen($line)); |
121 | $line = "<TT><FONT COLOR=000000>$line</FONT></TT><BR>\n"; |
122 | } |
123 | |
124 | $new_body[$i] = "$line"; |
125 | } |
126 | $bdy = implode("\n", $new_body); |
127 | return $bdy; |
78509c54 |
128 | } |
129 | |
7ce342dc |
130 | /* SquirrelMail version number -- DO NOT CHANGE */ |
01f519fd |
131 | $version = "0.3"; |
d29aac0e |
132 | |
133 | |
134 | function find_mailbox_name ($mailbox) { |
135 | $mailbox = trim($mailbox); |
136 | if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") { |
137 | $mailbox = substr($mailbox, 0, strlen($mailbox) - 1); |
138 | $pos = strrpos ($mailbox, "\"")+1; |
139 | $box = substr($mailbox, $pos); |
140 | } else { |
141 | $box = substr($mailbox, strrpos($mailbox, " ")+1, strlen($mailbox)); |
142 | } |
143 | return $box; |
144 | } |
145 | |
146 | function replace_spaces ($string) { |
147 | return str_replace(" ", " ", $string); |
148 | } |
149 | |
150 | function replace_escaped_spaces ($string) { |
151 | return str_replace(" ", " ", $string); |
152 | } |
d17b1a71 |
153 | |
154 | function count_chars($string) { |
155 | for ($i = 0; $i < strlen($string); $i++) { |
156 | $ch = substr($string, $i, 1); |
157 | $size++; |
158 | if ($ch == "\\") { |
159 | $i++; |
160 | $ch = substr($string, $i, 1); |
161 | if ($ch == "n") |
162 | $i--; |
163 | if ($ch == "r") |
164 | $i--; |
165 | } |
166 | } |
167 | return $size; |
168 | } |
3302d0d4 |
169 | ?> |