/** Load up some useful constants */
require_once(SM_PATH . 'functions/constants.php');
-/** corrects a time stamp to be the local time */
+/**
+ * Corrects a time stamp to be the local time.
+ *
+ * @param int stamp the timestamp to adjust
+ * @param string tzc the timezone correction
+ * @return int the corrected timestamp
+ */
function getGMTSeconds($stamp, $tzc) {
/* date couldn't be parsed */
if ($stamp == -1) {
}
/**
- Switch system has been intentionaly chosen for the
- internationalization of month and day names. The reason
- is to make sure that _("") strings will go into the
- main po.
-**/
-
+ * Returns the (localized) string for a given day number.
+ * Switch system has been intentionaly chosen for the
+ * internationalization of month and day names. The reason
+ * is to make sure that _("") strings will go into the
+ * main po.
+ *
+ * @param int day_number the day number
+ * @return string the day in human readable form
+ */
function getDayName( $day_number ) {
switch( $day_number ) {
return( $ret );
}
+/**
+ * Like getDayName, but returns the short form
+ * @param int day_number the day number
+ * @return string the day in short human readable form
+ */
function getDayAbrv( $day_number ) {
switch( $day_number ) {
return( $ret );
}
+
+/**
+ * Returns the (localized) string for a given month number.
+ *
+ * @param string month_number the month number (01..12)
+ * @return string the month name in human readable form
+ */
function getMonthName( $month_number ) {
switch( $month_number ) {
case '01':
return( $ret );
}
+/**
+ * Returns the (localized) string for a given month number,
+ * short representation.
+ *
+ * @param string month_number the month number (01..12)
+ * @return string the shortened month in human readable form
+ */
function getMonthAbrv( $month_number ) {
switch( $month_number ) {
case '01':
return( $ret );
}
-
+/**
+ * Returns the localized representation of the date/time.
+ *
+ * @param string date_format The format for the date, like the input for the PHP date() function.
+ * @param int stamp the timestamp to convert
+ * @return string a full date representation
+ */
function date_intl( $date_format, $stamp ) {
$ret = str_replace( array('D','F','l','M'), array('$1','$2','$3','$4'), $date_format );
- $ret = date('w#m#'. $ret, $stamp ); // to reduce the date calls we retrieve m and w in the same call
- $aParts = explode('#',$ret); // extract day and month in order to replace later by intl day and month
+ // to reduce the date calls we retrieve m and w in the same call
+ $ret = date('w#m#'. $ret, $stamp );
+ // extract day and month in order to replace later by intl day and month
+ $aParts = explode('#',$ret);
$ret = str_replace(array('$1','$4','$2','$3',), array(getDayAbrv($aParts[0]),
getMonthAbrv($aParts[1]),
getMonthName($aParts[1]),
getDayName($aParts[0])),
$aParts[2]);
- return( $ret );
+ return( $ret );
}
+/**
+ * This returns a date of the format "Wed, Oct 29, 2003 9:52 am",
+ * or the same in 24H format (depending on the user's settings),
+ * and taking localization into accout.
+ *
+ * @param int stamp the timestamp
+ * @return string the long date string
+ */
function getLongDateString( $stamp ) {
global $hour_format;
}
+/**
+ * Returns a short representation of the date,
+ * taking timezones and localization into account.
+ * Depending on user's settings, this string can be
+ * of the form: "14:23" or "Jun 14, 2003" depending
+ * on whether the stamp is "today" or not.
+ *
+ * @param int stamp the timestamp
+ * @return string the date string
+ */
function getDateString( $stamp ) {
global $invert_time, $hour_format, $show_full_date;
return( date_intl( $date_format, $stamp ) );
}
+/**
+ * Decodes a RFC 822 Date-header into a timestamp
+ *
+ * @param array dateParts the Date-header split by whitespace
+ * @return int the timestamp calculated from the header
+ */
function getTimeStamp($dateParts) {
/** $dateParts[0] == <day of week> Mon, Tue, Wed
** $dateParts[1] == <day of month> 23
* returns true if current php version is at mimimum a.b.c
*
* Called: check_php_version(4,1)
+ * @param int a major version number
+ * @param int b minor version number
+ * @param int c release number
+ * @return bool
*/
function check_php_version ($a = '0', $b = '0', $c = '0')
{
* constructed by us, as an array of 3 ints.
*
* Called: check_sm_version(1,3,3)
+ * @param int a major version number
+ * @param int b minor version number
+ * @param int c release number
+ * @return bool
*/
function check_sm_version($a = 0, $b = 0, $c = 0)
{
}
-/* recursively strip slashes from the values of an array */
+/**
+ * Recursively strip slashes from the values of an array.
+ * @param array array the array to strip, passed by reference
+ * @return void
+ */
function sqstripslashes(&$array) {
if(count($array) > 0) {
foreach ($array as $index=>$value) {
}
}
+/**
+ * Add a variable to the session.
+ * @param mixed $var the variable to register
+ * @param string $name the name to refer to this variable
+ * @return void
+ */
function sqsession_register ($var, $name) {
sqsession_is_active();
session_register("$name");
}
+/**
+ * Delete a variable from the session.
+ * @param string $name the name of the var to delete
+ * @return void
+ */
function sqsession_unregister ($name) {
sqsession_is_active();
session_unregister("$name");
}
+/**
+ * Checks to see if a variable has already been registered
+ * in the session.
+ * @param string $name the name of the var to check
+ * @return bool whether the var has been registered
+ */
function sqsession_is_registered ($name) {
$test_name = &$name;
$result = false;
* sqgetGlobalVar('username',$username,SQ_SESSION);
* -- no quotes around last param!
*
- * Returns FALSE if variable is not found.
- * Returns TRUE if it is.
+ * @param string name the name of the var to search
+ * @param mixed value the variable to return
+ * @param int search constant defining where to look
+ * @return bool whether variable is found.
*/
function sqgetGlobalVar($name, &$value, $search = SQ_INORDER) {
return FALSE;
}
+/**
+ * Deletes an existing session, more advanced than the standard PHP
+ * session_destroy(), it explicitly deletes the cookies and global vars.
+ */
function sqsession_destroy() {
/*
}
-/*
+/**
* Function to verify a session has been started. If it hasn't
* start a session up. php.net doesn't tell you that $_SESSION
* (even though autoglobal), is not created unless a session is
require_once(SM_PATH . 'functions/global.php');
/**
- * Always set up the language before calling these functions
+ * Output a SquirrelMail page header, from <!doctype> to </head>
+ * Always set up the language before calling these functions.
+ *
+ * @param string title the page title, default SquirrelMail.
+ * @param string xtra extra HTML to insert into the header
+ * @param bool do_hook whether to execute hooks, default true
+ * @return void
*/
function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE ) {
global $squirrelmail_language;
$pageheader_sent = TRUE;
}
+/**
+ * Given a path to a SquirrelMail file, return a HTML link to it
+ *
+ * @param string path the SquirrelMail file to link to
+ * @param string text the link text
+ * @param string target the target frame for this link
+ */
function makeInternalLink($path, $text, $target='') {
sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
if ($target != '') {
return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
}
+/**
+ * Same as makeInternalLink, but echoes it too
+ */
function displayInternalLink($path, $text, $target='') {
echo makeInternalLink($path, $text, $target);
}
+/**
+ * Outputs a complete SquirrelMail page header, starting with <!doctype> and
+ * including the default menu bar. Uses displayHtmlHeader and takes
+ * JavaScript and locale settings into account.
+ *
+ * @param array color the array of theme colors
+ * @param string mailbox the current mailbox name to display
+ * @param string xtra extra html code to add
+ * @param bool session
+ * @return void
+ */
function displayPageHeader($color, $mailbox, $xtra='', $session=false) {
global $hide_sm_attributions, $PHP_SELF, $frame_top,
"</table><br>\n\n";
}
-/* blatently copied/truncated/modified from the above function */
+/**
+ * Blatantly copied/truncated/modified from displayPageHeader.
+ * Outputs a page header specifically for the compose_in_new popup window
+ *
+ * @param array color the array of theme colors
+ * @param string mailbox the current mailbox name to display
+ * @return void
+ */
function compose_Header($color, $mailbox) {
global $javascript_on;
return $data;
}
-/* This function executes a hook. */
+/**
+ * This function executes a hook and allows for parameters to be passed.
+ *
+ * @param string name the name of the hook
+ * @param mixed param the parameters to pass to the hook function
+ * @return mixed the return value of the hook function
+ */
function do_hook_function($name,$parm=NULL) {
global $squirrelmail_plugin_hooks;
$ret = '';
return $ret;
}
-/* This function executes a hook. */
+/**
+ * This function executes a hook, concatenating the results of each
+ * plugin that has the hook defined.
+ *
+ * @param string name the name of the hook
+ * @param mixed parm optional hook function parameters
+ * @return string a concatenation of the results of each plugin function
+ */
function concat_hook_function($name,$parm=NULL) {
global $squirrelmail_plugin_hooks;
$ret = '';
* false. If $priority is > 0, any one or more trues will override
* any falses. If $priority < 0, then one or more falses will
* override any trues.
- * Priority 0 means majority rules. Ties will be broken with $tie */
+ * Priority 0 means majority rules. Ties will be broken with $tie
+ *
+ * @param string name the hook name
+ * @param mixed parm the parameters for the hook function
+ * @param int priority
+ * @param bool tie
+ * @return bool the result of the function
+ */
function boolean_hook_function($name,$parm=NULL,$priority=0,$tie=false) {
global $squirrelmail_plugin_hooks;
$yea = 0;
* This function checks whether the user's USER_AGENT is known to
* be broken. If so, returns true and the plugin is invisible to the
* offending browser.
+ * This function needs to have its name changed!
+ *
+ * @return bool whether this browser properly supports JavaScript
*/
function soupNazi(){
/* Hashing functions */
+/**
+ * Given a username and datafilename, this will return the path to the
+ * hashed location of that datafile.
+ *
+ * @param string username the username of the current user
+ * @param string dir the squirrelmail datadir
+ * @param string datafile the name of the file to open
+ * @param bool hash_seach default true
+ * @return string the hashed location of datafile
+ */
function getHashedFile($username, $dir, $datafile, $hash_search = true) {
global $dir_hash_level;
return ($result);
}
+/**
+ * Helper function for getHashedFile, given a username returns the hashed
+ * dir for that username.
+ *
+ * @param string username the username of the current user
+ * @param string dir the squirrelmail datadir
+ * @param string hash_dirs default ''
+ * @return the path to the hash dir for username
+ */
function getHashedDir($username, $dir, $hash_dirs = '') {
global $dir_hash_level;
return ($real_hash_dir);
}
+/**
+ * Helper function for getHashDir which does the actual hash calculation.
+ *
+ * @param string username the username to calculate the hash dir for
+ * @return array a list of hash dirs for this username
+ */
function computeHashDirs($username) {
/* Compute the hash for this user and extract the hash directories. */
$hash = base_convert(crc32($username), 10, 16);
*
* 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) {
require_once(SM_PATH . 'functions/imap.php');
/**
- * Recursive function to find the correct parent for a new node
+ * Recursive function to find the correct parent for a new node.
+ *
+ * @param mixed value the value to find a parent for
+ * @param int treeIndexToStart where to start the search, usually the root node (0)
+ * @param array tree the tree to search
+ * @return int the index of the parent
*/
-
function findParentForChild($value, $treeIndexToStart, $tree) {
// is $value in $tree[$treeIndexToStart]['value']
if ((isset($tree[$treeIndexToStart])) && (strstr($value, $tree[$treeIndexToStart]['value']))) {
}
}
+/**
+ * Will insert a new value into the tree, based on a given comparison value.
+ *
+ * @param mixed comparisonValue the value to determine where the new element should be placed.
+ * @param mixed value the new node to insert
+ * @param array tree the tree to insert the node in, by ref
+ */
function addChildNodeToTree($comparisonValue, $value, &$tree) {
$parentNode = findParentForChild($comparisonValue, 0, $tree);
}
}
+/**
+ * Recursively walk the tree of trash mailboxes and delete all folders and messages
+ *
+ * @param int index the place in the tree to start, usually 0
+ * @param stream imap_stream the IMAP connection to send commands to
+ * @param array tree the tree to walk
+ * @return void
+ */
function walkTreeInPreOrderEmptyTrash($index, $imap_stream, $tree) {
global $trash_folder;
if ($tree[$index]['doIHaveChildren']) {
}
+/**
+ * Recursively delete a tree of mail folders.
+ *
+ * @param int index the place in the tree to start, usually 0
+ * @param stream imap_stream the IMAP connection to send commands to
+ * @param array tree the tree to walk
+ * @return void
+ */
function walkTreeInPreOrderDeleteFolders($index, $imap_stream, $tree) {
if ($tree[$index]['doIHaveChildren']) {
for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
}
}
+/**
+ * Recursively walk a tree of folders to create them under the trash folder.
+ */
function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName) {
global $trash_folder, $delimiter;
}
}
+/**
+ * Recursive function that outputs a tree In-Pre-Order.
+ * @param int index the node to start (usually 0)
+ * @param array tree the tree to walk
+ * @return void
+ */
function simpleWalkTreePre($index, $tree) {
if ($tree[$index]['doIHaveChildren']) {
for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
$Email_RegExp_Match = '[0-9a-z]([-_.+]?[0-9a-z])*(%' . $Host_RegExp_Match .
')?@' . $Host_RegExp_Match;
+/**
+ * Parses a body and converts all found email addresses to clickable links.
+ *
+ * @param string body the body to process, by ref
+ * @return int the number of unique addresses found
+ */
function parseEmail (&$body) {
global $color, $Email_RegExp_Match;
$sbody = $body;
']', '[', '{', '}', "\240", ', ', '. ', ",\n", ",\r");
+/**
+ * Parses a body and converts all found URLs to clickable links.
+ *
+ * @param string body the body to process, by ref
+ * @return void
+ */
function parseUrl (&$body) {
global $url_parser_poss_ends, $url_parser_url_tokens;;
$start = 0;