3302d0d4 |
1 | <? |
7ce342dc |
2 | |
3302d0d4 |
3 | //************************************************************************* |
4 | // Count the number of occurances of $needle are in $haystack. |
5 | //************************************************************************* |
6 | function countCharInString($haystack, $needle) { |
7 | $len = strlen($haystack); |
8 | for ($i = 0; $i < $len; $i++) { |
9 | if ($haystack[$i] == $needle) |
10 | $count++; |
11 | } |
12 | return $count; |
13 | } |
14 | |
15 | //************************************************************************* |
16 | // Read from the back of $haystack until $needle is found, or the begining |
17 | // of the $haystack is reached. |
18 | //************************************************************************* |
19 | function readShortMailboxName($haystack, $needle) { |
d92b6f31 |
20 | if (strpos($haystack, $needle)) { |
21 | $pos = strrpos($haystack, $needle) + 1; |
22 | $data = substr($haystack, $pos, strlen($haystack)); |
23 | } else { |
24 | $data = $haystack; |
3302d0d4 |
25 | } |
d92b6f31 |
26 | return $data; |
3302d0d4 |
27 | } |
28 | |
8467bf00 |
29 | // Wraps text at $wrap characters |
30 | function wordWrap($passed, $wrap) { |
a8648d75 |
31 | $passed = str_replace(">", ">", $passed); |
32 | $passed = str_replace("<", "<", $passed); |
33 | |
8467bf00 |
34 | $words = explode(" ", trim($passed)); |
35 | $i = 0; |
36 | $line_len = strlen($words[$i])+1; |
37 | $line = ""; |
38 | while ($i < count($words)) { |
39 | while ($line_len < $wrap) { |
a8648d75 |
40 | $line = "$line$words[$i] "; |
8467bf00 |
41 | $i++; |
42 | $line_len = $line_len + strlen($words[$i])+1; |
e550d551 |
43 | } |
8467bf00 |
44 | $line_len = strlen($words[$i])+1; |
b8ea4ed6 |
45 | if ($line_len < $wrap) { |
46 | if ($i < count($words)) // don't <BR> the last line |
a8648d75 |
47 | $line = "$line\n"; |
b8ea4ed6 |
48 | } else { |
49 | $endline = $words[$i]; |
50 | while ($line_len >= $wrap) { |
51 | $bigline = substr($endline, 0, $wrap); |
52 | $endline = substr($endline, $wrap, strlen($endline)); |
53 | $line_len = strlen($endline); |
54 | $line = "$line$bigline<BR>"; |
55 | } |
56 | $line = "$line$endline<BR>"; |
57 | $i++; |
58 | } |
e550d551 |
59 | } |
a8648d75 |
60 | |
61 | $line = str_replace(">", ">", $line); |
62 | $line = str_replace("<", "<", $line); |
8467bf00 |
63 | return $line; |
e550d551 |
64 | } |
40ee9452 |
65 | |
66 | /** Returns an array of email addresses **/ |
67 | function parseAddrs($text) { |
7831268e |
68 | if (trim($text) == "") { |
69 | return; |
70 | } |
40ee9452 |
71 | $text = str_replace(" ", "", $text); |
72 | $text = str_replace(",", ";", $text); |
73 | $array = explode(";", $text); |
74 | return $array; |
75 | } |
76 | |
77 | /** Returns a line of comma separated email addresses from an array **/ |
78 | function getLineOfAddrs($array) { |
79 | $to_line = ""; |
80 | for ($i = 0; $i < count($array); $i++) { |
81 | if ($to_line) |
82 | $to_line = "$to_line, $array[$i]"; |
83 | else |
84 | $to_line = "$array[$i]"; |
85 | } |
86 | return $to_line; |
87 | } |
7ce342dc |
88 | |
a8648d75 |
89 | function translateText($body, $wrap_at) { |
90 | /** Add any parsing you want to in here */ |
91 | $body = trim($body); |
92 | $body_ary = explode("\n", $body); |
93 | |
94 | for ($i = 0; $i < count($body_ary); $i++) { |
95 | $line = $body_ary[$i]; |
96 | $line = "^^$line"; |
97 | |
98 | $line = str_replace(">", ">", $line); |
99 | $line = str_replace("<", "<", $line); |
100 | |
101 | if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning |
102 | $line = wordWrap($line, $wrap_at); |
103 | |
104 | $line = str_replace(" ", " ", $line); |
105 | $line = str_replace("\t", " ", $line); |
106 | $line = nl2br($line); |
107 | |
108 | if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) { |
109 | $line = substr($line, 2, strlen($line)); |
110 | $line = "<TT><FONT COLOR=FF0000>$line</FONT></TT><BR>\n"; |
111 | } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) { |
112 | $line = substr($line, 2, strlen($line)); |
113 | $line = "<TT><FONT COLOR=800000>$line</FONT></TT><BR>\n"; |
114 | } else { |
115 | $line = substr($line, 2, strlen($line)); |
116 | $line = "<TT><FONT COLOR=000000>$line</FONT></TT><BR>\n"; |
117 | } |
118 | |
119 | $new_body[$i] = "$line"; |
120 | } |
121 | $bdy = implode("\n", $new_body); |
122 | return $bdy; |
78509c54 |
123 | } |
124 | |
7ce342dc |
125 | /* SquirrelMail version number -- DO NOT CHANGE */ |
d3cdb279 |
126 | $version = "0.3pre1"; |
3302d0d4 |
127 | ?> |