| 1 | <?php |
| 2 | |
| 3 | $strings_php = true; |
| 4 | |
| 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) { |
| 22 | if (substr($haystack, -1) == $needle) |
| 23 | $haystack = substr($haystack, 0, strlen($haystack) - 1); |
| 24 | |
| 25 | if (strrpos($haystack, $needle)) { |
| 26 | $pos = strrpos($haystack, $needle) + 1; |
| 27 | $data = substr($haystack, $pos, strlen($haystack)); |
| 28 | } else { |
| 29 | $data = $haystack; |
| 30 | } |
| 31 | return $data; |
| 32 | } |
| 33 | |
| 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 | |
| 47 | // Wraps text at $wrap characters |
| 48 | function wordWrap($passed, $wrap) { |
| 49 | $passed = str_replace(">", ">", $passed); |
| 50 | $passed = str_replace("<", "<", $passed); |
| 51 | |
| 52 | $words = explode(" ", trim($passed)); |
| 53 | $i = 0; |
| 54 | $line_len = strlen($words[$i])+1; |
| 55 | $line = ""; |
| 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++; |
| 77 | } |
| 78 | } |
| 79 | } else { |
| 80 | $line = $words[0]; |
| 81 | } |
| 82 | |
| 83 | $line = str_replace(">", ">", $line); |
| 84 | $line = str_replace("<", "<", $line); |
| 85 | return $line; |
| 86 | } |
| 87 | |
| 88 | /** Returns an array of email addresses **/ |
| 89 | function parseAddrs($text) { |
| 90 | if (trim($text) == "") { |
| 91 | return; |
| 92 | } |
| 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]); |
| 100 | } |
| 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 | } |
| 115 | |
| 116 | function translateText($body, $wrap_at, $charset) { |
| 117 | include ("../functions/url_parser.php"); |
| 118 | /** Add any parsing you want to in here */ |
| 119 | $body_ary = explode("\n", $body); |
| 120 | |
| 121 | for ($i = 0; $i < count($body_ary); $i++) { |
| 122 | $line = $body_ary[$i]; |
| 123 | $line = "^^$line"; |
| 124 | |
| 125 | //$line = str_replace(">", ">", $line); |
| 126 | //$line = str_replace("<", "<", $line); |
| 127 | //$line = htmlspecialchars($line); |
| 128 | |
| 129 | if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning |
| 130 | $line = wordWrap($line, $wrap_at); |
| 131 | |
| 132 | $line = charset_decode($charset, $line); |
| 133 | |
| 134 | $line = str_replace(" ", " ", $line); |
| 135 | $line = str_replace("\t", " ", $line); |
| 136 | $line = nl2br($line); |
| 137 | |
| 138 | if (strpos(trim(str_replace(" ", "", $line)), ">>") == 2) { |
| 139 | $line = substr($line, 2, strlen($line)); |
| 140 | $line = "<TT><FONT COLOR=FF0000>$line</FONT></TT><BR>\n"; |
| 141 | } else if (strpos(trim(str_replace(" ", "", $line)), ">") == 2) { |
| 142 | $line = substr($line, 2, strlen($line)); |
| 143 | $line = "<TT><FONT COLOR=800000>$line</FONT></TT><BR>\n"; |
| 144 | } else { |
| 145 | $line = substr($line, 2, strlen($line)); |
| 146 | $line = "<TT><FONT COLOR=000000>$line</FONT></TT><BR>\n"; |
| 147 | } |
| 148 | |
| 149 | $line = parseEmail ($line); |
| 150 | $line = parseUrl ($line); |
| 151 | $new_body[$i] = "$line"; |
| 152 | } |
| 153 | $bdy = implode("\n", $new_body); |
| 154 | return $bdy; |
| 155 | } |
| 156 | |
| 157 | /* SquirrelMail version number -- DO NOT CHANGE */ |
| 158 | $version = "0.5pre1"; |
| 159 | |
| 160 | |
| 161 | function find_mailbox_name ($mailbox) { |
| 162 | $mailbox = trim($mailbox); |
| 163 | if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") { |
| 164 | $mailbox = substr($mailbox, 0, strlen($mailbox) - 1); |
| 165 | $pos = strrpos ($mailbox, "\"")+1; |
| 166 | $box = substr($mailbox, $pos); |
| 167 | } else { |
| 168 | $box = substr($mailbox, strrpos($mailbox, " ")+1, strlen($mailbox)); |
| 169 | } |
| 170 | return $box; |
| 171 | } |
| 172 | |
| 173 | function replace_spaces ($string) { |
| 174 | return str_replace(" ", " ", $string); |
| 175 | } |
| 176 | |
| 177 | function replace_escaped_spaces ($string) { |
| 178 | return str_replace(" ", " ", $string); |
| 179 | } |
| 180 | |
| 181 | function get_location () { |
| 182 | # This determines the location to forward to relative |
| 183 | # to your server. If this doesn't work correctly for |
| 184 | # you (although it should), you can remove all this |
| 185 | # code except the last two lines, and change the header() |
| 186 | # function to look something like this, customized to |
| 187 | # the location of SquirrelMail on your server: |
| 188 | # |
| 189 | # http://www.myhost.com/squirrelmail/src/login.php |
| 190 | |
| 191 | global $PHP_SELF, $SERVER_NAME, $HTTPS, $HTTP_HOST; |
| 192 | |
| 193 | // Get the path |
| 194 | $path = substr($PHP_SELF, 0, strrpos($PHP_SELF, '/')); |
| 195 | |
| 196 | // Check if this is a HTTPS or regular HTTP request |
| 197 | $proto = "http://"; |
| 198 | if(isset($HTTPS) && $HTTPS == 'on' ) { |
| 199 | $proto = "https://"; |
| 200 | } |
| 201 | |
| 202 | // Get the hostname from the Host header or server config. |
| 203 | // Fallback is to omit the server name and use a relative URI, |
| 204 | // although this is not RFC 2616 compliant. |
| 205 | if(isset($HTTP_HOST) && !empty($HTTP_HOST)) { |
| 206 | $location = $proto . $HTTP_HOST . $path; |
| 207 | } else if(isset($SERVER_NAME) && !empty($SERVER_NAME)) { |
| 208 | $location = $proto . $SERVER_NAME . $path; |
| 209 | } else { |
| 210 | $location = $path; |
| 211 | } |
| 212 | return $location; |
| 213 | } |
| 214 | ?> |