\n"); echo(" redirect\n\n"); echo(" \n"); echo(" \n"); echo(" \n"); echo("\n"); exit; } if (isset($_SESSION["serverstring"])) { if (($_SESSION["currentfolder"] == $_SESSION["serverstring"]) || ($_SESSION["currentfolder"] == "")) { $_SESSION["currentfolder"] = $_SESSION["serverstring"] . substr($_SESSION["rootfolderpath"], 0, strrpos($_SESSION["rootfolderpath"], $_SESSION["folderseparator"])); } } // Provide our little wrapper if gettext is not installed if (!function_exists("gettext")) { function gettext($str) { return $str; } } // This is a quick and easy way to change the version of ismail on a grand scale $ismailversion = "v2.0-pre4"; // Set up our locale action // I18N support information here // Also, if you wish a default locale to be different than en_US, set it below. if (!isset($_SESSION["locale"])) { $_SESSION["locale"] = 'en_US'; } UpdateLocale($_SESSION["locale"]); // All of our default settings $defaultsettings["addrepliestoaddressbook"]["default"] = 0; $defaultsettings["addrepliestoaddressbook"]["type"] = "boolean"; $defaultsettings["addrepliestoaddressbook"]["desc"] = gettext("When replying, add new senders to the address book"); $defaultsettings["stripscripttags"]["default"] = 0; $defaultsettings["stripscripttags"]["type"] = "boolean"; $defaultsettings["stripscripttags"]["desc"] = gettext("Strip script tags from the body of HTML formatted emails and attachments"); $defaultsettings["linknewwindow"]["default"] = 1; $defaultsettings["linknewwindow"]["type"] = "boolean"; $defaultsettings["linknewwindow"]["desc"] = gettext("Open hyperlinks in new windows?"); $defaultsettings["confirmdelivery"]["default"] = "ask"; $defaultsettings["confirmdelivery"]["type"] = "select"; $defaultsettings["confirmdelivery"]["values"] = array("always" => gettext("always"), "ask" => gettext("ask"), "never" => gettext("never")); $defaultsettings["confirmdelivery"]["desc"] = gettext("Delivery Receipt Behavior"); $defaultsettings["readdelay"]["default"] = 0; $defaultsettings["readdelay"]["type"] = "select"; $defaultsettings["readdelay"]["desc"] = gettext("Number of seconds to wait before marking a message as 'read'"); $defaultsettings["readdelay"]["values"] = array("0"=>gettext("Mark Immediately"), "1"=>"1 " . gettext("second"), "2"=>"2 " . gettext("seconds"), "3"=>"3 " . gettext("seconds"), "4"=>"4 " . gettext("seconds"), "5"=>"5 " . gettext("seconds"), "10"=>"10 " . gettext("seconds")); $defaultsettings["autorefresh"]["default"] = 1; $defaultsettings["autorefresh"]["type"] = "boolean"; $defaultsettings["autorefresh"]["desc"] = gettext("Auto-refresh to get new mail?"); $defaultsettings["refreshinterval"]["default"] = 60; $defaultsettings["refreshinterval"]["type"] = "integer"; $defaultsettings["refreshinterval"]["desc"] = gettext("Auto-refresh interval (in minutes)"); $defaultsettings["messagesatonce"]["default"] = 10; $defaultsettings["messagesatonce"]["type"] = "integer"; $defaultsettings["messagesatonce"]["desc"] = gettext("Messages to Display at Once (0 for all messages at once)"); $defaultsettings["locale"]["default"] = "en_US"; $defaultsettings["locale"]["type"] = "select"; $defaultsettings["locale"]["desc"] = gettext("Please choose your locale"); $defaultsettings["locale"]["values"] = array("en_US" => gettext("United States"), "cs_CZ" => gettext("Czech Republic"), "it_IT" => gettext("Italy"), "sv_SE" => gettext("Sweden")); $defaultsettings["sortfield"]["default"] = "date"; $defaultsettings["sortfield"]["type"] = "none"; $defaultsettings["sortdirection"]["default"] = "asc"; $defaultsettings["sortdirection"]["type"] = "none"; // opens an IMAP mailbox and handles errors // must be called before any text is output to a page or errors will result function open_mailbox($mailbox="", $username="", $password="") { if ($username == "") { $username = $_SESSION["username"]; } if ($password == "") { $password = $_SESSION["password"]; } if($mailbox) { $mbox = @imap_open($mailbox,$username, $password); } else { $mbox = @imap_open($_SESSION["serverstring"], $username, $password, OP_HALFOPEN); } if (!$mbox) { if (!isset($_SESSION["username"])) { header("Location: error.php?error=" . urlencode(gettext("Login failed for user") . " '" . $username . "'. " . gettext("Please check the username, password, and/or domain and try again."))); exit; } else { header("Location: error.php?error=" . urlencode(gettext("Unable to open mailbox") . " '" . $mailbox . "'.")); exit; } } return $mbox; } // returns a string for placing in a value tag in HTML function html_format($str) { return(str_replace("'", "'", str_replace("\"", """, str_replace("<", "<", str_replace(">", ">", str_replace("&", "&", $str)))))); } // This gets passed an array of settings, which it uses to set session variables function SetSettings($settings) { $keys = array_keys($GLOBALS["defaultsettings"]); foreach ($keys as $key) { if (isset($settings[$key])) { $_SESSION[$key] = $settings[$key]; } else { $_SESSION[$key] = $GLOBALS["defaultsettings"][$key]["default"]; } } } function ISDecode($string) { $string = trim($string); $arr = imap_mime_header_decode($string); $string = ""; for ($i = 0; $i < count($arr); $i++) { $string .= $arr[$i]->text; } $string = str_replace("\n", "", $string); $string = str_replace("\r", "", $string); return $string; } function ParseEmailLine($string) { $info = array("email"=>"", "first"=>"", "middle"=>"", "last"=>""); $name = ""; // Seperate out the name from the e-mail address // Find an address - this is the simple way that does *some* validating - // we can make this much much nastier if we have to preg_match_all("/([\w\.\-_]+@[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3})/", $string, $matches); if (count($matches[0]) > 0) { $info["email"] = strtolower($matches[1][0]); } // Get the stuff in quotes if it is preg_match_all("/\"([^\"]+)\"/", $string, $matches); if (count($matches[1]) > 0) $name = str_replace("\"", "", $matches[1][0]); if ($name == "") { $name = array(); // there are no quotes, get the stuff anyway preg_match_all("/([^\s]+)/", $string, $matches); for ($i = 0; $i < count($matches[0]); $i++) { if (strstr($matches[0][$i], "@") == false) { $name[$i] = $matches[0][$i]; } } } else { $name = split(" ", $name); } // Now we parse the name into what is likely first and last. If there is any. $first = ""; $middle = ""; $last = ""; $arr = array(); if (count($name) > 0) { // Put the name in the correct order for ($i = count($name) - 1; $i >= 0; $i--) { if (strstr($name[$i], ",") == true) { array_push($arr, str_replace(",", "", $name[$i])); } else { array_unshift($arr, $name[$i]); } } $name = $arr; unset($arr); // Now figure out what is first, middle, and last $info["first"] = $name[0]; if (count($name) == 2) { $info["last"] = $name[1]; } else if (count($name) >= 3) { $info["last"] = $name[count($name) - 1]; for ($i = 1; $i < count($name) - 1; $i++) { $middle .= $name[$i] . " "; } $info["middle"] = trim($middle); } } return $info; } function PageHeader($echo=1, $frame=0) { $header = ""; if ($_SESSION["locale"] == "cs_CZ") { $header = "\n"; } else { $header = "\n"; } if ($frame == "1") { $header .= "\n"; } else { $header .= "\n"; } $header .= "\n"; if ($echo == 1) { echo($header . "\n"); } else { return $header; } } function UpdateLocale($locale) { if (function_exists("bindtextdomain")) { putenv("LANG=" . $locale); setlocale(LC_ALL, $locale); // Set the text domain as 'messages' $domain = 'messages'; bindtextdomain($domain, "./locale"); textdomain($domain); } } function mkdir_p($dirname) { $dir=split("/", $dirname); $path = ""; for ($i = 0; $i < count($dir); $i++) { $path .= $dir[$i]."/"; if (!is_dir($path)) { @mkdir($path); @chmod($path, 0700); } } if (is_dir($dirname)) { return true; } else { return false; } } function rmdir_rf($dir){ if (!is_dir($dir)) { return true; } $current_dir = opendir($dir); while ($entryname = readdir($current_dir)) { if (is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")) { if (deldir($dir . "/" . $entryname) === false) { return false; } } else if ($entryname != "." and $entryname!="..") { if (!unlink($dir . "/" . $entryname)) { return false; } } } closedir($current_dir); if (!rmdir($dir)) { return false; } else { return true; } } ?>