From 202bcbcc2b67c7c153db1b09b608b62beeba0496 Mon Sep 17 00:00:00 2001
From: stekkel You need to have PHP installed with the multibyte string function \n".
+ "enabled (using configure option --enable-mbstring). System assumed that you accidently switched to Japanese translation \n".
+ "and reverted your language preference to English. Please refresh this page in order to use webmail.
\n";
$error .= sprintf(_("Is PEAR installed, and is the include path set correctly to find %s?"),
'DB.php') . "
\n";
diff --git a/functions/addressbook.php b/functions/addressbook.php
index 863d7d81..75eb5596 100644
--- a/functions/addressbook.php
+++ b/functions/addressbook.php
@@ -12,20 +12,11 @@
* @subpackage addressbook
*/
-/**
- * If SM_PATH isn't defined, define it. Required to include files.
- * @ignore
- */
-if (!defined('SM_PATH')) {
- define('SM_PATH','../');
-}
/* required includes */
-include_once(SM_PATH . 'functions/display_messages.php');
+// FIXME, NO display code in functions files
include_once(SM_PATH . 'templates/util_global.php');
-global $addrbook_dsn, $addrbook_global_dsn;
-
/**
* Create and initialize an addressbook object.
* @param boolean $showerr display any address book init errors. html page header
@@ -450,13 +441,13 @@ class AddressBook {
var $localbackendname = '';
/**
* Controls use of 'extra' field
- *
- * Extra field can be used to add link to form, which allows
- * to modify all fields supported by backend. This is the only field
+ *
+ * Extra field can be used to add link to form, which allows
+ * to modify all fields supported by backend. This is the only field
* that is not sanitized with htmlspecialchars. Backends MUST make
* sure that field data is sanitized and displayed correctly inside
* table cell. Use of html formating in other address book fields is
- * not allowed. Backends that don't return 'extra' row in address book
+ * not allowed. Backends that don't return 'extra' row in address book
* data should not modify this object property.
* @var boolean
* @since 1.5.1
@@ -498,8 +489,31 @@ class AddressBook {
* @return integer number of backends
*/
function add_backend($backend, $param = '') {
+ static $backend_classes;
+ if (!isset($backend_classes)) {
+ $backend_classes = array();
+ }
+ if (!isset($backend_classes[$backend])) {
+ /**
+ * Support backend provided by plugins. Plugin function must
+ * return an associative array with as key the backend name ($backend)
+ * and as value the file including the path containing the backend class.
+ * i.e.: $aBackend = array('backend_template' => SM_PATH . 'plugins/abook_backend_template/functions.php')
+ *
+ * NB: Because the backend files are included from within this function they DO NOT have access to
+ * vars in the global scope. This function is the global scope for the included backend !!!
+ */
+ $aBackend = do_hook('abook_add_class');
+ if (isset($aBackend) && is_array($aBackend) && isset($aBackend[$backend])) {
+ require_once($aBackend[$backend]);
+ } else {
+ require_once(SM_PATH . 'functions/abook_'.$backend.'.php');
+ }
+ $backend_classes[$backend] = true;
+ }
$backend_name = 'abook_' . $backend;
- eval('$newback = new ' . $backend_name . '($param);');
+ $newback = new $backend_name($param);
+ //eval('$newback = new ' . $backend_name . '($param);');
if(!empty($newback->error)) {
$this->error = $newback->error;
return false;
@@ -880,9 +894,9 @@ class addressbook_backend {
/**
* Search for entries in backend
*
- * Working backend should support use of wildcards. * symbol
+ * Working backend should support use of wildcards. * symbol
* should match one or more symbols. ? symbol should match any
- * single symbol.
+ * single symbol.
* @param string $expression
* @return bool
*/
@@ -944,28 +958,4 @@ class addressbook_backend {
return false;
}
}
-
-/*
- PHP 5 requires that the class be made first, which seems rather
- logical, and should have been the way it was generated the first time.
-*/
-
-require_once(SM_PATH . 'functions/abook_local_file.php');
-require_once(SM_PATH . 'functions/abook_ldap_server.php');
-
-/* Only load database backend if database is configured */
-if((isset($addrbook_dsn) && !empty($addrbook_dsn)) ||
- (isset($addrbook_global_dsn) && !empty($addrbook_global_dsn))) {
- include_once(SM_PATH . 'functions/abook_database.php');
-}
-
-/*
- * hook allows adding different address book classes.
- * class must follow address book class coding standards.
- *
- * see addressbook_backend class and functions/abook_*.php files.
- * @since 1.5.1 and 1.4.5
- */
-do_hook('abook_add_class');
-
?>
diff --git a/functions/attachment_common.php b/functions/attachment_common.php
index 3b9e561a..0aec18e7 100644
--- a/functions/attachment_common.php
+++ b/functions/attachment_common.php
@@ -12,18 +12,7 @@
* @todo document attachment $type hook arguments
*/
-/** @ignore */
-if (! defined('SM_PATH')) define('SM_PATH','../');
-/** sqgetGlobalVar() */
-include_once(SM_PATH . 'functions/global.php');
-/** sqm_baseuri() */
-include_once(SM_PATH . 'functions/display_messages.php');
-
-global $attachment_common_show_images_list;
-$attachment_common_show_images_list = array();
-
-global $FileExtensionToMimeType, $attachment_common_types;
/**
* Mapping of file extensions to mime types
*
@@ -70,7 +59,7 @@ if (isset($attachment_common_types)) {
register_attachment_common('image/x-xbitmap', 'link_image');
elseif ($val == '*/*' || $val == 'image/*') {
/**
- * browser (Firefox) declared that anything is acceptable.
+ * browser (Firefox) declared that anything is acceptable.
* Lets register some common image types.
*/
if (! isset($jpeg_done)) {
@@ -131,6 +120,7 @@ function register_attachment_common($type, $func) {
* @since 1.2.0
*/
function attachment_common_link_text(&$Args) {
+ global $base_uri;
/* If there is a text attachment, we would like to create a "View" button
that links to the text attachment viewer.
@@ -144,7 +134,7 @@ function attachment_common_link_text(&$Args) {
sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
// if htmlspecialchars() breaks something - find other way to encode & in url.
- $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING);
+ $Args[1]['attachment_common']['href'] = $base_uri . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING);
$Args[1]['attachment_common']['href'] =
set_url_var($Args[1]['attachment_common']['href'],
'ent_id',$Args[5]);
@@ -169,7 +159,8 @@ function attachment_common_link_text(&$Args) {
* @since 1.2.6
*/
function attachment_common_link_message(&$Args) {
- $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/read_body.php?startMessage=' .
+ global $base_uri;
+ $Args[1]['attachment_common']['href'] = $base_uri . 'src/read_body.php?startMessage=' .
$Args[2] . '&passed_id=' . $Args[3] . '&mailbox=' . $Args[4] .
'&passed_ent_id=' . $Args[5] . '&override_type0=message&override_type1=rfc822';
@@ -184,9 +175,10 @@ function attachment_common_link_message(&$Args) {
* @since 1.2.0
*/
function attachment_common_link_html(&$Args) {
+ global $base_uri;
sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
- $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING).
+ $Args[1]['attachment_common']['href'] = $base_uri . 'src/view_text.php?'. htmlspecialchars($QUERY_STRING).
/* why use the overridetype? can this be removed */
/* override_type might be needed only when we want view other type of messages as html */
'&override_type0=text&override_type1=html';
@@ -205,7 +197,7 @@ function attachment_common_link_html(&$Args) {
* @since 1.2.0
*/
function attachment_common_link_image(&$Args) {
- global $attachment_common_show_images_list;
+ global $attachment_common_show_images_list, $base_uri ;
sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
@@ -215,7 +207,7 @@ function attachment_common_link_image(&$Args) {
$attachment_common_show_images_list[] = $info;
- $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/image.php?'. htmlspecialchars($QUERY_STRING);
+ $Args[1]['attachment_common']['href'] = $base_uri . 'src/image.php?'. htmlspecialchars($QUERY_STRING);
$Args[1]['attachment_common']['href'] =
set_url_var($Args[1]['attachment_common']['href'],
'ent_id',$Args[5]);
@@ -231,9 +223,10 @@ function attachment_common_link_image(&$Args) {
* @since 1.2.0
*/
function attachment_common_link_vcard(&$Args) {
+ global $base_uri;
sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
- $Args[1]['attachment_common']['href'] = sqm_baseuri() . 'src/vcard.php?'. htmlspecialchars($QUERY_STRING);
+ $Args[1]['attachment_common']['href'] = $base_uri . 'src/vcard.php?'. htmlspecialchars($QUERY_STRING);
$Args[1]['attachment_common']['href'] =
set_url_var($Args[1]['attachment_common']['href'],
'ent_id',$Args[5]);
diff --git a/functions/auth.php b/functions/auth.php
index a051aeaf..f5be2704 100644
--- a/functions/auth.php
+++ b/functions/auth.php
@@ -3,8 +3,8 @@
/**
* auth.php
*
- * Contains functions used to do authentication. Library depends on
- * functions from functions/global.php, functions/i18n.php and
+ * Contains functions used to do authentication. Library depends on
+ * functions from functions/global.php, functions/i18n.php and
* functions/strings.php.
*
* @copyright © 1999-2006 The SquirrelMail Project Team
@@ -13,75 +13,16 @@
* @package squirrelmail
*/
-/** Put in a safety net here, in case a naughty admin didn't run conf.pl when they upgraded */
-
-if (! isset($smtp_auth_mech)) {
- $smtp_auth_mech = 'none';
-}
-
-if (! isset($imap_auth_mech)) {
- $imap_auth_mech = 'login';
-}
-
-if (! isset($use_imap_tls)) {
- $use_imap_tls = false;
-}
-
-if (! isset($use_smtp_tls)) {
- $use_smtp_tls = false;
-}
-
-/**
- * Check if user has previously logged in to the SquirrelMail session. If user
- * has not logged in, execution will stop inside this function.
- *
- * @return int A positive value is returned if user has previously logged in
- * successfully.
- * @since 1.0
- */
-function is_logged_in() {
-
- if ( sqsession_is_registered('user_is_logged_in') ) {
- return;
- } else {
- global $PHP_SELF, $session_expired_post,
- $session_expired_location, $squirrelmail_language;
-
- // First we store some information in the new session to prevent
- // information-loss.
- //
- $session_expired_post = $_POST;
- $session_expired_location = $PHP_SELF;
- if (!sqsession_is_registered('session_expired_post')) {
- sqsession_register($session_expired_post,'session_expired_post');
- }
- if (!sqsession_is_registered('session_expired_location')) {
- sqsession_register($session_expired_location,'session_expired_location');
- }
-
- // signout page will deal with users who aren't logged
- // in on its own; don't show error here
- //
- if (strpos($PHP_SELF, 'signout.php') !== FALSE) {
- return;
- }
-
- include_once( SM_PATH . 'functions/display_messages.php' );
- set_up_language($squirrelmail_language, true);
- logout_error( _("You must be logged in to access this page.") );
- exit;
- }
-}
/**
* Detect logged user
- *
- * Function is similar to is_logged_in() function. If user is logged in, function
+ *
+ * Function is similar to is_logged_in() function. If user is logged in, function
* returns true. If user is not logged in or session is expired, function saves $_POST
- * and $PHP_SELF in session and returns false. POST information is saved in
+ * and $PHP_SELF in session and returns false. POST information is saved in
* 'session_expired_post' variable, PHP_SELF is saved in 'session_expired_location'.
*
- * Script that uses this function instead of is_logged_in() function, must handle user
+ * Script that uses this function instead of is_logged_in() function, must handle user
* level messages.
* @return boolean
* @since 1.5.1
@@ -124,18 +65,18 @@ function sqauth_read_password() {
/**
* Saves or updates user password information
- *
+ *
* This function is used to update password information that SquirrelMail
- * stores during existing web session. It does not modify password stored
+ * stores during existing web session. It does not modify password stored
* in authentication system used by IMAP server.
*
- * Function must be called before any html output started. Direct access
- * to password information is deprecated. Saved password information is
+ * Function must be called before any html output started. Direct access
+ * to password information is deprecated. Saved password information is
* available only to next executed SquirrelMail script. If your script needs
- * access to saved password after sqauth_save_password() call, use returned
+ * access to saved password after sqauth_save_password() call, use returned
* OTP encrypted key.
* @param string $pass password
- * @return string password encrypted with OTP. In case script wants to access
+ * @return string password encrypted with OTP. In case script wants to access
* password information before reloading page.
* @since 1.5.1
*/
diff --git a/functions/date.php b/functions/date.php
index b362d15c..50bb101a 100644
--- a/functions/date.php
+++ b/functions/date.php
@@ -15,8 +15,10 @@
* @subpackage date
*/
-/** Load up some useful constants */
-require_once(SM_PATH . 'functions/constants.php');
+/**
+ * dependency information
+ * - none
+ */
/**
* Corrects a time stamp to be the local time.
@@ -443,15 +445,3 @@ function getTimeStamp($dateParts) {
return getGMTSeconds($stamp, $dateParts[0]);
}
}
-
-/* I use this function for profiling. Should never be called in
- actual versions of SquirrelMail released to public. */
-/*
- function getmicrotime() {
- $mtime = microtime();
- $mtime = explode(' ',$mtime);
- $mtime = $mtime[1] + $mtime[0];
- return ($mtime);
- }
-*/
-?>
\ No newline at end of file
diff --git a/functions/db_prefs.php b/functions/db_prefs.php
index a1ee7178..f116c837 100644
--- a/functions/db_prefs.php
+++ b/functions/db_prefs.php
@@ -39,10 +39,9 @@ define('SMDB_MYSQL', 1);
/** PostgreSQL */
define('SMDB_PGSQL', 2);
-require_once(SM_PATH . 'config/config.php');
+
if (!include_once('DB.php')) {
// same error also in abook_database.php
- require_once(SM_PATH . 'functions/display_messages.php');
$error = _("Could not include PEAR database functions required for the database backend.") . "
\n";
$error .= sprintf(_("Is PEAR installed, and is the include path set correctly to find %s?"),
'DB.php') . "
\n";
@@ -212,7 +211,7 @@ class dbPrefs {
/**
* Function used to handle database connection errors
- * @param object PEAR Error object
+ * @param object PEAR Error object
*/
function failQuery($res = NULL) {
if($res == NULL) {
@@ -250,7 +249,7 @@ class dbPrefs {
/**
* Delete user's prefs setting
- * @param string $user user name
+ * @param string $user user name
* @param string $key preference name
* @return boolean
*/
@@ -298,8 +297,8 @@ class dbPrefs {
." See doc/db-backend.txt or contact your system administrator.";
/**
- * Debugging function. Can be used to log all issues that trigger
- * oversized field errors. Function should be enabled in all three
+ * Debugging function. Can be used to log all issues that trigger
+ * oversized field errors. Function should be enabled in all three
* strlen checks. See http://www.php.net/error-log
*/
// error_log($user.'|'.$key.'|'.$value."\n",3,'/tmp/oversized_log');
diff --git a/functions/display_messages.php b/functions/display_messages.php
index 7f94acd5..f01808f5 100644
--- a/functions/display_messages.php
+++ b/functions/display_messages.php
@@ -12,13 +12,6 @@
* @package squirrelmail
*/
-/** @ignore */
-if (! defined('SM_PATH')) define('SM_PATH','../');
-
-/**
- * including plugin functions
- */
-include_once(SM_PATH . 'functions/plugin.php');
/**
* Displays error message and URL to message listing
@@ -52,7 +45,7 @@ function plain_error_message($message, $color) {
/**
* Displays error when user is logged out
- *
+ *
* Error strings can be overriden by logout_error hook
* @param string $errString error message
* @param string $errTitle title of page with error message
@@ -60,16 +53,11 @@ function plain_error_message($message, $color) {
*/
function logout_error( $errString, $errTitle = '' ) {
global $frame_top, $org_logo, $org_name, $org_logo_width, $org_logo_height,
- $hide_sm_attributions, $version, $squirrelmail_language,
+ $hide_sm_attributions, $version, $squirrelmail_language,
$color, $theme, $theme_default;
$base_uri = sqm_baseuri();
- include_once( SM_PATH . 'functions/page_header.php' );
- if ( !isset( $org_logo ) ) {
- // Don't know yet why, but in some accesses $org_logo is not set.
- include( SM_PATH . 'config/config.php' );
- }
/* Display width and height like good little people */
$width_and_height = '';
if (isset($org_logo_width) && is_numeric($org_logo_width) && $org_logo_width>0) {
@@ -132,7 +120,7 @@ function logout_error( $errString, $errTitle = '' ) {
/**
* Displays error message
- *
+ *
* Since 1.4.1 function checks if page header is already displayed.
* Since 1.4.3 and 1.5.1 function contains error_box hook.
* Use plain_error_message() and make sure that page header is created,
@@ -152,8 +140,6 @@ function error_box($string, $color) {
/* check if the page header has been sent; if not, send it! */
if(!isset($pageheader_sent) && !$pageheader_sent) {
- /* include this just to be sure */
- include_once( SM_PATH . 'functions/page_header.php' );
displayHtmlHeader('SquirrelMail: '.$err);
$pageheader_sent = TRUE;
echo "\n\n";
@@ -177,5 +163,4 @@ function error_option_save($message) {
$optpage_save_error=array();
$optpage_save_error=array_merge($optpage_save_error,array($message));
-}
-?>
+}
\ No newline at end of file
diff --git a/functions/file_prefs.php b/functions/file_prefs.php
index e35e4df4..161f2ef7 100644
--- a/functions/file_prefs.php
+++ b/functions/file_prefs.php
@@ -13,11 +13,6 @@
* @since 1.2.5
*/
-/** @ignore */
-if (! defined('SM_PATH')) define('SM_PATH','../');
-
-/** include this for error messages */
-include_once(SM_PATH . 'functions/display_messages.php');
/**
* Check the preferences into the session cache.
@@ -31,6 +26,8 @@ function cachePrefValues($data_dir, $username) {
sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
if ( isset($prefs_are_cached) && $prefs_are_cached) {
sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
+// sm_print_r($prefs_cache);
+// exit;
return;
}
diff --git a/functions/folder_manip.php b/functions/folder_manip.php
index a5e5c02c..3211c888 100644
--- a/functions/folder_manip.php
+++ b/functions/folder_manip.php
@@ -222,7 +222,7 @@ function folders_delete_ask ($imapConnection, $folder_name)
*/
function folders_delete_do ($imapConnection, $delimiter, $folder_name)
{
- require_once(SM_PATH . 'functions/tree.php');
+ include(SM_PATH . 'functions/tree.php');
$boxes = sqimap_mailbox_list ($imapConnection);
diff --git a/functions/gettext.php b/functions/gettext.php
index 5a8f180a..f311150e 100644
--- a/functions/gettext.php
+++ b/functions/gettext.php
@@ -16,8 +16,6 @@
* @subpackage i18n
*/
-/** Almost everything requires global.php... */
-require_once(SM_PATH . 'functions/global.php');
/** Load classes and other functions */
include_once(SM_PATH . 'class/l10n.class.php');
@@ -36,7 +34,7 @@ function _($str) {
global $l10n, $gettext_domain;
if (! isset($l10n[$gettext_domain]) ||
! is_object($l10n[$gettext_domain]) ||
- $l10n[$gettext_domain]->error==1)
+ $l10n[$gettext_domain]->error==1)
return $str;
return $l10n[$gettext_domain]->translate($str);
}
@@ -98,7 +96,7 @@ if (! function_exists('dgettext')) {
global $l10n;
if (! isset($l10n[$domain]) ||
! is_object($l10n[$domain]) ||
- $l10n[$domain]->error==1)
+ $l10n[$domain]->error==1)
return $str;
return $l10n[$domain]->translate($str);
}
diff --git a/functions/global.php b/functions/global.php
index aeee4ff8..f9c189fe 100644
--- a/functions/global.php
+++ b/functions/global.php
@@ -23,6 +23,7 @@ define('SQ_COOKIE',4);
define('SQ_SERVER',5);
define('SQ_FORM',6);
+
/**
* returns true if current php version is at mimimum a.b.c
*
@@ -148,12 +149,10 @@ function sqsession_is_registered ($name) {
* @param int search constant defining where to look
* @return bool whether variable is found.
*/
-function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) {
+function sqgetGlobalVar($name, &$value, $search = SQ_INORDER, $default = NULL, $typecast = false) {
+
+ $result = false;
- /* NOTE: DO NOT enclose the constants in the switch
- statement with quotes. They are constant values,
- enclosing them in quotes will cause them to evaluate
- as strings. */
switch ($search) {
/* we want the default case to be first here,
so that if a valid value isn't specified,
@@ -163,7 +162,8 @@ function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) {
case SQ_SESSION:
if( isset($_SESSION[$name]) ) {
$value = $_SESSION[$name];
- return TRUE;
+ $result = TRUE;
+ break;
} elseif ( $search == SQ_SESSION ) {
break;
}
@@ -171,32 +171,44 @@ function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) {
case SQ_POST:
if( isset($_POST[$name]) ) {
$value = $_POST[$name];
- return TRUE;
+ $result = TRUE;
+ break;
} elseif ( $search == SQ_POST ) {
break;
}
case SQ_GET:
if ( isset($_GET[$name]) ) {
$value = $_GET[$name];
- return TRUE;
+ $result = TRUE;
+ break;
}
/* NO IF HERE. FOR SQ_INORDER CASE, EXIT after GET */
break;
case SQ_COOKIE:
if ( isset($_COOKIE[$name]) ) {
$value = $_COOKIE[$name];
- return TRUE;
+ $result = TRUE;
+ break;
}
break;
case SQ_SERVER:
if ( isset($_SERVER[$name]) ) {
$value = $_SERVER[$name];
- return TRUE;
+ $result = TRUE;
+ break;
}
break;
}
- /* Nothing found, return FALSE */
- return FALSE;
+ if ($result && $typecast) {
+ switch ($typecast) {
+ case 'int': $value = (int) $value; break;
+ case 'bool': $value = (bool) $value; break;
+ default: break;
+ }
+ } else if (!is_null($default)) {
+ $value = $default;
+ }
+ return $result;
}
/**
@@ -227,7 +239,6 @@ function sqsession_destroy() {
$_SESSION = array();
@session_destroy();
}
-
}
/**
@@ -249,18 +260,14 @@ function sqsession_is_active() {
* (IE6 only)
*/
function sqsession_start() {
- global $PHP_SELF;
-
- $dirs = array('|src/.*|', '|plugins/.*|', '|functions/.*|');
- $repl = array('', '', '');
- $base_uri = preg_replace($dirs, $repl, $PHP_SELF);
-
+ global $base_uri;
session_start();
- $sessid = session_id();
+ $session_id = session_id();
+
// session_starts sets the sessionid cookie buth without the httponly var
// setting the cookie again sets the httponly cookie attribute
- sqsetcookie(session_name(),$sessid,false,$base_uri);
+ sqsetcookie(session_name(),session_id(),false,$base_uri);
}
@@ -275,7 +282,21 @@ function sqsession_start() {
* @param boolean $bHttpOnly Disallow JS to access the cookie (IE6 only)
* @return void
*/
-function sqsetcookie($sName,$sValue,$iExpire=false,$sPath="",$sDomain="",$bSecure=false,$bHttpOnly=true) {
+function sqsetcookie($sName,$sValue,$iExpire=false,$sPath="",$sDomain="",$bSecure=false,$bHttpOnly=true,$bFlush=false) {
+ static $sCookieCache;
+ if (!isset($sCache)) {
+ $sCache = '';
+ }
+ /**
+ * We have to send all cookies with one header call otherwise we loose cookies.
+ * In order to achieve that the sqsetcookieflush function calls this function with $bFlush = true.
+ * If that happens we send the cookie header.
+ */
+ if ($bFlush) {
+ header($sCookieCache);
+ return;
+ }
+
$sHeader = "Set-Cookie: $sName=$sValue";
if ($sPath) {
$sHeader .= "; path=$sPath";
@@ -295,10 +316,71 @@ function sqsetcookie($sName,$sValue,$iExpire=false,$sPath="",$sDomain="",$bSecur
$sHeader .= "; HttpOnly";
}
// $sHeader .= "; Version=1";
+ $sCookieCache .= $sHeader ."\r\n";
+ if ($bFlush) {
+ header($sCookieCache);
+ }
+}
+
+/**
+ * Send the cookie header
+ *
+ * Cookies set with sqsetcookie will bet set after a sqsetcookieflush call.
+ * @return void
+ */
+function sqsetcookieflush() {
+ sqsetcookie('','','','','','','',true);
+}
+
+/**
+ * session_regenerate_id replacement for PHP < 4.3.2
+ *
+ * This code is borrowed from Gallery, session.php version 1.53.2.1
+ */
+if (!function_exists('session_regenerate_id')) {
+ function make_seed() {
+ list($usec, $sec) = explode(' ', microtime());
+ return (float)$sec + ((float)$usec * 100000);
+ }
+
+ function php_combined_lcg() {
+ mt_srand(make_seed());
+ $tv = gettimeofday();
+ $lcg['s1'] = $tv['sec'] ^ (~$tv['usec']);
+ $lcg['s2'] = mt_rand();
+ $q = (int) ($lcg['s1'] / 53668);
+ $lcg['s1'] = (int) (40014 * ($lcg['s1'] - 53668 * $q) - 12211 * $q);
+ if ($lcg['s1'] < 0) {
+ $lcg['s1'] += 2147483563;
+ }
+ $q = (int) ($lcg['s2'] / 52774);
+ $lcg['s2'] = (int) (40692 * ($lcg['s2'] - 52774 * $q) - 3791 * $q);
+ if ($lcg['s2'] < 0) {
+ $lcg['s2'] += 2147483399;
+ }
+ $z = (int) ($lcg['s1'] - $lcg['s2']);
+ if ($z < 1) {
+ $z += 2147483562;
+ }
+ return $z * 4.656613e-10;
+ }
- header($sHeader);
+ function session_regenerate_id() {
+ global $base_uri;
+ $tv = gettimeofday();
+ sqgetGlobalVar('REMOTE_ADDR',$remote_addr,SQ_SERVER);
+ $buf = sprintf("%.15s%ld%ld%0.8f", $remote_addr, $tv['sec'], $tv['usec'], php_combined_lcg() * 10);
+ session_id(md5($buf));
+ if (ini_get('session.use_cookies')) {
+ // at a later stage we use sqsetcookie. At this point just do
+ // what session_regenerate_id would do
+ setcookie(session_name(), session_id(), NULL, $base_uri);
+ }
+ return TRUE;
+ }
}
+
/**
* php_self
*
@@ -328,89 +410,4 @@ function php_self () {
return '';
}
-/** set the name of the session cookie */
-if(isset($session_name) && $session_name) {
- ini_set('session.name' , $session_name);
-} else {
- ini_set('session.name' , 'SQMSESSID');
-}
-
-/**
- * If magic_quotes_runtime is on, SquirrelMail breaks in new and creative ways.
- * Force magic_quotes_runtime off.
- * tassium@squirrelmail.org - I put it here in the hopes that all SM code includes this.
- * If there's a better place, please let me know.
- */
-ini_set('magic_quotes_runtime','0');
-
-/* Since we decided all IMAP servers must implement the UID command as defined in
- * the IMAP RFC, we force $uid_support to be on.
- */
-
-global $uid_support;
-$uid_support = true;
-
-/* if running with magic_quotes_gpc then strip the slashes
- from POST and GET global arrays */
-if (get_magic_quotes_gpc()) {
- sqstripslashes($_GET);
- sqstripslashes($_POST);
-}
-
-/**
- * If register_globals are on, unregister globals.
- * Code requires PHP 4.1.0 or newer.
- */
-if ((bool) @ini_get('register_globals')) {
- /**
- * Remove all globals from $_GET, $_POST, and $_COOKIE.
- */
- foreach ($_REQUEST as $key => $value) {
- unset($GLOBALS[$key]);
- }
- /**
- * Remove globalized $_FILES variables
- * Before 4.3.0 $_FILES are included in $_REQUEST.
- * Unglobalize them in separate call in order to remove dependency
- * on PHP version.
- */
- foreach ($_FILES as $key => $value) {
- unset($GLOBALS[$key]);
- // there are three undocumented $_FILES globals.
- unset($GLOBALS[$key.'_type']);
- unset($GLOBALS[$key.'_name']);
- unset($GLOBALS[$key.'_size']);
- }
- /**
- * Remove globalized environment variables.
- */
- foreach ($_ENV as $key => $value) {
- unset($GLOBALS[$key]);
- }
- /**
- * Remove globalized server variables.
- */
- foreach ($_SERVER as $key => $value) {
- unset($GLOBALS[$key]);
- }
-}
-
-/* strip any tags added to the url from PHP_SELF.
- This fixes hand crafted url XXS expoits for any
- page that uses PHP_SELF as the FORM action */
-$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
-
-$PHP_SELF = php_self();
-
-sqsession_is_active();
-
-/**
- * Remove globalized session data in rg=on setups
- */
-if ((bool) @ini_get('register_globals')) {
- foreach ($_SESSION as $key => $value) {
- unset($GLOBALS[$key]);
- }
-}
-?>
diff --git a/functions/html.php b/functions/html.php
index 9597cc92..59f69a25 100644
--- a/functions/html.php
+++ b/functions/html.php
@@ -157,46 +157,4 @@ function set_url_var($url, $var, $val=0, $link=true) {
}
return $url;
}
-
-/**
- * Temporary test function to process template vars with formatting.
- * I use it for viewing the message_header (view_header.php) with
- * a sort of template.
- * @param mixed $var
- * @param mixed $format_ar
- * @since 1.3.0
- * @todo if function is temporary, then why it is used.
- * @deprecated
- */
-function echo_template_var($var, $format_ar = array() ) {
- $frm_last = count($format_ar) -1;
-
- if (isset($format_ar[0])) echo $format_ar[0];
- $i = 1;
-
- switch (true) {
- case (is_string($var)):
- echo $var;
- break;
- case (is_array($var)):
- $frm_a = array_slice($format_ar,1,$frm_last-1);
- foreach ($var as $a_el) {
- if (is_array($a_el)) {
- echo_template_var($a_el,$frm_a);
- } else {
- echo $a_el;
- if (isset($format_ar[$i])) {
- echo $format_ar[$i];
- }
- $i++;
- }
- }
- break;
- default:
- break;
- }
- if (isset($format_ar[$frm_last]) && $frm_last>$i ) {
- echo $format_ar[$frm_last];
- }
-}
?>
\ No newline at end of file
diff --git a/functions/identity.php b/functions/identity.php
index fb90144e..10c377eb 100644
--- a/functions/identity.php
+++ b/functions/identity.php
@@ -12,15 +12,6 @@
* @since 1.4.2
*/
-/** Used to simplify includes
- * @ignore
- */
-if (!defined('SM_PATH')) {
- define('SM_PATH','../');
-}
-
-/** preference and signature functions */
-include_once(SM_PATH . 'include/load_prefs.php');
/**
* Returns an array of all the identities.
@@ -79,7 +70,7 @@ function save_identities($identities) {
$num_cur = getPref($data_dir, $username, 'identities');
-
+
$cnt = count($identities);
// Remove any additional identities in prefs //
@@ -185,9 +176,9 @@ function sqfixidentities( $identities, $id, $action ) {
// Process actions from plugins and save/update action //
default:
/**
- * send action and id information. number of hook arguments
- * differs from 1.4.4 or older and 1.5.0. count($args) can
- * be used to detect modified hook. Older hook does not
+ * send action and id information. number of hook arguments
+ * differs from 1.4.4 or older and 1.5.0. count($args) can
+ * be used to detect modified hook. Older hook does not
* provide information that can be useful for plugins.
*/
do_hook('options_identities_process', $action, $id);
diff --git a/functions/imap.php b/functions/imap.php
index ae7704b3..84dfa9c9 100644
--- a/functions/imap.php
+++ b/functions/imap.php
@@ -14,13 +14,7 @@
*/
/** Includes */
-require_once(SM_PATH . 'functions/imap_mailbox.php');
-require_once(SM_PATH . 'functions/imap_messages.php');
-require_once(SM_PATH . 'functions/imap_general.php');
-
-/** This is here for bc */
-require_once(SM_PATH . 'functions/date.php');
-require_once(SM_PATH . 'functions/mailbox_display.php');
-require_once(SM_PATH . 'functions/mime.php');
+include_once(SM_PATH . 'functions/imap_messages.php');
+include_once(SM_PATH . 'functions/imap_general.php');
?>
\ No newline at end of file
diff --git a/functions/imap_asearch.php b/functions/imap_asearch.php
index 88684694..957591e6 100644
--- a/functions/imap_asearch.php
+++ b/functions/imap_asearch.php
@@ -19,8 +19,8 @@
/** This functionality requires the IMAP and date functions
*/
-require_once(SM_PATH . 'functions/imap_general.php');
-require_once(SM_PATH . 'functions/date.php');
+//require_once(SM_PATH . 'functions/imap_general.php');
+//require_once(SM_PATH . 'functions/date.php');
/** Set to TRUE to dump the IMAP dialogue
* @global bool $imap_asearch_debug_dump
diff --git a/functions/imap_general.php b/functions/imap_general.php
index 1373a20e..1afcafff 100755
--- a/functions/imap_general.php
+++ b/functions/imap_general.php
@@ -13,9 +13,8 @@
*/
/** Includes.. */
-require_once(SM_PATH . 'functions/page_header.php');
-require_once(SM_PATH . 'functions/auth.php');
-include_once(SM_PATH . 'functions/rfc822address.php');
+
+require_once(SM_PATH . 'functions/rfc822address.php');
/**
@@ -64,7 +63,6 @@ function sqimap_run_command_list ($imap_stream, $query, $handle_errors, &$respon
} else {
global $squirrelmail_language, $color;
set_up_language($squirrelmail_language);
- require_once(SM_PATH . 'functions/display_messages.php');
$string = "\n" .
_("ERROR: No available IMAP stream.") .
"\n";
@@ -115,7 +113,6 @@ function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response,
} else {
global $squirrelmail_language, $color;
set_up_language($squirrelmail_language);
- require_once(SM_PATH . 'functions/display_messages.php');
$string = "\n" .
_("ERROR: No available IMAP stream.") .
"\n";
@@ -319,7 +316,6 @@ function sqimap_read_data_list($imap_stream, $tag, $handle_errors,
&$response, &$message, $query = '') {
global $color, $squirrelmail_language;
set_up_language($squirrelmail_language);
- require_once(SM_PATH . 'functions/display_messages.php');
$string = "\n" .
_("ERROR: Bad function call.") .
"
\n" .
@@ -350,7 +346,6 @@ function sqimap_error_box($title, $query = '', $message_title = '', $message = '
global $color, $squirrelmail_language;
set_up_language($squirrelmail_language);
- require_once(SM_PATH . 'functions/display_messages.php');
$string = "\n" . $title . "
\n";
$cmd = explode(' ',$query);
$cmd= strtolower($cmd[0]);
@@ -461,7 +456,7 @@ function sqimap_retrieve_imap_response($imap_stream, $tag, $handle_errors,
case '*':
{
- if (($sCommand == "FETCH" || $sCommand == "STORE") && preg_match('/^\*\s\d+\sFETCH/',$read)) {
+ if (($sCommand == "FETCH" || $sCommand == "STORE") && preg_match('/^\*\s\d+\sFETCH/',$read)) {
/* check for literal */
$s = substr($read,-3);
$fetch_data = array();
@@ -863,7 +858,6 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
/* "BAD" and anything else gets reported here. */
$message = htmlspecialchars($message);
set_up_language($squirrelmail_language, true);
- require_once(SM_PATH . 'functions/display_messages.php');
if ($response == 'BAD') {
$string = sprintf (_("Bad request: %s")."
\r\n", $message);
} else {
@@ -890,8 +884,8 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
*/
set_up_language($squirrelmail_language, true);
- include_once(SM_PATH . 'functions/display_messages.php' );
sqsession_destroy();
+ sqsetcookieflush();
/* terminate the session nicely */
sqimap_logout($imap_stream);
logout_error( _("Unknown user or password incorrect.") );
@@ -911,7 +905,6 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
if ( stristr($message, 'REFERRAL imap') === TRUE ) {
sqimap_logout($imap_stream);
set_up_language($squirrelmail_language, true);
- include_once(SM_PATH . 'functions/display_messages.php' );
sqsession_destroy();
logout_error( _("Your mailbox is not located at this server. Try a different server or consult your system administrator") );
exit;
@@ -948,7 +941,6 @@ function sqimap_capability($imap_stream, $capability='', $bUseCache=true) {
if (!$bUseCache || ! sqgetGlobalVar('sqimap_capabilities', $sqimap_capabilities, SQ_SESSION)) {
$read = sqimap_run_command($imap_stream, 'CAPABILITY', true, $a, $b);
-
$c = explode(' ', $read[0]);
for ($i=2; $i < count($c); $i++) {
$cap_list = explode('=', $c[$i]);
@@ -1297,4 +1289,4 @@ function map_yp_alias($username) {
return chop(substr($yp, strlen($username)+1));
}
-?>
+?>
\ No newline at end of file
diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php
index 41d8fd53..921ec31b 100755
--- a/functions/imap_mailbox.php
+++ b/functions/imap_mailbox.php
@@ -12,13 +12,9 @@
* @subpackage imap
*/
-/** @ignore */
-if (! defined('SM_PATH')) define('SM_PATH','../');
-
/** UTF7 support */
require_once(SM_PATH . 'functions/imap_utf7_local.php');
-global $boxesnew;
/**
* Mailboxes class
@@ -769,7 +765,7 @@ function sqimap_get_mailboxes($imap_stream,$force=false,$show_only_subscribed=tr
if ($show_only_subscribed) { $show_only_subscribed=$show_only_subscribed_folders; }
- require_once(SM_PATH . 'include/load_prefs.php');
+ //require_once(SM_PATH . 'include/load_prefs.php');
/**
* There are three main listing commands we can use in IMAP:
@@ -814,7 +810,6 @@ function sqimap_get_mailboxes($imap_stream,$force=false,$show_only_subscribed=tr
// get subscribed mailbox list from cache (session)
// if not there, then get it from the imap server and store in cache
- sqsession_is_active();
if (!$force) {
sqgetGlobalVar($sub_cache_name,$lsub_cache,SQ_SESSION);
diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php
index 2b1d756f..f17071d3 100644
--- a/functions/mailbox_display.php
+++ b/functions/mailbox_display.php
@@ -12,15 +12,6 @@
* @package squirrelmail
*/
-/** The standard includes.. */
-require_once(SM_PATH . 'functions/strings.php');
-require_once(SM_PATH . 'functions/html.php');
-require_once(SM_PATH . 'functions/imap_mailbox.php');
-require_once(SM_PATH . 'functions/imap_messages.php');
-require_once(SM_PATH . 'functions/imap_asearch.php');
-require_once(SM_PATH . 'functions/mime.php');
-require_once(SM_PATH . 'functions/forms.php');
-
/**
* Selects a mailbox for header retrieval.
@@ -609,9 +600,9 @@ function prepareMessageList(&$aMailbox, $aProps) {
$link = $sTargetModule.'.php?' . implode('&',$aQuery);
// see top of this function for which attributes are available
- // in the global scope for plugin use (like $link, $target,
+ // in the global scope for plugin use (like $link, $target,
// $onclick, $link_extra, $title, and so forth)
- // plugins are responsible for sharing nicely (such as for
+ // plugins are responsible for sharing nicely (such as for
// setting the target, etc)
do_hook('subject_link', array($iPageOffset, $sSearch, $aSearch));
}
diff --git a/functions/mime.php b/functions/mime.php
index 8f232695..d06aecde 100644
--- a/functions/mime.php
+++ b/functions/mime.php
@@ -12,11 +12,32 @@
* @package squirrelmail
*/
-/** The typical includes... */
-require_once(SM_PATH . 'functions/imap.php');
-require_once(SM_PATH . 'functions/attachment_common.php');
-/** add sqm_baseuri()*/
-include_once(SM_PATH . 'functions/display_messages.php');
+/**
+ * dependency information
+ functions dependency
+ mime_structure
+ class/mime/Message.class.php
+ Message::parseStructure
+ functions/page_header.php
+ displayPageHeader
+ functions/display_messages.php
+ plain_error_message
+ mime_fetch_body
+ functions/imap_general.php
+ sqimap_run_command
+ mime_print_body_lines
+
+
+
+functions/imap.php
+functions/attachment_common.php
+functions/display_messages.php
+
+magicHtml => url_parser
+translateText => url_parser
+
+*/
+
/* -------------------------------------------------------------------------- */
/* MIME DECODING */
@@ -37,7 +58,6 @@ function mime_structure ($bodystructure, $flags=array()) {
$i = 0;
$msg = Message::parseStructure($read,$i);
if (!is_object($msg)) {
- include_once(SM_PATH . 'functions/display_messages.php');
global $color, $mailbox;
/* removed urldecode because $_GET is auto urldecoded ??? */
displayPageHeader( $color, $mailbox );
@@ -264,7 +284,7 @@ function translateText(&$body, $wrap_at, $charset) {
global $where, $what; /* from searching */
global $color; /* color theme */
- require_once(SM_PATH . 'functions/url_parser.php');
+ // require_once(SM_PATH . 'functions/url_parser.php');
$body_ary = explode("\n", $body);
for ($i=0; $i < count($body_ary); $i++) {
@@ -489,7 +509,7 @@ function formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $ma
* @return string html formated attachment information.
*/
function formatAttachments($message, $exclude_id, $mailbox, $id) {
- global $where, $what, $startMessage, $color, $passed_ent_id;
+ global $where, $what, $startMessage, $color, $passed_ent_id, $base_uri;
$att_ar = $message->getAttachments($exclude_id);
@@ -506,10 +526,10 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
$type1 = strtolower($header->type1);
$name = '';
$links['download link']['text'] = _("Download");
- $links['download link']['href'] = sqm_baseuri() .
+ $links['download link']['href'] = $base_uri .
"src/download.php?absolute_dl=true&passed_id=$id&mailbox=$urlMailbox&ent_id=$ent";
if ($type0 =='message' && $type1 == 'rfc822') {
- $default_page = sqm_baseuri() . 'src/read_body.php';
+ $default_page = $base_uri . 'src/read_body.php';
$rfc822_header = $att->rfc822_header;
$filename = $rfc822_header->subject;
if (trim( $filename ) == '') {
@@ -530,7 +550,7 @@ function formatAttachments($message, $exclude_id, $mailbox, $id) {
}
$description = $from_name;
} else {
- $default_page = sqm_baseuri() . 'src/download.php';
+ $default_page = $base_uri . 'src/download.php';
$filename = $att->getFilename();
if ($header->description) {
$description = decodeHeader($header->description);
@@ -2073,7 +2093,7 @@ function sq_sanitize($body,
*/
function magicHTML($body, $id, $message, $mailbox = 'INBOX', $take_mailto_links =true) {
- require_once(SM_PATH . 'functions/url_parser.php'); // for $MailTo_PReg_Match
+ // require_once(SM_PATH . 'functions/url_parser.php'); // for $MailTo_PReg_Match
global $attachment_common_show_images, $view_unsafe_images,
$has_unsafe_images;
@@ -2235,7 +2255,7 @@ function magicHTML($body, $id, $message, $mailbox = 'INBOX', $take_mailto_links
if ($take_mailto_links) {
// parseUrl($trusted); // this even parses URLs inside of tags... too aggressive
global $MailTo_PReg_Match;
- $MailTo_PReg_Match = '/mailto:' . substr($MailTo_PReg_Match, 1);
+ $MailTo_PReg_Match = '/mailto:' . substr($MailTo_PReg_Match, 1) ;
if ((preg_match_all($MailTo_PReg_Match, $trusted, $regs)) && ($regs[0][0] != '')) {
foreach ($regs[0] as $i => $mailto_before) {
$mailto_params = $regs[10][$i];
@@ -2390,4 +2410,4 @@ function SendDownloadHeaders($type0, $type1, $filename, $force, $filesize=0) {
} // end fn SendDownloadHeaders
-?>
+?>
\ No newline at end of file
diff --git a/functions/page_header.php b/functions/page_header.php
index 5b4789cc..9c60b63c 100644
--- a/functions/page_header.php
+++ b/functions/page_header.php
@@ -11,15 +11,8 @@
* @package squirrelmail
*/
-/** @ignore */
-if (! defined('SM_PATH')) define('SM_PATH','../');
-
/** Include required files from SM */
-require_once(SM_PATH . 'functions/strings.php');
-require_once(SM_PATH . 'functions/html.php');
-require_once(SM_PATH . 'functions/imap_mailbox.php');
-require_once(SM_PATH . 'functions/global.php');
-include_once(SM_PATH . 'class/template/template.class.php');
+include_once(SM_PATH . 'functions/imap_mailbox.php');
/**
* Output a SquirrelMail page header, from to
@@ -71,6 +64,7 @@ function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE
.(!empty($used_fontsize) ? '&fontsize='.$used_fontsize : '')
.(!empty($text_direction) ? '&dir='.$text_direction : '')."\">\n";
+
// load custom style sheet (deprecated)
if ( ! empty($theme_css) ) {
echo "\n";
@@ -125,7 +119,8 @@ ECHO;
* @param string target the target frame for this link
*/
function makeInternalLink($path, $text, $target='') {
- sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
+ global $base_uri;
+// sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
if ($target != '') {
$target = " target=\"$target\"";
}
@@ -210,7 +205,10 @@ function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
displayHtmlHeader ('SquirrelMail');
$sBodyTagJs = '';
}
-
+ /*
+ * this explains the imap_mailbox.php dependency. We should instead store
+ * the selected mailbox in the session and fallback to the session var.
+ */
$shortBoxName = htmlspecialchars(imap_utf7_decode_local(
readShortMailboxName($mailbox, $delimiter)));
if ( $shortBoxName == 'INBOX' ) {
@@ -293,4 +291,3 @@ function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
}
echo "\n\n";
}
-?>
\ No newline at end of file
diff --git a/functions/plugin.php b/functions/plugin.php
index ab8d5184..6e66aa60 100644
--- a/functions/plugin.php
+++ b/functions/plugin.php
@@ -13,14 +13,6 @@
* @package squirrelmail
*/
-/** Everything needs global.. */
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'config/config.php');
-require_once(SM_PATH . 'functions/prefs.php');
-
-global $squirrelmail_plugin_hooks;
-$squirrelmail_plugin_hooks = array();
-
/**
* This function adds a plugin.
* @param string $name Internal plugin name (ie. delete_move_next)
@@ -200,7 +192,7 @@ function is_plugin_enabled($plugin_name) {
global $plugins;
/**
- * check if variable is empty. if var is not set, php empty
+ * check if variable is empty. if var is not set, php empty
* returns true without error notice.
*
* then check if it is an array
@@ -214,25 +206,4 @@ function is_plugin_enabled($plugin_name) {
return false;
}
}
-
-/*************************************/
-/*** MAIN PLUGIN LOADING CODE HERE ***/
-/*************************************/
-
-/* On startup, register all plugins configured for use. */
-if (isset($plugins) && is_array($plugins)) {
- // turn on output buffering in order to prevent output of new lines
- ob_start();
- foreach ($plugins as $name) {
- use_plugin($name);
- }
- // get output and remove whitespace
- $output = trim(ob_get_contents());
- ob_end_clean();
- // if plugins output more than newlines and spacing, stop script execution.
- if (!empty($output)) {
- die($output);
- }
-}
-
?>
diff --git a/functions/prefs.php b/functions/prefs.php
index ec3bc71c..49244419 100644
--- a/functions/prefs.php
+++ b/functions/prefs.php
@@ -3,7 +3,7 @@
/**
* prefs.php
*
- * This contains functions for manipulating user preferences
+ * This contains functions for filebased user prefs locations
*
* @copyright © 1999-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
@@ -12,32 +12,7 @@
* @subpackage prefs
*/
-/** @ignore */
-if (!defined('SM_PATH')) define('SM_PATH','../');
-/** Include global.php */
-require_once(SM_PATH . 'functions/global.php');
-require_once(SM_PATH . 'functions/plugin.php');
-
-sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
-sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
-
-if ( !sqsession_is_registered('prefs_are_cached') ||
- !isset( $prefs_cache) ||
- !is_array( $prefs_cache)
- ) {
- $prefs_are_cached = false;
- $prefs_cache = array();
-}
-
-$prefs_backend = do_hook_function('prefs_backend');
-if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) {
- require_once(SM_PATH . $prefs_backend);
-} elseif (isset($prefs_dsn) && !empty($prefs_dsn)) {
- require_once(SM_PATH . 'functions/db_prefs.php');
-} else {
- require_once(SM_PATH . 'functions/file_prefs.php');
-}
/* Hashing functions */
@@ -151,33 +126,4 @@ function computeHashDirs($username) {
/* Return our array of hash directories. */
return ($hash_dirs);
}
-
-/**
- * Javascript support detection function
- * @param boolean $reset recheck javascript support if set to true.
- * @return integer SMPREF_JS_ON or SMPREF_JS_OFF ({@see functions/constants.php})
- * @since 1.5.1
- */
-function checkForJavascript($reset = FALSE) {
- global $data_dir, $username, $javascript_on, $javascript_setting;
-
- if ( !$reset && sqGetGlobalVar('javascript_on', $javascript_on, SQ_SESSION) )
- return $javascript_on;
-
- if ( $reset || !isset($javascript_setting) )
- $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
-
- if ( !sqGetGlobalVar('new_js_autodetect_results', $js_autodetect_results) &&
- !sqGetGlobalVar('js_autodetect_results', $js_autodetect_results) )
- $js_autodetect_results = SMPREF_JS_OFF;
-
- if ( $javascript_setting == SMPREF_JS_AUTODETECT )
- $javascript_on = $js_autodetect_results;
- else
- $javascript_on = $javascript_setting;
-
- sqsession_register($javascript_on, 'javascript_on');
- return $javascript_on;
-}
-
?>
\ No newline at end of file
diff --git a/functions/strings.php b/functions/strings.php
index 613f342c..00761057 100644
--- a/functions/strings.php
+++ b/functions/strings.php
@@ -12,35 +12,6 @@
* @package squirrelmail
*/
-/** @ignore */
-if (!defined('SM_PATH')) define('SM_PATH','../');
-
-/**
- * SquirrelMail version number -- DO NOT CHANGE
- */
-global $version;
-$version = '1.5.2 [CVS]';
-
-/**
- * SquirrelMail internal version number -- DO NOT CHANGE
- * $sm_internal_version = array (release, major, minor)
- */
-global $SQM_INTERNAL_VERSION;
-$SQM_INTERNAL_VERSION = array(1,5,2);
-
-/**
- * There can be a circular issue with includes, where the $version string is
- * referenced by the include of global.php, etc. before it's defined.
- * For that reason, bring in global.php AFTER we define the version strings.
- */
-include_once(SM_PATH . 'functions/global.php');
-
-/**
- * Include Compatibility plugin if available.
- */
-if (file_exists(SM_PATH . 'plugins/compatibility/functions.php'))
- include_once(SM_PATH . 'plugins/compatibility/functions.php');
-
/**
* Appends citation markers to the string.
* Also appends a trailing space.
@@ -483,28 +454,6 @@ function readShortMailboxName($haystack, $needle) {
return( $elem );
}
-/**
- * Find out where SquirrelMail lives and try to be smart about it.
- * The only problem would be when SquirrelMail lives in directories
- * called "src", "functions", or "plugins", but people who do that need
- * to be beaten with a steel pipe anyway.
- *
- * @return string the base uri of SquirrelMail installation.
- * @since 1.2.6
- */
-function sqm_baseuri(){
- global $base_uri, $PHP_SELF;
- /**
- * If it is in the session, just return it.
- */
- if (sqgetGlobalVar('base_uri',$base_uri,SQ_SESSION)){
- return $base_uri;
- }
- $dirs = array('|src/.*|', '|plugins/.*|', '|functions/.*|');
- $repl = array('', '', '');
- $base_uri = preg_replace($dirs, $repl, $PHP_SELF);
- return $base_uri;
-}
/**
* get_location
diff --git a/functions/tree.php b/functions/tree.php
index 9df95a5e..14c32383 100644
--- a/functions/tree.php
+++ b/functions/tree.php
@@ -12,11 +12,6 @@
* @package squirrelmail
*/
-/** @ignore */
-if (! defined('SM_PATH')) define('SM_PATH','../');
-
-/** Clearly, this needs the IMAP functions.. */
-require_once(SM_PATH . 'functions/imap.php');
/**
* Recursive function to find the correct parent for a new node.
diff --git a/include/constants.php b/include/constants.php
new file mode 100644
index 00000000..2a602585
--- /dev/null
+++ b/include/constants.php
@@ -0,0 +1,158 @@
+
\ No newline at end of file
diff --git a/include/errors.php b/include/errors.php
index 983a594c..e23e2885 100644
--- a/include/errors.php
+++ b/include/errors.php
@@ -54,7 +54,7 @@ $aErrors['SQM_IMAP_APPEND_QUOTA_ERROR'] = array(
'category' => SQM_ERROR_IMAP,
'message' => _( "Out of quota error."),
'link' => '',
- 'tip' => _("Remove unneccessary messages from your folders. Start with your Trash folder.")
+ 'tip' => _("Remove unneccessary messages from your folder. Start with your Trash folder.")
);
$aErrors['SQM_IMAP_APPEND_ERROR'] = array(
diff --git a/include/init.php b/include/init.php
new file mode 100644
index 00000000..80a17c5c
--- /dev/null
+++ b/include/init.php
@@ -0,0 +1,420 @@
+ -1; --$i) {
+ $sSM_PATH .= '../';
+ if ($a[$i] === 'src' || $a[$i] === 'plugins') {
+ break;
+ }
+}
+
+$base_uri = implode('/',array_slice($a,0,$i)). '/';
+
+
+
+define('SM_PATH',$sSM_PATH);
+
+/**
+ * global var $bInit is used to check if initialisation took place.
+ * At this moment it's a workarounf for the include of addrbook_search_html
+ * inside compose.php. If we found a better way then remove this. Do only use
+ * this var if you know for sure a page can be called stand alone and be included
+ * in another file.
+ */
+$bInit = true;
+
+require(SM_PATH . 'functions/global.php');
+require(SM_PATH . 'config/config.php');
+require(SM_PATH . 'functions/plugin.php');
+require(SM_PATH . 'include/constants.php');
+require(SM_PATH . 'include/languages.php');
+
+/**
+ * If magic_quotes_runtime is on, SquirrelMail breaks in new and creative ways.
+ * Force magic_quotes_runtime off.
+ * tassium@squirrelmail.org - I put it here in the hopes that all SM code includes this.
+ * If there's a better place, please let me know.
+ */
+ini_set('magic_quotes_runtime','0');
+
+
+/* if running with magic_quotes_gpc then strip the slashes
+ from POST and GET global arrays */
+if (get_magic_quotes_gpc()) {
+ sqstripslashes($_GET);
+ sqstripslashes($_POST);
+}
+
+/**
+ * If register_globals are on, unregister globals.
+ * Code requires PHP 4.1.0 or newer.
+ */
+if ((bool) @ini_get('register_globals')) {
+ /**
+ * Remove all globals from $_GET, $_POST, and $_COOKIE.
+ */
+ foreach ($_REQUEST as $key => $value) {
+ unset($GLOBALS[$key]);
+ }
+ /**
+ * Remove globalized $_FILES variables
+ * Before 4.3.0 $_FILES are included in $_REQUEST.
+ * Unglobalize them in separate call in order to remove dependency
+ * on PHP version.
+ */
+ foreach ($_FILES as $key => $value) {
+ unset($GLOBALS[$key]);
+ // there are three undocumented $_FILES globals.
+ unset($GLOBALS[$key.'_type']);
+ unset($GLOBALS[$key.'_name']);
+ unset($GLOBALS[$key.'_size']);
+ }
+ /**
+ * Remove globalized environment variables.
+ */
+ foreach ($_ENV as $key => $value) {
+ unset($GLOBALS[$key]);
+ }
+ /**
+ * Remove globalized server variables.
+ */
+ foreach ($_SERVER as $key => $value) {
+ unset($GLOBALS[$key]);
+ }
+}
+
+/* strip any tags added to the url from PHP_SELF.
+This fixes hand crafted url XXS expoits for any
+ page that uses PHP_SELF as the FORM action */
+$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
+
+$PHP_SELF = php_self();
+
+/**
+ * Initialize the session
+ */
+
+/**
+ * includes from classes stored in the session
+ */
+require(SM_PATH . 'class/mime.class.php');
+
+/** set the name of the session cookie */
+if (!isset($session_name) || !$session_name) {
+ $session_name = 'SQMSESSID';
+}
+ini_set('session.name' , $session_name);
+session_set_cookie_params (0, $base_uri);
+sqsession_is_active();
+
+sqsession_register($base_uri, 'base_uri');
+
+/**
+ * Remove globalized session data in rg=on setups
+ */
+if ((bool) @ini_get('register_globals')) {
+ foreach ($_SESSION as $key => $value) {
+ unset($GLOBALS[$key]);
+ }
+}
+/**
+ * Retrieve the language cookie
+ */
+if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE)) {
+ $squirrelmail_language = '';
+}
+
+
+/**
+ * @var $sInitlocation From where do we include.
+ */
+if (!isset($sInitLocation)) {
+ $sInitLocation=NULL;
+}
+
+/**
+ * MAIN PLUGIN LOADING CODE HERE
+ */
+
+/**
+ * Include Compatibility plugin if available.
+ */
+if (file_exists(SM_PATH . 'plugins/compatibility/functions.php'))
+ include_once(SM_PATH . 'plugins/compatibility/functions.php');
+$squirrelmail_plugin_hooks = array();
+
+/* On init, register all plugins configured for use. */
+if (isset($plugins) && is_array($plugins)) {
+ // turn on output buffering in order to prevent output of new lines
+ ob_start();
+ foreach ($plugins as $name) {
+ use_plugin($name);
+ }
+ // get output and remove whitespace
+ $output = trim(ob_get_contents());
+ ob_end_clean();
+ // if plugins output more than newlines and spacing, stop script execution.
+ if (!empty($output)) {
+ die($output);
+ }
+}
+
+
+switch ($sInitLocation) {
+ case 'style': session_write_close(); sqsetcookieflush(); break;
+ case 'redirect':
+ $prefs_backend = do_hook_function('prefs_backend');
+ if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) {
+ require(SM_PATH . $prefs_backend);
+ } elseif (isset($prefs_dsn) && !empty($prefs_dsn)) {
+ require(SM_PATH . 'functions/db_prefs.php');
+ } else {
+ require(SM_PATH . 'functions/prefs.php');
+ require(SM_PATH . 'functions/file_prefs.php');
+ }
+ //nobreak;
+ case 'login':
+ require(SM_PATH . 'functions/display_messages.php' );
+ require(SM_PATH . 'functions/page_header.php');
+ require(SM_PATH . 'functions/html.php');
+ break;
+ default:
+ require(SM_PATH . 'functions/display_messages.php' );
+ require(SM_PATH . 'functions/page_header.php');
+ require(SM_PATH . 'functions/html.php');
+ require(SM_PATH . 'functions/strings.php');
+
+
+ /**
+ * Check if we are logged in
+ */
+ require(SM_PATH . 'functions/auth.php');
+
+ if ( !sqsession_is_registered('user_is_logged_in') ) {
+ // First we store some information in the new session to prevent
+ // information-loss.
+ //
+ $session_expired_post = $_POST;
+ $session_expired_location = $PHP_SELF;
+ if (!sqsession_is_registered('session_expired_post')) {
+ sqsession_register($session_expired_post,'session_expired_post');
+ }
+ if (!sqsession_is_registered('session_expired_location')) {
+ sqsession_register($session_expired_location,'session_expired_location');
+ }
+ // signout page will deal with users who aren't logged
+ // in on its own; don't show error here
+ //
+ if (strpos($PHP_SELF, 'signout.php') !== FALSE) {
+ return;
+ }
+
+ set_up_language($squirrelmail_language, true);
+ logout_error( _("You must be logged in to access this page.") );
+ exit;
+ }
+
+ sqgetGlobalVar('username',$username,SQ_SESSION);
+
+ /**
+ * Setting the prefs backend
+ */
+ sqgetGlobalVar('prefs_cache', $prefs_cache, SQ_SESSION );
+ sqgetGlobalVar('prefs_are_cached', $prefs_are_cached, SQ_SESSION );
+
+ if ( !sqsession_is_registered('prefs_are_cached') ||
+ !isset( $prefs_cache) ||
+ !is_array( $prefs_cache)) {
+ $prefs_are_cached = false;
+ $prefs_cache = false; //array();
+ }
+
+ $prefs_backend = do_hook_function('prefs_backend');
+ if (isset($prefs_backend) && !empty($prefs_backend) && file_exists(SM_PATH . $prefs_backend)) {
+ require(SM_PATH . $prefs_backend);
+ } elseif (isset($prefs_dsn) && !empty($prefs_dsn)) {
+ require(SM_PATH . 'functions/db_prefs.php');
+ } else {
+ require(SM_PATH . 'functions/prefs.php');
+ require(SM_PATH . 'functions/file_prefs.php');
+ }
+
+ /**
+ * initializing user settings
+ */
+ require(SM_PATH . 'include/load_prefs.php');
+
+
+// i do not understand the frames language cookie story
+ /**
+ * We'll need this to later have a noframes version
+ *
+ * Check if the user has a language preference, but no cookie.
+ * Send him a cookie with his language preference, if there is
+ * such discrepancy.
+ */
+ $my_language = getPref($data_dir, $username, 'language');
+ if ($my_language != $squirrelmail_language) {
+ sqsetcookie('squirrelmail_language', $my_language, time()+2592000, $base_uri);
+ }
+// /dont understand
+
+ /**
+ * Set up the language.
+ */
+ $err=set_up_language(getPref($data_dir, $username, 'language'));
+ /* this is the last cookie we set so flush it. */
+ sqsetcookieflush();
+
+ // Japanese translation used without mbstring support
+ if ($err==2) {
+ $sError =
+ "