Tons of formatting changes by Jon Tai.
authorindiri69 <indiri69@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 16 Mar 2002 19:44:50 +0000 (19:44 +0000)
committerindiri69 <indiri69@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 16 Mar 2002 19:44:50 +0000 (19:44 +0000)
Didn't merge changes to imap_search.php, as I wanted to take a
closer look at it.

Jon Tai said:
I cleaned up the four imap_*.php files - fixed comments so they use the
/* */ style, fixed spacings, added { } around logic blocks that didn't
have them, etc.

I also hacked sqimap_find_email() in imap_general.php to support strings
in the form of "lehresma@css.tayloru.edu (Luke Ehresman)".

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2591 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/imap_general.php
functions/imap_mailbox.php
functions/imap_messages.php

index 64e11117221bb269ec961f5bd110212e40e25892..28fe6cffe8a536209d5cba0030660c8b67be193e 100755 (executable)
 require_once('../functions/page_header.php');
 require_once('../functions/display_messages.php');
 
-/**
- * Unique SessionId
- *
- * Sets an unique session id in order to avoid simultanous sessions crash.
- *
- * @return  string  a 4 chars unique string
- */
-
 global $sqimap_session_id;
 $sqimap_session_id = 1;
-function sqimap_session_id() {
 
+/* Sets an unique session id in order to avoid simultanous sessions crash. */
+function sqimap_session_id() {
     global $data_dir, $username, $sqimap_session_id;
-
     return( sprintf("A%03d", $sqimap_session_id++) );
 }
 
-/******************************************************************************
-** Both send a command and accept the result from the command.  This is
-** to allow proper session number handling.
-******************************************************************************/
-
+/*
+ * Both send a command and accept the result from the command.
+ * This is to allow proper session number handling.
+ */
 function sqimap_run_command_list ($imap_stream, $query, $handle_errors, &$response, &$message) {
     $sid = sqimap_session_id();
     fputs ($imap_stream, $sid . ' ' . $query . "\r\n");
@@ -52,13 +43,11 @@ function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response, &
 
 
 /*
- *  Reads the output from the IMAP stream.  If handle_errors is set to true,
- *  this will also handle all errors that are received.  If it is not set,
- *  the errors will be sent back through $response and $message
+ * Reads the output from the IMAP stream.  If handle_errors is set to true,
+ * this will also handle all errors that are received.  If it is not set,
+ * the errors will be sent back through $response and $message
  */
-
-function sqimap_read_data_list ($imap_stream, $pre, $handle_errors,
-                               &$response, &$message, $query = '') {
+function sqimap_read_data_list ($imap_stream, $pre, $handle_errors, &$response, &$message, $query = '') {
     global $color, $squirrelmail_language;
 
     $read = '';
@@ -76,12 +65,12 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors,
             }
         }
 
-        // if (ereg("^\\* [0-9]+ FETCH.*\\{([0-9]+)\\}", $read, $regs)) {
+        /* if (ereg("^\\* [0-9]+ FETCH.*\\{([0-9]+)\\}", $read, $regs)) { */
         if (preg_match('/^\* [0-9]+ FETCH.*\{([0-9]+)\}/', $read, $regs)) {
-            $size = $regs[1];
-        //} else if (ereg("^\\* [0-9]+ FETCH", $read, $regs)) {
+           $size = $regs[1];
+        /* } else if (ereg("^\\* [0-9]+ FETCH", $read, $regs)) { */
         } else if (preg_match('/^\* [0-9]+ FETCH/', $read, $regs)) {
-            // Sizeless response, probably single-line
+            /* Sizeless response, probably single-line */
             $size = -1;
             $data[] = $read;
             $read = fgets($imap_stream, $bufsize);
@@ -94,10 +83,10 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors,
                     break;
                 }
             }
-            // If we know the size, no need to look at the end parameters
+            /* If we know the size, no need to look at the end parameters */
             if ($size > 0) {
                 if ($total_size == $size) {
-                    // We've reached the end of this 'message', switch to the next one.
+                    /* We've reached the end of this 'message', switch to the next one. */
                     $data[] = $read;
                     break;
                 } else if ($total_size > $size) {
@@ -115,34 +104,35 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors,
                 }
                 $total_size += strlen($read);
             } else {
+                /* if (ereg("^$pre (OK|BAD|NO)(.*)", $read, $regs) || */
                 if (preg_match("/^$pre (OK|BAD|NO)(.*)/", $read, $regs) ||
-                // if (ereg("^$pre (OK|BAD|NO)(.*)", $read, $regs) ||
-                   (($size == -1) && preg_match('/^\* [0-9]+ FETCH.*/', $read, $regs))) {
+                    /* (($size == -1) && ereg("^\\* [0-9]+ FETCH.*", $read, $regs))) { */
+                    (($size == -1) && preg_match('/^\* [0-9]+ FETCH.*/', $read, $regs))) {
                     break;
                 } else if ( preg_match('/^\* OK \[PARSE.*/', $read, $regs ) ) {
+                    /*
+                     * This block has been added in order to avoid the problem
+                     * caused by the * OK [PARSE] Missing parameter answer
+                     * Please, replace it with a better parsing if you know how.
+                     * This block has been updated by
+                     * Seth E. Randall <sethr@missoulafcu.org>.  Once we see
+                     * one OK [PARSE line, we just go through and keep
+                     * tossing them out until we get something different.
+                     */
                     while ( preg_match('/^\* OK \[PARSE.*/', $read, $regs ) ) {
                         $read = fgets($imap_stream, $bufsize);
                     }
-                    /*
-                        This block has been added in order to avoid the problem
-                        caused by the * OK [PARSE] Missing parameter answer
-                        Please, replace it with a better parsing if you know how.
-                        This block has been updated by
-                        Seth E. Randall <sethr@missoulafcu.org>.  Once we see
-                        one OK [PARSE line, we just go through and keep
-                        tossing them out until we get something different.
-                    */
                     $data[] = $read;
                     $read = fgets ($imap_stream, $bufsize);
                 } else if (preg_match('/^\* BYE \[ALERT\](.*)/', $read, $regs)) {
                     /*
-                        It seems that the IMAP server has coughed a lung up
-                        and hung up the connection.  Print any info we have
-                        and abort.
+                     * It seems that the IMAP server has coughed up a lung
+                     * and hung up the connection.  Print any info we have
+                     * and abort.
                      */
                     echo _("Please contact your system administrator and report the following error:") . "<br>\n";
-                    echo "$regs[1]";
-                    exit(0);
+                    echo $regs[1];
+                    exit;
                 } else {
                     $data[] = $read;
                     $read = fgets ($imap_stream, $bufsize);
@@ -150,8 +140,10 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors,
             }
         }
 
-        // while (($more_msgs = !ereg("^$pre (OK|BAD|NO)(.*)$", $read, $regs)) &&
-        // !ereg("^\\* [0-9]+ FETCH.*", $read, $regs)) {
+        /*
+         * while (($more_msgs = !ereg("^$pre (OK|BAD|NO)(.*)$", $read, $regs)) &&
+         * !ereg("^\\* [0-9]+ FETCH.*", $read, $regs)) {
+         */
         while (($more_msgs = !preg_match("/^$pre (OK|BAD|NO)(.*)$/", $read, $regs)) &&
             !preg_match('/^\* [0-9]+ FETCH.*/', $read, $regs)) {
             $read = fgets($imap_stream, $bufsize);
@@ -165,7 +157,7 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors,
     if ($handle_errors == false) {
         return( $resultlist );
     } else if ($response == 'NO') {
-        // ignore this error from m$ exchange, it is not fatal (aka bug)
+        /* ignore this error from M$ exchange, it is not fatal (aka bug) */
         if (strstr($message, 'command resulted in') === false) {
             set_up_language($squirrelmail_language);
             echo "<br><b><font color=$color[2]>\n" .
@@ -188,36 +180,32 @@ function sqimap_read_data_list ($imap_stream, $pre, $handle_errors,
              $message . "</font><br>\n";
         exit;
     } else {
-        return( $resultlist );
+        return $resultlist;
     }
 }
 
 function sqimap_read_data ($imap_stream, $pre, $handle_errors, &$response, &$message, $query = '') {
-
     $res = sqimap_read_data_list($imap_stream, $pre, $handle_errors, $response, $message, $query);
     return $res[0];
-
 }
 
-/******************************************************************************
-**  Logs the user into the imap server.  If $hide is set, no error messages
-**  will be displayed.  This function returns the imap connection handle.
-******************************************************************************/
+/*
+ * Logs the user into the imap server.  If $hide is set, no error messages
+ * will be displayed.  This function returns the imap connection handle.
+ */
 function sqimap_login ($username, $password, $imap_server_address, $imap_port, $hide) {
-
     global $color, $squirrelmail_language, $HTTP_ACCEPT_LANGUAGE, $onetimepad;
 
-    $imap_stream = fsockopen ( $imap_server_address, $imap_port,
-                             $error_number, $error_string, 15);
+    $imap_stream = fsockopen ( $imap_server_address, $imap_port, $error_number, $error_string, 15);
     if ( !$imap_stream ) {
-        return FALSE;
+        return false;
     }
     $server_info = fgets ($imap_stream, 1024);
 
-    // Decrypt the password
+    /* Decrypt the password */
     $password = OneTimePadDecrypt($password, $onetimepad);
 
-    /** Do some error correction **/
+    /* Do some error correction */
     if (!$imap_stream) {
         if (!$hide) {
             set_up_language($squirrelmail_language, true);
@@ -230,11 +218,11 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
     $query = 'LOGIN "' . quoteIMAP($username) .  '" "' . quoteIMAP($password) . '"';
     $read = sqimap_run_command ($imap_stream, $query, false, $response, $message);
 
-    /** If the connection was not successful, lets see why **/
+    /* If the connection was not successful, lets see why */
     if ($response != 'OK') {
         if (!$hide) {
             if ($response != 'NO') {
-                // "BAD" and anything else gets reported here.
+                /* "BAD" and anything else gets reported here. */
                 set_up_language($squirrelmail_language, true);
                 if ($response == 'BAD') {
                    printf (_("Bad request: %s")."<br>\r\n", $message);
@@ -249,14 +237,14 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
                 }
                 exit;
             } else {
-                /* If the user does not log in with the correct
+                /*
+                 * If the user does not log in with the correct
                  * username and password it is not possible to get the
                  * correct locale from the user's preferences.
                  * Therefore, apply the same hack as on the login
                  * screen.
-                 */
-
-                /* $squirrelmail_language is set by a cookie when
+                 *
+                 * $squirrelmail_language is set by a cookie when
                  * the user selects language and logs out
                  */
 
@@ -272,13 +260,10 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
             exit;
         }
     }
-
     return $imap_stream;
 }
 
-/*
- *  Simply logs out the imap session
- */
+/* Simply logs out the IMAP session */
 function sqimap_logout ($imap_stream) {
     /* Logout is not valid until the server returns 'BYE' */
     sqimap_run_command($imap_stream, 'LOGOUT', false, $response, $message);
@@ -293,26 +278,23 @@ function sqimap_capability($imap_stream, $capability) {
         $c = explode(' ', $read[0]);
         for ($i=2; $i < count($c); $i++) {
             $cap_list = explode('=', $c[$i]);
-            if (isset($cap_list[1]))
+            if (isset($cap_list[1])) {
                 $sqimap_capabilities[$cap_list[0]] = $cap_list[1];
-            else
+            } else {
                 $sqimap_capabilities[$cap_list[0]] = TRUE;
+            }
         }
     }
-    if (! isset($sqimap_capabilities[$capability])) {
-        return false;
-    } else {
+    if (isset($sqimap_capabilities[$capability])) {
         return $sqimap_capabilities[$capability];
+    } else {
+        return false;
     }
 }
 
-/******************************************************************************
-**  Returns the delimeter between mailboxes:  INBOX/Test, or INBOX.Test...
-******************************************************************************/
+/* Returns the delimeter between mailboxes: INBOX/Test, or INBOX.Test */
 function sqimap_get_delimiter ($imap_stream = false) {
-
-    global $sqimap_delimiter;
-    global $optional_delimiter;
+    global $sqimap_delimiter, $optional_delimiter;
 
     /* Use configured delimiter if set */
     if((!empty($optional_delimiter)) && $optional_delimiter != 'detect') {
@@ -322,12 +304,13 @@ function sqimap_get_delimiter ($imap_stream = false) {
     /* Do some caching here */
     if (!$sqimap_delimiter) {
         if (sqimap_capability($imap_stream, 'NAMESPACE')) {
-            /* According to something that I can't find, this is supposed to work on all systems
-            OS: This won't work in Courier IMAP.
-            OS:  According to rfc2342 response from NAMESPACE command is:
-            OS:  * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES)
-            OS:  We want to lookup all personal NAMESPACES...
-            */
+            /*
+             * According to something that I can't find, this is supposed to work on all systems
+             * OS: This won't work in Courier IMAP.
+             * OS: According to rfc2342 response from NAMESPACE command is:
+             * OS: * NAMESPACE (PERSONAL NAMESPACES) (OTHER_USERS NAMESPACE) (SHARED NAMESPACES)
+             * OS: We want to lookup all personal NAMESPACES...
+             */
             $read = sqimap_run_command($imap_stream, 'NAMESPACE', true, $a, $b);
             if (eregi('\\* NAMESPACE +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL) +(\\( *\\(.+\\) *\\)|NIL)', $read[0], $data)) {
                 if (eregi('^\\( *\\((.*)\\) *\\)', $data[1], $data2)) {
@@ -355,49 +338,44 @@ function sqimap_get_delimiter ($imap_stream = false) {
 }
 
 
-/*
- *  Gets the number of messages in the current mailbox.
- */
+/* Gets the number of messages in the current mailbox. */
 function sqimap_get_num_messages ($imap_stream, $mailbox) {
-
     $read_ary = sqimap_run_command ($imap_stream, "EXAMINE \"$mailbox\"", true, $result, $message);
     for ($i = 0; $i < count($read_ary); $i++) {
         if (ereg("[^ ]+ +([^ ]+) +EXISTS", $read_ary[$i], $regs)) {
             return $regs[1];
         }
     }
-    return sprintf( "BUG!  Couldn't get number of messages in %s!", $mailbox );
-
+    return "BUG! Couldn't get number of messages in $mailbox!";
 }
 
 
-/*
-*  Returns a displayable email address
-*/
+/* Returns a displayable email address.
+ *     Luke Ehresman <lehresma@css.tayloru.edu>
+ *     "Luke Ehresman" <lehresma@css.tayloru.edu>
+ *     <lehresma@css.tayloru.edu>
+ *     lehresma@css.tayloru.edu (Luke Ehresman)
+ *     lehresma@css.tayloru.edu
+ * becomes: lehresma@css.tayloru.edu
+ */
 function sqimap_find_email ($string) {
-    /** Luke Ehresman <lehresma@css.tayloru.edu>
-    ** <lehresma@css.tayloru.edu>
-    ** lehresma@css.tayloru.edu
-    **
-    ** What about
-    **    lehresma@css.tayloru.edu (Luke Ehresman)
-    **/
-
     if (ereg("<([^>]+)>", $string, $regs)) {
         $string = $regs[1];
+    } else if (ereg("([^ ]+@[^ ]+)", $string, $regs)) {
+        $string = $regs[1];
     }
     return trim($string);
 }
 
 
 /*
- *  Takes the From: field, and creates a displayable name.
- *    Luke Ehresman   <lkehresman@yahoo.com>
- *    "Luke Ehresman" <lkehresman@yahoo.com>
- *    lkehresman@yahoo.com (Luke Ehresman)
- *           becomes:   Luke Ehresman
- *    <lkehresman@yahoo.com>
- *           becomes:   lkehresman@yahoo.com
+ * Takes the From: field and creates a displayable name.
+ *     Luke Ehresman   <lkehresman@yahoo.com>
+ *     "Luke Ehresman" <lkehresman@yahoo.com>
+ *     lkehresman@yahoo.com (Luke Ehresman)
+ * becomes: Luke Ehresman
+ *     <lkehresman@yahoo.com>
+ * becomes: lkehresman@yahoo.com
  */
 function sqimap_find_displayable_name ($string) {
     $string = trim($string);
@@ -431,10 +409,9 @@ function sqimap_find_displayable_name ($string) {
 }
 
 /*
- Returns the number of unseen messages in this folder
-*/
+ * Returns the number of unseen messages in this folder
+ */
 function sqimap_unseen_messages ($imap_stream, $mailbox) {
-    //fputs ($imap_stream, sqimap_session_id() . " SEARCH UNSEEN NOT DELETED\r\n");
     $read_ary = sqimap_run_command ($imap_stream, "STATUS \"$mailbox\" (UNSEEN)", true, $result, $message);
     $i = 0;
     while (isset($read_ary[$i])) {
@@ -448,8 +425,8 @@ function sqimap_unseen_messages ($imap_stream, $mailbox) {
 
 
 /*
-*  Saves a message to a given folder -- used for saving sent messages
-*/
+ *  Saves a message to a given folder -- used for saving sent messages
+ */
 function sqimap_append ($imap_stream, $sent_folder, $length) {
     fputs ($imap_stream, sqimap_session_id() . " APPEND \"$sent_folder\" (\\Seen) \{$length}\r\n");
     $tmp = fgets ($imap_stream, 1024);
index 2ecd675716de939d484f1f6df886ee8ecb66f80d..6c4d916e5cc087d5f6af4cd510feaf7c6480a1db 100755 (executable)
  * $Id$
  */
 
-GLOBAL $boxesnew;
+global $boxesnew;
 
 function isBoxBelow( $box2, $box1 ) {
-
     global $delimiter, $folder_prefix, $imap_server_type;
 
     if ( $imap_server_type == 'uw' ) {
         $boxs = $box2;
         $i = strpos( $box1, $delimiter, strlen( $folder_prefix ) );
-        if ( $i === FALSE ) {
+        if ( $i === false ) {
             $i = strlen( $box2 );
         }
     } else {
         $boxs = $box2 . $delimiter;
-        // Skip next second delimiter
+        /* Skip next second delimiter */
         $i = strpos( $box1, $delimiter );
         $i = strpos( $box1, $delimiter, $i + 1  );
-        if ( $i === FALSE ) {
+        if ( $i === false ) {
             $i = strlen( $box2 );
         } else {
             $i++;
         }
     }
 
-    return( substr( $box1, 0, $i ) == substr( $boxs, 0, $i ) );
-
+    return ( substr( $box1, 0, $i ) == substr( $boxs, 0, $i ) );
 }
 
-/*
-    Defines Special Mail Boxes
-*/
+/* Defines special mailboxes */
 function isSpecialMailbox( $box ) {
-
     global $trash_folder, $sent_folder, $draft_folder,
            $move_to_trash, $move_to_sent, $save_as_draft;
 
@@ -56,36 +51,28 @@ function isSpecialMailbox( $box ) {
         $ret = do_hook_function( 'special_mailbox', $box );
     }
 
-    return( $ret );
-
+    return $ret;
 }
 
-/*************************
- **  Expunges a mailbox **
- *************************/
-function sqimap_mailbox_expunge ($imap_stream, $mailbox,$handle_errors = TRUE) {
-    $read = sqimap_run_command($imap_stream, 'EXPUNGE',
-                               $handle_errors, $response, $message);
+/* Expunges a mailbox */
+function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true) {
+    $read = sqimap_run_command($imap_stream, 'EXPUNGE', $handle_errors,
+                               $response, $message);
 }
 
-
-/******************************************************************************
- **  Checks whether or not the specified mailbox exists 
- ******************************************************************************/
+/* Checks whether or not the specified mailbox exists */
 function sqimap_mailbox_exists ($imap_stream, $mailbox) {
     if (! isset($mailbox)) {
         return false;
     }
     $mbx = sqimap_run_command($imap_stream, "LIST \"\" \"$mailbox\"",
-                              TRUE, $response, $message);
+                              true, $response, $message);
     return isset($mbx[0]);
 }
 
-/******************************************************************************
- **  Selects a mailbox
- ******************************************************************************/
+/* Selects a mailbox */
 function sqimap_mailbox_select ($imap_stream, $mailbox,
-                                $hide=TRUE, $recent=false, $extrainfo=false) {
+                                $hide = true, $recent = false, $extrainfo = false) {
     global $auto_expunge;
 
     if ( $mailbox == 'None' ) {
@@ -93,7 +80,7 @@ function sqimap_mailbox_select ($imap_stream, $mailbox,
     }
 
     $read = sqimap_run_command($imap_stream, "SELECT \"$mailbox\"",
-                               TRUE, $response, $message);
+                               true, $response, $message);
     if ($recent) {
         for ($i=0; $i<count($read); $i++) {
             if (strpos(strtolower($read[$i]), 'recent')) {
@@ -103,8 +90,7 @@ function sqimap_mailbox_select ($imap_stream, $mailbox,
         return $r[1];
     } else {
         if ($auto_expunge) {
-            $tmp = sqimap_run_command($imap_stream, 'EXPUNGE',
-                                  false, $a, $b);
+            $tmp = sqimap_run_command($imap_stream, 'EXPUNGE', false, $a, $b);
         }
         if (isset( $extrainfo ) && $extrainfo) {
             $result = array();
@@ -133,81 +119,52 @@ function sqimap_mailbox_select ($imap_stream, $mailbox,
     }
 }
 
-
-
-/******************************************************************************
- **  Creates a folder
- ******************************************************************************/
-function sqimap_mailbox_create ($imap_stream, $mailbox, $type)
-{
+/* Creates a folder */
+function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
     global $delimiter;
     if (strtolower($type) == 'noselect') {
-        $mailbox = $mailbox.$delimiter;
+        $mailbox .= $delimiter;
     }
     $read_ary = sqimap_run_command($imap_stream, "CREATE \"$mailbox\"",
-                                   TRUE, $response, $message);
-
+                                   true, $response, $message);
     sqimap_subscribe ($imap_stream, $mailbox);
 }
 
-
-
-/******************************************************************************
- **  Subscribes to an existing folder 
- ******************************************************************************/
-function sqimap_subscribe ($imap_stream, $mailbox)
-{
+/* Subscribes to an existing folder */
+function sqimap_subscribe ($imap_stream, $mailbox) {
     $read_ary = sqimap_run_command($imap_stream, "SUBSCRIBE \"$mailbox\"",
-                                 TRUE, $response, $message);
+                                   true, $response, $message);
 }
 
-
-
-/******************************************************************************
- **  Unsubscribes to an existing folder 
- ******************************************************************************/
-function sqimap_unsubscribe ($imap_stream, $mailbox)
-{
+/* Unsubscribes to an existing folder */
+function sqimap_unsubscribe ($imap_stream, $mailbox) {
     global $imap_server_type;
-    
     $read_ary = sqimap_run_command($imap_stream, "UNSUBSCRIBE \"$mailbox\"",
-                                 TRUE, $response, $message);
+                                   true, $response, $message);
 }
 
-
-
-/******************************************************************************
- **  This function simply deletes the given folder
- ******************************************************************************/
-function sqimap_mailbox_delete ($imap_stream, $mailbox)
-{
+/* Deletes the given folder */
+function sqimap_mailbox_delete ($imap_stream, $mailbox) {
     $read_ary = sqimap_run_command($imap_stream, "DELETE \"$mailbox\"",
-                                 TRUE, $response, $message);
+                                   true, $response, $message);
     sqimap_unsubscribe ($imap_stream, $mailbox);
-       do_hook_function("rename_or_delete_folder",$args = array($mailbox, 'delete', ''));
+    do_hook_function("rename_or_delete_folder", $args = array($mailbox, 'delete', ''));
 }
 
-/***********************************************************************
- ** Determines if the user is subscribed to the folder or not
- **********************************************************************/
+/* Determines if the user is subscribed to the folder or not */
 function sqimap_mailbox_is_subscribed($imap_stream, $folder) {
-
     $boxesall = sqimap_mailbox_list ($imap_stream);
     foreach ($boxesall as $ref) {
         if ($ref['unformatted'] == $folder) {
-            return TRUE;
+            return true;
         }
     }
     return false;
 }
 
-
-/*
-    Renames a mailbox
-*/
+/* Renames a mailbox */
 function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) {
-
-    if ( $old_name <> $new_name ) {
+    if ( $old_name != $new_name ) {
         global $delimiter, $imap_server_type;
         if ( substr( $old_name, -1 ) == $delimiter  ) {
             $old_name = substr( $old_name, 0, strlen( $old_name ) - 1 );
@@ -218,8 +175,7 @@ function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) {
         }
         $boxesall = sqimap_mailbox_list($imap_stream);
         $cmd = 'RENAME "' . quoteIMAP($old_name) . '" "' .  quoteIMAP($new_name) . '"';
-        $data = sqimap_run_command($imap_stream, $cmd,
-                                 TRUE, $response, $message);
+        $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
         sqimap_unsubscribe($imap_stream, $old_name.$postfix);
         sqimap_subscribe($imap_stream, $new_name.$postfix);
         do_hook_function("rename_or_delete_folder",$args = array($old_name, 'rename', $new_name));
@@ -230,56 +186,53 @@ function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) {
                 $new_sub = $new_name . $delimiter . substr($box[$p], $l);
                 if ($imap_server_type == 'cyrus') {
                     $cmd = 'RENAME "' . quoteIMAP($box[$p]) . '" "' .  quoteIMAP($new_sub) . '"';
-                    $data = sqimap_run_command($imap_stream, $cmd, TRUE, 
+                    $data = sqimap_run_command($imap_stream, $cmd, true,
                                                $response, $message);
                 }
                 sqimap_unsubscribe($imap_stream, $box[$p]);
                 sqimap_subscribe($imap_stream, $new_sub);
-                       do_hook_function("rename_or_delete_folder",$args = array($box[$p], 'rename', $new_sub));
+                do_hook_function("rename_or_delete_folder",
+                                 $args = array($box[$p], 'rename', $new_sub));
             }
         }
     }
-
 }
 
-/******************************************************************************
- **  Formats a mailbox into 4 parts for the $boxesall array
- **
- **  The four parts are:
- **
- **    raw            - Raw LIST/LSUB response from the IMAP server
- **    formatted      - nicely formatted folder name
- **    unformatted    - unformatted, but with delimiter at end removed
- **    unformatted-dm - folder name as it appears in raw response
- **    unformatted-disp - unformatted without $folder_prefix
- **
- ******************************************************************************/
-function sqimap_mailbox_parse ($line, $line_lsub)
-{
+/*
+ * Formats a mailbox into 4 parts for the $boxesall array
+ *
+ * The four parts are:
+ *
+ *     raw            - Raw LIST/LSUB response from the IMAP server
+ *     formatted      - nicely formatted folder name
+ *     unformatted    - unformatted, but with delimiter at end removed
+ *     unformatted-dm - folder name as it appears in raw response
+ *     unformatted-disp - unformatted without $folder_prefix
+ */
+function sqimap_mailbox_parse ($line, $line_lsub) {
     global $folder_prefix, $delimiter;
-    
+
     /* Process each folder line */
     for ($g=0; $g < count($line); $g++) {
-        
+
         /* Store the raw IMAP reply */
         if (isset($line[$g])) {
             $boxesall[$g]["raw"] = $line[$g];
         }
         else {
-            $boxesall[$g]["raw"] = "";
+            $boxesall[$g]["raw"] = '';
         }
-        
-        
+
+
         /* Count number of delimiters ($delimiter) in folder name */
         $mailbox = trim($line_lsub[$g]);
         $dm_count =  substr_count($mailbox, $delimiter);
         if (substr($mailbox, -1) == $delimiter) {
-            /* If name ends in delimiter - decrement count by one */
-            $dm_count--;  
+            /* If name ends in delimiter, decrement count by one */
+            $dm_count--;
         }
-        
-        /* Format folder name, but only if it's a INBOX.* or have */
-        /* a parent. */
+
+        /* Format folder name, but only if it's a INBOX.* or has a parent. */
         $boxesallbyname[$mailbox] = $g;
         $parentfolder = readMailboxParent($mailbox, $delimiter);
         if ( (strtolower(substr($mailbox, 0, 5)) == "inbox") ||
@@ -288,7 +241,7 @@ function sqimap_mailbox_parse ($line, $line_lsub)
                (strlen($parentfolder) > 0) ) ) {
             $indent = $dm_count - ( substr_count($folder_prefix, $delimiter));
             if ($indent > 0) {
-                $boxesall[$g]['formatted']  = str_repeat("&nbsp;&nbsp;", $indent);
+                $boxesall[$g]['formatted']  = str_repeat('&nbsp;&nbsp;', $indent);
             }
             else {
                 $boxesall[$g]['formatted'] = '';
@@ -323,16 +276,17 @@ function sqimap_mailbox_parse ($line, $line_lsub)
     return $boxesall;
 }
 
-/**
+/*
  * Sorting function used to sort mailbox names.
- *   + Original patch from dave_michmerhuizen@yahoo.com
- *   + Allows case insensitivity when sorting folders
- *   + Takes care of the delimiter being sorted to the end, causing
- *     subfolders to be listed in below folders that are prefixed
- *     with their parent folders name.
- *        For example: INBOX.foo, INBOX.foobar, and INBOX.foo.bar
- *        Without special sort function: foobar between foo and foo.bar
- *        With special sort function: foobar AFTER foo and foo.bar :)
+ *     + Original patch from dave_michmerhuizen@yahoo.com
+ *     + Allows case insensitivity when sorting folders
+ *     + Takes care of the delimiter being sorted to the end, causing
+ *       subfolders to be listed in below folders that are prefixed
+ *       with their parent folders name.
+ *
+ *       For example: INBOX.foo, INBOX.foobar, and INBOX.foo.bar
+ *       Without special sort function: foobar between foo and foo.bar
+ *       With special sort function: foobar AFTER foo and foo.bar :)
  */
 function user_strcasecmp($a, $b) {
     global $delimiter;
@@ -375,52 +329,55 @@ function user_strcasecmp($a, $b) {
         }
     }
 
-    return ($result);
+    return $result;
 }
 
 
-/******************************************************************************
- **  Returns sorted mailbox lists in several different ways.
- * See comment on sqimap_mailbox_parse() for info about the returned array.
- ******************************************************************************/
+/*
+ * Returns sorted mailbox lists in several different ways. 
+ * See comment on sqimap_mailbox_parse() for info about the returned array.
+ */
 function sqimap_mailbox_list($imap_stream) {
-
-    GLOBAL $boxesnew;
+    global $boxesnew;
 
     if ( !isset( $boxesnew ) ) {
 
-        GLOBAL $data_dir, $username, $list_special_folders_first,
+        global $data_dir, $username, $list_special_folders_first,
                $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
                $move_to_trash, $move_to_sent, $save_as_draft,
                $delimiter;
 
-        $inbox_in_list = $inbox_subscribed = FALSE;
+        $inbox_in_list = false;
+        $inbox_subscribed = false;
 
         require_once('../src/load_prefs.php');
         require_once('../functions/array.php');
 
-        /** LSUB array **/
+        /* LSUB array */
         $lsub_ary = sqimap_run_command ($imap_stream, "LSUB \"$folder_prefix\" \"*%\"",
-                                      TRUE, $response, $message);
+                                        true, $response, $message);
 
-        /* Section about removing the last element was removed */
-        /* We don't return "* OK" anymore from sqimap_read_data */
+        /*
+         * Section about removing the last element was removed 
+         * We don't return "* OK" anymore from sqimap_read_data
+         */
 
         $sorted_lsub_ary = array();
         for ($i=0;$i < count($lsub_ary); $i++) {
-            /* Workaround for EIMS */
-            /* Doesn't work if the mailbox name is multiple lines */
+            /*
+             * Workaround for EIMS
+             * Doesn't work if the mailbox name is multiple lines
+             */
             if (isset($lsub_ary[$i + 1]) &&
                 ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
                      $lsub_ary[$i], $regs)) {
                 $i ++;
-                $lsub_ary[$i] = $regs[1] . '"' . addslashes(trim($lsub_ary[$i])) .
-                    '"' . $regs[2];
+                $lsub_ary[$i] = $regs[1] . '"' . addslashes(trim($lsub_ary[$i])) . '"' . $regs[2];
             }
             $temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
             $sorted_lsub_ary[] = $temp_mailbox_name;
             if (strtoupper($temp_mailbox_name) == 'INBOX') {
-                $inbox_subscribed = TRUE;
+                $inbox_subscribed = true;
             }
         }
         $new_ary = array();
@@ -434,7 +391,7 @@ function sqimap_mailbox_list($imap_stream) {
             usort($sorted_lsub_ary, 'user_strcasecmp');
         }
 
-        /** LIST array **/
+        /* LIST array */
         $sorted_list_ary = array();
         for ($i=0; $i < count($sorted_lsub_ary); $i++) {
             if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
@@ -445,13 +402,12 @@ function sqimap_mailbox_list($imap_stream) {
             }
 
             $read = sqimap_run_command ($imap_stream, "LIST \"\" \"$mbx\"",
-                                      TRUE, $response, $message);
+                                        true, $response, $message);
             /* Another workaround for EIMS */
             if (isset($read[1]) &&
                 ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
                      $read[0], $regs)) {
-                $read[0] = $regs[1] . '"' . addslashes(trim($read[1])) .
-                           '"' . $regs[2];
+                $read[0] = $regs[1] . '"' . addslashes(trim($read[1])) . '"' . $regs[2];
             }
 
             if (isset($sorted_list_ary[$i])) {
@@ -467,17 +423,17 @@ function sqimap_mailbox_list($imap_stream) {
 
             if (isset($sorted_list_ary[$i]) &&
                 strtoupper(find_mailbox_name($sorted_list_ary[$i])) == 'INBOX') {
-                $inbox_in_list = TRUE;
+                $inbox_in_list = true;
             }
         }
 
-        /**
+        /*
          * Just in case they're not subscribed to their inbox,
          * we'll get it for them anyway
          */
-        if ($inbox_subscribed == false || $inbox_in_list == false) {
+        if (!$inbox_subscribed || !$inbox_in_list) {
             $inbox_ary = sqimap_run_command ($imap_stream, "LIST \"\" \"INBOX\"",
-                                           TRUE, $response, $message);
+                                             true, $response, $message);
             /* Another workaround for EIMS */
             if (isset($inbox_ary[1]) &&
                 ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
@@ -492,27 +448,25 @@ function sqimap_mailbox_list($imap_stream) {
 
         $boxesall = sqimap_mailbox_parse ($sorted_list_ary, $sorted_lsub_ary);
 
-        /** Now, lets sort for special folders **/
+        /* Now, lets sort for special folders */
         $boxesnew = $used = array();
 
         /* Find INBOX */
         foreach ( $boxesall as $k => $box ) {
             if ( strtolower($box['unformatted']) == 'inbox') {
                 $boxesnew[] = $box;
-                $used[$k] = TRUE;
+                $used[$k] = true;
             } else {
-                $used[$k] = FALSE;
+                $used[$k] = false;
             }
         }
 
         /* List special folders and their subfolders, if requested. */
-        if ($list_special_folders_first == TRUE) {
-
+        if ($list_special_folders_first) {
             foreach ( $boxesall as $k => $box ) {
-                if ( !$used[$k] &&
-                     isSpecialMailbox( $box['unformatted'] ) ) {
+                if ( !$used[$k] && isSpecialMailbox( $box['unformatted'] ) ) {
                     $boxesnew[] = $box;
-                    $used[$k] = TRUE;
+                    $used[$k] = true;
                 }
             }
 
@@ -526,25 +480,21 @@ function sqimap_mailbox_list($imap_stream) {
         }
     }
 
-    return( $boxesnew );
-
+    return $boxesnew;
 }
 
 /*
  *  Returns a list of all folders, subscribed or not
  */
 function sqimap_mailbox_list_all($imap_stream) {
-
-
-    GLOBAL $list_special_folders_first, $folder_prefix,
-           $delimiter;
+    global $list_special_folders_first, $folder_prefix, $delimiter;
 
     require_once('../functions/array.php');
 
     $ssid = sqimap_session_id();
     $lsid = strlen( $ssid );
     fputs ($imap_stream, $ssid . " LIST \"$folder_prefix\" *\r\n");
-    $read_ary = sqimap_read_data ($imap_stream, $ssid, TRUE, $response, $message);
+    $read_ary = sqimap_read_data ($imap_stream, $ssid, true, $response, $message);
     $g = 0;
     $phase = 'inbox';
 
@@ -554,9 +504,7 @@ function sqimap_mailbox_list_all($imap_stream) {
             ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
                  $read_ary[$i], $regs)) {
             $i ++;
-            $read_ary[$i] = $regs[1] . '"' .
-                            addslashes(trim($read_ary[$i])) .
-                            '"' . $regs[2];
+            $read_ary[$i] = $regs[1] . '"' . addslashes(trim($read_ary[$i])) . '"' . $regs[2];
         }
         if (substr($read_ary[$i], 0, $lsid) != $ssid ) {
 
@@ -571,8 +519,7 @@ function sqimap_mailbox_list_all($imap_stream) {
                 $dm_count--;
             }
 
-            /* Format folder name, but only if it's a INBOX.* or have */
-            /* a parent. */
+            /* Format folder name, but only if it's a INBOX.* or has a parent. */
             $boxesallbyname[$mailbox] = $g;
             $parentfolder = readMailboxParent($mailbox, $delimiter);
             if((eregi('^inbox'.quotemeta($delimiter), $mailbox)) ||
@@ -595,21 +542,17 @@ function sqimap_mailbox_list_all($imap_stream) {
                 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
             }
             $boxes[$g]['unformatted'] = $mailbox;
-            $boxes[$g]['unformatted-disp'] =
-                ereg_replace('^' . $folder_prefix, '', $mailbox);
+            $boxes[$g]['unformatted-disp'] = ereg_replace('^' . $folder_prefix, '', $mailbox);
             $boxes[$g]['id'] = $g;
 
-            /** Now lets get the flags for this mailbox **/
+            /* Now lets get the flags for this mailbox */
             $read_mlbx = sqimap_run_command ($imap_stream, "LIST \"\" \"$mailbox\"",
-                                           TRUE, $response, $message);
+                                             true, $response, $message);
 
             /* Another workaround for EIMS */
             if (isset($read_mlbx[1]) &&
-                ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
-                     $read_mlbx[0], $regs)) {
-                $read_mlbx[0] = $regs[1] . '"' .
-                                addslashes(trim($read_mlbx[1])) .
-                                '"' . $regs[2];
+                ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", $read_mlbx[0], $regs)) {
+                $read_mlbx[0] = $regs[1] . '"' . addslashes(trim($read_mlbx[1])) . '"' . $regs[2];
             }
 
             $flags = substr($read_mlbx[0], strpos($read_mlbx[0], '(')+1);
index a411f6829d679e15257cb96f46e73d0ad748996a..031122c9ed48e812dbad76f85890fb058ed573fc 100755 (executable)
  * $Id$
  */
 
-/****************************************************************************
- **  Copies specified messages to specified folder
- ****************************************************************************/
+/* Copies specified messages to specified folder */
 function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
     $read = sqimap_run_command ($imap_stream, "COPY $start:$end \"$mailbox\"", true, $response, $message);
 }
 
-/****************************************************************************
- **  Deletes specified messages and moves them to trash if possible
- ****************************************************************************/
+/* Deletes specified messages and moves them to trash if possible */
 function sqimap_messages_delete ($imap_stream, $start, $end, $mailbox) {
     global $move_to_trash, $trash_folder, $auto_expunge;
 
     if (($move_to_trash == true) && (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) {
         sqimap_messages_copy ($imap_stream, $start, $end, $trash_folder);
-        sqimap_messages_flag ($imap_stream, $start, $end, "Deleted");
-    } else {
-        sqimap_messages_flag ($imap_stream, $start, $end, "Deleted");
     }
+    sqimap_messages_flag ($imap_stream, $start, $end, "Deleted");
 }
 
-/****************************************************************************
- **  Sets the specified messages with specified flag
- ****************************************************************************/
+/* Sets the specified messages with specified flag */
 function sqimap_messages_flag ($imap_stream, $start, $end, $flag) {
     $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", true, $response, $message);
 }
 
-
-/****************************************************************************
- **  Remove specified flag from specified messages
- ****************************************************************************/
+/* Remove specified flag from specified messages */
 function sqimap_messages_remove_flag ($imap_stream, $start, $end, $flag) {
     $read = sqimap_run_command ($imap_stream, "STORE $start:$end -FLAGS (\\$flag)", true, $response, $message);
 }
 
-
-/****************************************************************************
- **  Returns some general header information -- FROM, DATE, and SUBJECT
- ****************************************************************************/
+/* Returns some general header information -- FROM, DATE, and SUBJECT */
 class small_header {
     var $from = '', $subject = '', $date = '', $to = '', 
         $priority = 0, $message_id = 0, $cc = '';
@@ -60,8 +46,9 @@ function sqimap_get_small_header ($imap_stream, $id, $sent) {
     $res = sqimap_get_small_header_list($imap_stream, array($id), $sent);
     return $res[0];
 }
-   
-/* Sort the message list and crunch to be as small as possible
+
+/*
+ * Sort the message list and crunch to be as small as possible
  * (overflow could happen, so make it small if possible)
  */
 function sqimap_message_list_squisher($messages_array) {
@@ -84,9 +71,9 @@ function sqimap_message_list_squisher($messages_array) {
             $msgs_str .= ':' . $end;
         }
     }
-      
+
     return $msgs_str;
-}   
+}
 
 function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
     global $squirrelmail_language, $color, $data_dir, $username;
@@ -99,7 +86,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
     $read_list = array();
     $sizes_list = array();
 
-    /**
+    /*
      * We need to return the data in the same order as the caller supplied
      * in $msg_list, but IMAP servers are free to return responses in
      * whatever order they wish... So we need to re-sort manually
@@ -120,7 +107,6 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
                   '</b><br>' .
                   _("Unknown response from IMAP server: ") . ' 1.' .
                   $r[0] . "</font><br>\n";
-             /* exit; */
         } else if (! isset($id2index[$regs[1]]) || !count($id2index[$regs[1]])) {
              set_up_language($squirrelmail_language);
              echo '<br><b><font color=$color[2]>' .
@@ -128,17 +114,16 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
                   '</b><br>' .
                   _("Unknown message number in reply from server: ") .
                   $regs[1] . "</font><br>\n";
-             /* exit */
         } else {
              $read_list[$id2index[$regs[1]]] = $r;
         }
     }
     arsort($read_list);
-      
+
     $query = "$sid FETCH $msgs_str RFC822.SIZE\r\n";
     fputs ($imap_stream, $query);
     $sizesin_list = sqimap_read_data_list($imap_stream, $sid, true, $response, $message);
-      
+
     foreach ($sizesin_list as $r) {
         if (!eregi("^\\* ([0-9]+) FETCH", $r[0], $regs)) {
             set_up_language($squirrelmail_language);
@@ -161,7 +146,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
         $sizes_list[$id2index[$regs[1]]] = $r;
     }
     arsort($sizes_list);
-      
+
     for ($msgi = 0; $msgi < $maxmsg; $msgi++) {
         $subject = _("(no subject)");
         $from = _("Unknown Sender");
@@ -174,52 +159,50 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
         $type[1] = "";
         $read = $read_list[$msgi];
 
-        for ($i = 0; $i < count($read); $i++) {
-            if (eregi ("^to:(.*)$", $read[$i], $regs)) {
-                /*$to = sqimap_find_displayable_name(substr($read[$i], 3));*/
+        foreach ($read as $read_part) {
+            if (eregi ("^to:(.*)$", $read_part, $regs)) {
                 $to = $regs[1];
-            } else if (eregi ("^from:(.*)$", $read[$i], $regs)) {
-                /*$from = sqimap_find_displayable_name(substr($read[$i], 5));*/
+            } else if (eregi ("^from:(.*)$", $read_part, $regs)) {
                 $from = $regs[1];
-            } else if (eregi ("^x-priority:(.*)$", $read[$i], $regs)) {
+            } else if (eregi ("^x-priority:(.*)$", $read_part, $regs)) {
                 $priority = trim($regs[1]);
-            } else if (eregi ("^message-id:(.*)$", $read[$i], $regs)) {
+            } else if (eregi ("^message-id:(.*)$", $read_part, $regs)) {
                 $messageid = trim($regs[1]);
-            } else if (eregi ("^cc:(.*)$", $read[$i], $regs)) {
+            } else if (eregi ("^cc:(.*)$", $read_part, $regs)) {
                 $cc = $regs[1];
-            } else if (eregi ("^date:(.*)$", $read[$i], $regs)) {
+            } else if (eregi ("^date:(.*)$", $read_part, $regs)) {
                 $date = $regs[1];
-            } else if (eregi ("^subject:(.*)$", $read[$i], $regs)) {
+            } else if (eregi ("^subject:(.*)$", $read_part, $regs)) {
                 $subject = htmlspecialchars(trim($regs[1]));
                 if ($subject == "") {
                     $subject = _("(no subject)");
                 }
-            } else if (eregi ("^content-type:(.*)$", $read[$i], $regs)) {
+            } else if (eregi ("^content-type:(.*)$", $read_part, $regs)) {
                 $type = strtolower(trim($regs[1]));
                 if ($pos = strpos($type, ";")) {
                     $type = substr($type, 0, $pos);
                 }
                 $type = explode("/", $type);
-                if (! isset($type[1])) {
+                if (!isset($type[1])) {
                     $type[1] = '';
                 }
             }
         }
-       $internaldate = getPref($data_dir, $username, 'internal_date_sort');
+        $internaldate = getPref($data_dir, $username, 'internal_date_sort');
         if (trim($date) == "" || $internaldate) {
             fputs($imap_stream, "$sid FETCH $msg_list[$msgi] INTERNALDATE\r\n");
             $readdate = sqimap_read_data($imap_stream, $sid, true, $response, $message);
             if (eregi(".*INTERNALDATE \"(.*)\".*", $readdate[0], $regs)) {
-                $date_list = explode(" ", trim($regs[1]));
-                $date_list[0] = str_replace("-", " ", $date_list[0]);
-                $date = implode(" ", $date_list);
+                $date_list = explode(' ', trim($regs[1]));
+                $date_list[0] = str_replace("-", ' ', $date_list[0]);
+                $date = implode(' ', $date_list);
             }
         }
         eregi("([0-9]+)[^0-9]*$", $sizes_list[$msgi][0], $regs);
         $size = $regs[1];
-         
+
         $header = new small_header;
-        if ($issent == true) {
+        if ($issent) {
             $header->from = (trim($to) != '' ? $to : '(' ._("No To Address") . ')');
         } else {
             $header->from = $from;
@@ -240,15 +223,13 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
     return $result;
 }
 
-/****************************************************************************
- **  Returns the flags for the specified messages 
- ****************************************************************************/
+/* Returns the flags for the specified messages */
 function sqimap_get_flags ($imap_stream, $i) {
     $read = sqimap_run_command ($imap_stream, "FETCH $i:$i FLAGS", true, $response, $message);
-    if (ereg("FLAGS(.*)", $read[0], $regs)) {
+    if (ereg('FLAGS(.*)', $read[0], $regs)) {
         return explode(' ', trim(ereg_replace('[\\(\\)\\\\]', '', $regs[1])));
     }
-    return Array('None');
+    return array('None');
 }
 
 function sqimap_get_flags_list ($imap_stream, $msg_list) {
@@ -260,7 +241,7 @@ function sqimap_get_flags_list ($imap_stream, $msg_list) {
     $result_flags = array();
 
     for ($i = 0; $i < sizeof($result_list); $i++) {
-        if (eregi("^\\* ([0-9]+).*FETCH.*FLAGS(.*)", $result_list[$i][0], $regs)
+        if (eregi('^\* ([0-9]+).*FETCH.*FLAGS(.*)', $result_list[$i][0], $regs)
           && isset($id2index[$regs[1]]) && count($id2index[$regs[1]])) {
             $result_flags[$id2index[$regs[1]]] = explode(" ", trim(ereg_replace('[\\(\\)\\\\]', '', $regs[2])));
         } else {
@@ -277,31 +258,25 @@ function sqimap_get_flags_list ($imap_stream, $msg_list) {
     return $result_flags;
 }
 
-/****************************************************************************
- **  Returns a message array with all the information about a message.  See
- * the documentation folder for more information about this array.
- ****************************************************************************/
+/*
+ * Returns a message array with all the information about a message.  
+ * See the documentation folder for more information about this array.
+ */
 function sqimap_get_message ($imap_stream, $id, $mailbox) {
     $header = sqimap_get_message_header($imap_stream, $id, $mailbox);
     return sqimap_get_message_body($imap_stream, $header);
 }
 
-/****************************************************************************
- **  Wrapper function that reformats the header information.
- ****************************************************************************/
+/* Wrapper function that reformats the header information. */
 function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
     $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[HEADER]", true, $response, $message);
-     
     $header = sqimap_get_header($imap_stream, $read); 
     $header->id = $id;
     $header->mailbox = $mailbox;
-
     return $header;
 }
 
-/****************************************************************************
- **  Wrapper function that reformats the entity header information.
- ****************************************************************************/
+/* Wrapper function that reformats the entity header information. */
 function sqimap_get_ent_header ($imap_stream, $id, $mailbox, $ent) {
     $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[$ent.HEADER]", true, $response, $message);
     $header = sqimap_get_header($imap_stream, $read); 
@@ -311,9 +286,7 @@ function sqimap_get_ent_header ($imap_stream, $id, $mailbox, $ent) {
 }
 
 
-/****************************************************************************
- **  Wrapper function that returns entity headers for use by decodeMime
- ****************************************************************************/
+/* Wrapper function that returns entity headers for use by decodeMime */
 /*
 function sqimap_get_entity_header ($imap_stream, &$read, &$type0, &$type1, &$bound, &$encoding, &$charset, &$filename) {
     $header = sqimap_get_header($imap_stream, $read);
@@ -325,15 +298,13 @@ function sqimap_get_entity_header ($imap_stream, &$read, &$type0, &$type1, &$bou
     $filename = $header["FILENAME"];
 }
 */
-
-/****************************************************************************
- **  Queries the IMAP server and gets all header information.
- ****************************************************************************/
+/* Queries the IMAP server and gets all header information. */
 function sqimap_get_header ($imap_stream, $read) {
     global $where, $what;
 
     $hdr = new msg_header();
     $i = 0;
+
     /* Set up some defaults */
     $hdr->type0 = "text";
     $hdr->type1 = "plain";
@@ -344,21 +315,18 @@ function sqimap_get_header ($imap_stream, $read) {
             $hdr->mime = true;
             $i++;
         }
-
-        /** ENCODING TYPE **/
+        /* ENCODING TYPE */
         else if (substr(strtolower($read[$i]), 0, 26) == "content-transfer-encoding:") {
             $hdr->encoding = strtolower(trim(substr($read[$i], 26)));
             $i++;
         }
-
-         /** CONTENT-TYPE **/
-         else if (strtolower(substr($read[$i], 0, 13)) == "content-type:") {
+        /* CONTENT-TYPE */
+        else if (strtolower(substr($read[$i], 0, 13)) == "content-type:") {
             $cont = strtolower(trim(substr($read[$i], 13)));
             if (strpos($cont, ";")) {
                 $cont = substr($cont, 0, strpos($cont, ";"));
             }
 
-
             if (strpos($cont, "/")) {
                 $hdr->type0 = substr($cont, 0, strpos($cont, "/"));
                 $hdr->type1 = substr($cont, strpos($cont, "/")+1);
@@ -366,7 +334,6 @@ function sqimap_get_header ($imap_stream, $read) {
                 $hdr->type0 = $cont;
             }
 
-
             $line = $read[$i];
             $i++;
             while ( (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":") && (trim($read[$i]) != "") && (trim($read[$i]) != ")")) {
@@ -376,12 +343,12 @@ function sqimap_get_header ($imap_stream, $read) {
                 $i++;
             }
 
-            /** Detect the boundary of a multipart message **/
+            /* Detect the boundary of a multipart message */
             if (eregi('boundary="([^"]+)"', $line, $regs)) {
                 $hdr->boundary = $regs[1];
             }
 
-            /** Detect the charset **/
+            /* Detect the charset */
             if (strpos(strtolower(trim($line)), "charset=")) {
                 $pos = strpos($line, "charset=") + 8;
                 $charset = trim($line);
@@ -396,10 +363,8 @@ function sqimap_get_header ($imap_stream, $read) {
                 $hdr->charset = "us-ascii";
             }
         }
-
         else if (strtolower(substr($read[$i], 0, 20)) == "content-disposition:") {
-            /** Add better dontent-disposition support **/
-            
+            /* Add better content-disposition support */
             $line = $read[$i];
             $i++;
             while ( (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":") && (trim($read[$i]) != "") && (trim($read[$i]) != ")")) {
@@ -409,27 +374,25 @@ function sqimap_get_header ($imap_stream, $read) {
                 $i++;
             }
 
-            /** Detects filename if any **/
+            /* Detects filename if any */
             if (strpos(strtolower(trim($line)), "filename=")) {
                 $pos = strpos($line, "filename=") + 9;
                 $name = trim($line);
                 if (strpos($line, " ", $pos) > 0) {
-                   $name = substr($name, $pos, strpos($line, " ", $pos));
+                    $name = substr($name, $pos, strpos($line, " ", $pos));
                 } else {
-                   $name = substr($name, $pos);
+                    $name = substr($name, $pos);
                 }
                 $name = str_replace("\"", "", $name);
                 $hdr->filename = $name;
             }
         }
-
-        /** REPLY-TO **/
+        /* REPLY-TO */
         else if (strtolower(substr($read[$i], 0, 9)) == "reply-to:") {
             $hdr->replyto = trim(substr($read[$i], 9, strlen($read[$i])));
             $i++;
         }
-
-        /** FROM **/
+        /* FROM */
         else if (strtolower(substr($read[$i], 0, 5)) == "from:") {
             $hdr->from = trim(substr($read[$i], 5, strlen($read[$i]) - 6));
             if (! isset($hdr->replyto) || $hdr->replyto == "") {
@@ -437,7 +400,7 @@ function sqimap_get_header ($imap_stream, $read) {
             }
             $i++;
         }
-        /** DATE **/
+        /* DATE */
         else if (strtolower(substr($read[$i], 0, 5)) == "date:") {
             $d = substr($read[$i], 5);
             $d = trim($d);
@@ -446,23 +409,21 @@ function sqimap_get_header ($imap_stream, $read) {
             $hdr->date = getTimeStamp($d);
             $i++;
         }
-        /** SUBJECT **/
+        /* SUBJECT */
         else if (strtolower(substr($read[$i], 0, 8)) == "subject:") {
             $hdr->subject = trim(substr($read[$i], 8, strlen($read[$i]) - 9));
             if (strlen(Chop($hdr->subject)) == 0) {
                $hdr->subject = _("(no subject)");
             }
-            
-            /*  
+            /*
             if ($where == 'SUBJECT') {
                  $hdr->subject = $what;
                  // $hdr->subject = eregi_replace($what, "<b>\\0</b>", $hdr->subject);
             }
             */
-            
             $i++;
         }
-        /** CC **/
+        /* CC */
         else if (strtolower(substr($read[$i], 0, 3)) == "cc:") {
             $pos = 0;
             $hdr->cc[$pos] = trim(substr($read[$i], 4));
@@ -473,7 +434,7 @@ function sqimap_get_header ($imap_stream, $read) {
                 $i++;
             }
         }
-        /** BCC **/
+        /* BCC */
         else if (strtolower(substr($read[$i], 0, 4)) == "bcc:") {
             $pos = 0;
             $hdr->bcc[$pos] = trim(substr($read[$i], 5));
@@ -484,7 +445,7 @@ function sqimap_get_header ($imap_stream, $read) {
                 $i++;
             }
         }
-        /** TO **/
+        /* TO */
         else if (strtolower(substr($read[$i], 0, 3)) == "to:") {
             $pos = 0;
             $hdr->to[$pos] = trim(substr($read[$i], 4));
@@ -495,14 +456,12 @@ function sqimap_get_header ($imap_stream, $read) {
                 $i++;
             }
         }
-        /** MESSAGE ID **/
+        /* MESSAGE ID */
         else if (strtolower(substr($read[$i], 0, 11)) == "message-id:") {
             $hdr->message_id = trim(substr($read[$i], 11));
             $i++;
         }
-
-
-        /** ERROR CORRECTION **/
+        /* ERROR CORRECTION */
         else if (substr($read[$i], 0, 1) == ")") {
             if (strlen(trim($hdr->subject)) == 0) {
                 $hdr->subject = _("(no subject)");
@@ -515,7 +474,7 @@ function sqimap_get_header ($imap_stream, $read) {
             }
             $i++;
         }
-        /** X-PRIORITY **/
+        /* X-PRIORITY */
         else if (strtolower(substr($read[$i], 0, 11)) == "x-priority:") {
             $hdr->priority = trim(substr($read[$i], 11));
             $i++;
@@ -527,17 +486,10 @@ function sqimap_get_header ($imap_stream, $read) {
      return $hdr;
 }
 
-
-/****************************************************************************
- **  Returns the body of a message.
- ****************************************************************************/
+/* Returns the body of a message. */
 function sqimap_get_message_body ($imap_stream, &$header) {
     $id = $header->id;
     return decodeMime($imap_stream, $header);
 }
 
-
-/****************************************************************************
- **  Returns an array with the body structure 
- ****************************************************************************/
 ?>