|
@@ -41,6 +41,10 @@ require_once(SM_PATH . 'functions/global.php');
|
|
*
|
|
*
|
|
* Specifically, ' comes up as 5 characters instead of 1.
|
|
* Specifically, ' comes up as 5 characters instead of 1.
|
|
* This should not add newlines to the end of lines.
|
|
* This should not add newlines to the end of lines.
|
|
|
|
+ *
|
|
|
|
+ * @param string line the line of text to wrap, by ref
|
|
|
|
+ * @param int wrap the maximum line lenth
|
|
|
|
+ * @return void
|
|
*/
|
|
*/
|
|
function sqWordWrap(&$line, $wrap) {
|
|
function sqWordWrap(&$line, $wrap) {
|
|
global $languages, $squirrelmail_language;
|
|
global $languages, $squirrelmail_language;
|
|
@@ -96,6 +100,8 @@ function sqWordWrap(&$line, $wrap) {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Does the opposite of sqWordWrap()
|
|
* Does the opposite of sqWordWrap()
|
|
|
|
+ * @param string body the text to un-wordwrap
|
|
|
|
+ * @return void
|
|
*/
|
|
*/
|
|
function sqUnWordWrap(&$body) {
|
|
function sqUnWordWrap(&$body) {
|
|
global $squirrelmail_language;
|
|
global $squirrelmail_language;
|
|
@@ -135,6 +141,10 @@ function sqUnWordWrap(&$body) {
|
|
/**
|
|
/**
|
|
* If $haystack is a full mailbox name and $needle is the mailbox
|
|
* If $haystack is a full mailbox name and $needle is the mailbox
|
|
* separator character, returns the last part of the mailbox name.
|
|
* separator character, returns the last part of the mailbox name.
|
|
|
|
+ *
|
|
|
|
+ * @param string haystack full mailbox name to search
|
|
|
|
+ * @param string needle the mailbox separator character
|
|
|
|
+ * @return string the last part of the mailbox name
|
|
*/
|
|
*/
|
|
function readShortMailboxName($haystack, $needle) {
|
|
function readShortMailboxName($haystack, $needle) {
|
|
|
|
|
|
@@ -150,6 +160,12 @@ function readShortMailboxName($haystack, $needle) {
|
|
return( $elem );
|
|
return( $elem );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Creates an URL for the page calling this function, using either the PHP global
|
|
|
|
+ * REQUEST_URI, or the PHP global PHP_SELF with QUERY_STRING added.
|
|
|
|
+ *
|
|
|
|
+ * @return string the complete url for this page
|
|
|
|
+ */
|
|
function php_self () {
|
|
function php_self () {
|
|
if ( sqgetGlobalVar('REQUEST_URI', $req_uri, SQ_SERVER) && !empty($req_uri) ) {
|
|
if ( sqgetGlobalVar('REQUEST_URI', $req_uri, SQ_SERVER) && !empty($req_uri) ) {
|
|
return $req_uri;
|
|
return $req_uri;
|
|
@@ -171,13 +187,15 @@ function php_self () {
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * This determines the location to forward to relative to your server.
|
|
|
|
|
|
+ * Determines the location to forward to, relative to your server.
|
|
|
|
+ * This is used in HTTP Location: redirects.
|
|
* If this doesnt work correctly for you (although it should), you can
|
|
* If this doesnt work correctly for you (although it should), you can
|
|
- * remove all this code except the last two lines, and change the header()
|
|
|
|
- * function to look something like this, customized to the location of
|
|
|
|
- * SquirrelMail on your server:
|
|
|
|
|
|
+ * remove all this code except the last two lines, and have it return
|
|
|
|
+ * the right URL for your site, something like:
|
|
|
|
+ *
|
|
|
|
+ * http://www.example.com/squirrelmail/
|
|
*
|
|
*
|
|
- * http://www.myhost.com/squirrelmail/src/login.php
|
|
|
|
|
|
+ * @return string the base url for this SquirrelMail installation
|
|
*/
|
|
*/
|
|
function get_location () {
|
|
function get_location () {
|
|
|
|
|
|
@@ -243,8 +261,13 @@ function get_location () {
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * These functions are used to encrypt the passowrd before it is
|
|
|
|
- * stored in a cookie.
|
|
|
|
|
|
+ * These functions are used to encrypt the password before it is
|
|
|
|
+ * stored in a cookie. The encryption key is generated by
|
|
|
|
+ * OneTimePadCreate();
|
|
|
|
+ *
|
|
|
|
+ * @param string string the (password)string to encrypt
|
|
|
|
+ * @param string epad the encryption key
|
|
|
|
+ * @return string the base64-encoded encrypted password
|
|
*/
|
|
*/
|
|
function OneTimePadEncrypt ($string, $epad) {
|
|
function OneTimePadEncrypt ($string, $epad) {
|
|
$pad = base64_decode($epad);
|
|
$pad = base64_decode($epad);
|
|
@@ -256,6 +279,14 @@ function OneTimePadEncrypt ($string, $epad) {
|
|
return base64_encode($encrypted);
|
|
return base64_encode($encrypted);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Decrypt a password from the cookie, encrypted by OneTimePadEncrypt.
|
|
|
|
+ * This uses the encryption key that is stored in the session.
|
|
|
|
+ *
|
|
|
|
+ * @param string string the string to decrypt
|
|
|
|
+ * @param string epad the encryption key from the session
|
|
|
|
+ * @return string the decrypted password
|
|
|
|
+ */
|
|
function OneTimePadDecrypt ($string, $epad) {
|
|
function OneTimePadDecrypt ($string, $epad) {
|
|
$pad = base64_decode($epad);
|
|
$pad = base64_decode($epad);
|
|
$encrypted = base64_decode ($string);
|
|
$encrypted = base64_decode ($string);
|
|
@@ -272,6 +303,9 @@ function OneTimePadDecrypt ($string, $epad) {
|
|
* Randomize the mt_rand() function. Toss this in strings or integers
|
|
* Randomize the mt_rand() function. Toss this in strings or integers
|
|
* and it will seed the generator appropriately. With strings, it is
|
|
* and it will seed the generator appropriately. With strings, it is
|
|
* better to get them long. Use md5() to lengthen smaller strings.
|
|
* better to get them long. Use md5() to lengthen smaller strings.
|
|
|
|
+ *
|
|
|
|
+ * @param mixed val a value to seed the random number generator
|
|
|
|
+ * @return void
|
|
*/
|
|
*/
|
|
function sq_mt_seed($Val) {
|
|
function sq_mt_seed($Val) {
|
|
/* if mt_getrandmax() does not return a 2^n - 1 number,
|
|
/* if mt_getrandmax() does not return a 2^n - 1 number,
|
|
@@ -298,6 +332,8 @@ function sq_mt_seed($Val) {
|
|
* This function initializes the random number generator fairly well.
|
|
* This function initializes the random number generator fairly well.
|
|
* It also only initializes it once, so you don't accidentally get
|
|
* It also only initializes it once, so you don't accidentally get
|
|
* the same 'random' numbers twice in one session.
|
|
* the same 'random' numbers twice in one session.
|
|
|
|
+ *
|
|
|
|
+ * @return void
|
|
*/
|
|
*/
|
|
function sq_mt_randomize() {
|
|
function sq_mt_randomize() {
|
|
static $randomized;
|
|
static $randomized;
|
|
@@ -333,6 +369,13 @@ function sq_mt_randomize() {
|
|
$randomized = 1;
|
|
$randomized = 1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Creates an encryption key for encrypting the password stored in the cookie.
|
|
|
|
+ * The encryption key itself is stored in the session.
|
|
|
|
+ *
|
|
|
|
+ * @param int length optional, length of the string to generate
|
|
|
|
+ * @return string the encryption key
|
|
|
|
+ */
|
|
function OneTimePadCreate ($length=100) {
|
|
function OneTimePadCreate ($length=100) {
|
|
sq_mt_randomize();
|
|
sq_mt_randomize();
|
|
|
|
|
|
@@ -345,7 +388,10 @@ function OneTimePadCreate ($length=100) {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns a string showing the size of the message/attachment.
|
|
|
|
|
|
+ * Returns a string showing the size of the message/attachment.
|
|
|
|
+ *
|
|
|
|
+ * @param int bytes the filesize in bytes
|
|
|
|
+ * @return string the filesize in human readable format
|
|
*/
|
|
*/
|
|
function show_readable_size($bytes) {
|
|
function show_readable_size($bytes) {
|
|
$bytes /= 1024;
|
|
$bytes /= 1024;
|
|
@@ -370,10 +416,14 @@ function show_readable_size($bytes) {
|
|
/**
|
|
/**
|
|
* Generates a random string from the caracter set you pass in
|
|
* Generates a random string from the caracter set you pass in
|
|
*
|
|
*
|
|
- * Flags:
|
|
|
|
- * 1 = add lowercase a-z to $chars
|
|
|
|
- * 2 = add uppercase A-Z to $chars
|
|
|
|
- * 4 = add numbers 0-9 to $chars
|
|
|
|
|
|
+ * @param int size the size of the string to generate
|
|
|
|
+ * @param string chars a string containing the characters to use
|
|
|
|
+ * @param int flags a flag to add a specific set to the characters to use:
|
|
|
|
+ * Flags:
|
|
|
|
+ * 1 = add lowercase a-z to $chars
|
|
|
|
+ * 2 = add uppercase A-Z to $chars
|
|
|
|
+ * 4 = add numbers 0-9 to $chars
|
|
|
|
+ * @return string the random string
|
|
*/
|
|
*/
|
|
|
|
|
|
function GenerateRandomString($size, $chars, $flags = 0) {
|
|
function GenerateRandomString($size, $chars, $flags = 0) {
|
|
@@ -402,12 +452,18 @@ function GenerateRandomString($size, $chars, $flags = 0) {
|
|
return $String;
|
|
return $String;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Escapes special characters for use in IMAP commands.
|
|
|
|
+ * @param string the string to escape
|
|
|
|
+ * @return string the escaped string
|
|
|
|
+ */
|
|
function quoteimap($str) {
|
|
function quoteimap($str) {
|
|
return ereg_replace('(["\\])', '\\\\1', $str);
|
|
return ereg_replace('(["\\])', '\\\\1', $str);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Trims every element in the array
|
|
|
|
|
|
+ * Trims every element in the array, ie. remove the first char of each element
|
|
|
|
+ * @param array array the array to trim
|
|
*/
|
|
*/
|
|
function TrimArray(&$array) {
|
|
function TrimArray(&$array) {
|
|
foreach ($array as $k => $v) {
|
|
foreach ($array as $k => $v) {
|
|
@@ -425,10 +481,13 @@ function TrimArray(&$array) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// Returns a link to the compose-page, taking in
|
|
|
|
-// consideration the compose_in_new and javascript
|
|
|
|
-// settings.
|
|
|
|
-//
|
|
|
|
|
|
+/**
|
|
|
|
+ * Returns a link to the compose-page, taking in consideration
|
|
|
|
+ * the compose_in_new and javascript settings.
|
|
|
|
+ * @param string url the URL to the compose page
|
|
|
|
+ * @param string text the link text, default "Compose"
|
|
|
|
+ * @return string a link to the compose page
|
|
|
|
+ */
|
|
function makeComposeLink($url, $text = null)
|
|
function makeComposeLink($url, $text = null)
|
|
{
|
|
{
|
|
global $compose_new_win,$javascript_on;
|
|
global $compose_new_win,$javascript_on;
|
|
@@ -440,19 +499,15 @@ function makeComposeLink($url, $text = null)
|
|
|
|
|
|
// if not using "compose in new window", make
|
|
// if not using "compose in new window", make
|
|
// regular link and be done with it
|
|
// regular link and be done with it
|
|
- //
|
|
|
|
if($compose_new_win != '1') {
|
|
if($compose_new_win != '1') {
|
|
return makeInternalLink($url, $text, 'right');
|
|
return makeInternalLink($url, $text, 'right');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- //
|
|
|
|
// build the compose in new window link...
|
|
// build the compose in new window link...
|
|
- //
|
|
|
|
|
|
|
|
|
|
|
|
// if javascript is on, use onClick event to handle it
|
|
// if javascript is on, use onClick event to handle it
|
|
- //
|
|
|
|
if($javascript_on) {
|
|
if($javascript_on) {
|
|
sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
|
|
sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
|
|
return '<a href="javascript:void(0)" onclick="comp_in_new(\''.$base_uri.$url.'\')">'. $text.'</a>';
|
|
return '<a href="javascript:void(0)" onclick="comp_in_new(\''.$base_uri.$url.'\')">'. $text.'</a>';
|
|
@@ -460,18 +515,19 @@ function makeComposeLink($url, $text = null)
|
|
|
|
|
|
|
|
|
|
// otherwise, just open new window using regular HTML
|
|
// otherwise, just open new window using regular HTML
|
|
- //
|
|
|
|
return makeInternalLink($url, $text, '_blank');
|
|
return makeInternalLink($url, $text, '_blank');
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
-* sm_print_r($some_variable, [$some_other_variable [, ...]]);
|
|
|
|
-* Debugging function - does the same as print_r, but makes sure special
|
|
|
|
-* characters are converted to htmlentities first. This will allow
|
|
|
|
-* values like <some@email.address> to be displayed.
|
|
|
|
-* The output is wrapped in <pre> and </pre> tags.
|
|
|
|
-*/
|
|
|
|
|
|
+ * sm_print_r($some_variable, [$some_other_variable [, ...]]);
|
|
|
|
+ * Debugging function - does the same as print_r, but makes sure special
|
|
|
|
+ * characters are converted to htmlentities first. This will allow
|
|
|
|
+ * values like <some@email.address> to be displayed.
|
|
|
|
+ * The output is wrapped in <pre> and </pre> tags.
|
|
|
|
+ *
|
|
|
|
+ * @return void
|
|
|
|
+ */
|
|
function sm_print_r() {
|
|
function sm_print_r() {
|
|
ob_start(); // Buffer output
|
|
ob_start(); // Buffer output
|
|
foreach(func_get_args() as $var) {
|
|
foreach(func_get_args() as $var) {
|