* used by the rest of the Squirrelmail code.
*
* $Id$
+ * @package squirrelmail
*/
/**
*
* Specifically, ' comes up as 5 characters instead of 1.
* 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) {
global $languages, $squirrelmail_language;
/**
* Does the opposite of sqWordWrap()
+ * @param string body the text to un-wordwrap
+ * @return void
*/
function sqUnWordWrap(&$body) {
global $squirrelmail_language;
/**
* If $haystack is a full mailbox name and $needle is the mailbox
* 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) {
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 () {
if ( sqgetGlobalVar('REQUEST_URI', $req_uri, SQ_SERVER) && !empty($req_uri) ) {
return $req_uri;
/**
- * 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
- * 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 () {
/**
- * 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) {
$pad = base64_decode($epad);
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) {
$pad = base64_decode($epad);
$encrypted = base64_decode ($string);
* Randomize the mt_rand() function. Toss this in strings or integers
* and it will seed the generator appropriately. With strings, it is
* 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) {
/* if mt_getrandmax() does not return a 2^n - 1 number,
* This function initializes the random number generator fairly well.
* It also only initializes it once, so you don't accidentally get
* the same 'random' numbers twice in one session.
+ *
+ * @return void
*/
function sq_mt_randomize() {
static $randomized;
$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) {
sq_mt_randomize();
}
/**
- * 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) {
$bytes /= 1024;
/**
* 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) {
return $String;
}
+/**
+ * Escapes special characters for use in IMAP commands.
+ * @param string the string to escape
+ * @return string the escaped string
+ */
function quoteimap($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) {
foreach ($array as $k => $v) {
}
}
-// 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)
{
global $compose_new_win,$javascript_on;
// if not using "compose in new window", make
// regular link and be done with it
- //
if($compose_new_win != '1') {
return makeInternalLink($url, $text, 'right');
}
- //
// build the compose in new window link...
- //
// if javascript is on, use onClick event to handle it
- //
if($javascript_on) {
sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
return '<a href="javascript:void(0)" onclick="comp_in_new(\''.$base_uri.$url.'\')">'. $text.'</a>';
// otherwise, just open new window using regular HTML
- //
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() {
ob_start(); // Buffer output
foreach(func_get_args() as $var) {