From 5b6ae78a9e6c22ae203ba70136346ec2a6d365d0 Mon Sep 17 00:00:00 2001 From: lkehresman Date: Fri, 14 Apr 2000 01:15:43 +0000 Subject: [PATCH] added many speed improvements git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@421 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- config/conf.pl | 806 +++++++--------------------------- functions/array.php | 13 + functions/imap_mailbox.php | 542 ++++++++++++----------- functions/mailbox_display.php | 178 ++++---- 4 files changed, 522 insertions(+), 1017 deletions(-) diff --git a/config/conf.pl b/config/conf.pl index 5b013bf9..b833be74 100755 --- a/config/conf.pl +++ b/config/conf.pl @@ -4,10 +4,11 @@ # Luke Ehresman (lehresma@css.tayloru.edu) # # A simple configure script to configure squirrelmail -############################################################ +############################################################ $WHT = "\x1B[37;1m"; $NRM = "\x1B[0m"; +system "clear"; print "\n\n--------------------------------------------------------\n"; print "SquirrelMail version 0.4 -- Configure script\n"; print "by SquirrelMail Development Team\n"; @@ -15,682 +16,173 @@ print "http://squirrelmail.sourceforge.net\n"; print "--------------------------------------------------------\n"; print "\n"; -############################################################ +############################################################ # First, lets read in the data already in there... -############################################################ +############################################################ if ( -e "config.php") { - print "The file \"config.php\" exists. Using it for defaults.\n\n"; - open (FILE, "config.php"); + print "The file \"config.php\" exists. Using it for defaults.\n\n"; + open (FILE, "config.php"); } else { - print "No config file found. Reading from config_defaults.php.\n\n"; - open (FILE, "config_default.php"); + print "No config file found. Reading from config_defaults.php.\n\n"; + open (FILE, "config_default.php"); } # Reads and parses the current configuration file (either # config.php or config_default.php). while ($line = ) { - if ($line =~ /^\s+\$/) { - $line =~ s/^\s+\$//; - $var = $line; - - if ($var =~ /^([a-z]|[A-Z])/) { - @options = split(/\s=\s/, $var); - $options[1] =~ s/[\n|\r]//g; - $options[1] =~ s/^"//g; - $options[1] =~ s/;.*$//g; - $options[1] =~ s/"$//g; - - if ($options[0] =~ /^special_folders/) { - if ($options[0] =~ /\[.*\]$/) { - $sub = $options[0]; - $sub =~ s/\]$//; - $sub = substr ($sub, @sub-1, 1); - - $special_folders[$sub] = $options[1]; - } - } elsif ($options[0] =~ /^theme\[[0-9]+\]\["PATH"\]/) { - $sub = $options[0]; - $sub =~ s/\]\["PATH"\]//; - $sub = substr ($sub, @sub-1, 1); - $theme_path[$sub] = $options[1]; - } elsif ($options[0] =~ /^theme\[[0-9]+\]\["NAME"\]/) { - $sub = $options[0]; - $sub =~ s/\]\["NAME"\]//; - $sub = substr ($sub, @sub-1, 1); - $theme_name[$sub] = $options[1]; - } else { - ${$options[0]} = $options[1]; - } - } - } + if ($line =~ /^\s+\$/) { + $line =~ s/^\s+\$//; + $var = $line; + + if ($var =~ /^([a-z]|[A-Z])/) { + @options = split(/\s=\s/, $var); + $options[1] =~ s/[\n|\r]//g; + $options[1] =~ s/^"//g; + $options[1] =~ s/;.*$//g; + $options[1] =~ s/"$//g; + + if ($options[0] =~ /^special_folders/) { + if ($options[0] =~ /\[.*\]$/) { + $sub = $options[0]; + $sub =~ s/\]$//; + $sub = substr ($sub, @sub-1, 1); + + $special_folders[$sub] = $options[1]; + } + } elsif ($options[0] =~ /^theme\[[0-9]+\]\["PATH"\]/) { + $sub = $options[0]; + $sub =~ s/\]\["PATH"\]//; + $sub = substr ($sub, @sub-1, 1); + $theme_path[$sub] = $options[1]; + } elsif ($options[0] =~ /^theme\[[0-9]+\]\["NAME"\]/) { + $sub = $options[0]; + $sub =~ s/\]\["NAME"\]//; + $sub = substr ($sub, @sub-1, 1); + $theme_name[$sub] = $options[1]; + } else { + ${$options[0]} = $options[1]; + } + } + } } open (FILE, ">cf.php"); print FILE "; -if ($new_org_name eq "\n") { - $new_org_name = $org_name; -} else { - $new_org_name =~ s/[\r|\n]//g; -} -print FILE " ".'$org_name = "' . $new_org_name . "\";\n"; - - - -############################################################ -# Organization Logo -############################################################ -print $WHT."Where is the logo for your organization [$org_logo]: $NRM"; -$new_org_logo = ; -if ($new_org_logo eq "\n") { - $new_org_logo = $org_logo; -} else { - $new_org_logo =~ s/[\r|\n]//g; -} -print FILE " ".'$org_logo = "' . $new_org_logo . "\";\n"; - - - - -############################################################ -# Organization Title -############################################################ -print "The title of the web page [$org_title]: "; -$new_org_title = ; -if ($new_org_title eq "\n") { - $new_org_title = $org_title; -} else { - $new_org_title =~ s/[\r|\n]//g; -} -print FILE " ".'$org_title = "' . $new_org_title . "\";\n"; - - - -print "\n-------------------------------------------------.\n"; -print " Server Information )\n"; -print "-------------------------------------------------'\n"; -############################################################ -# IMAP Server -############################################################ -print "Where is the IMAP server [$imapServerAddress]: "; -$new_imapServerAddress = ; -if ($new_imapServerAddress eq "\n") { - $new_imapServerAddress = $imapServerAddress; -} else { - $new_imapServerAddress =~ s/[\r|\n]//g; -} -print FILE " ".'$imapServerAddress = "' . $new_imapServerAddress . "\";\n"; - - - -############################################################ -# IMAP Port -############################################################ -print "The port for your IMAP server [$imapPort]: "; -$new_imapPort = ; -if ($new_imapPort eq "\n") { - $new_imapPort = $imapPort; -} else { - $new_imapPort =~ s/[\r|\n]//g; -} -print FILE " ".'$imapPort = ' . $new_imapPort . ";\n"; - - -############################################################ -# DOMAIN -############################################################ -print "What is your domain name (ex: usa.om.org) [$domain]: "; -$new_domain = ; -if ($new_domain eq "\n") { - $new_domain = $domain; -} else { - $new_domain =~ s/[\r|\n]//g; -} -print FILE " ".'$domain = "' . $new_domain . "\";\n"; - -############################################################ -# USE SMTP OR SENDMAIL? -############################################################ -print "\nYou now need to choose the method that you will use for sending\n"; -print "messages in SquirrelMail. You can either connect to an SMTP server\n"; -print "or use sendmail directly.\n"; -if ($useSendmail eq "true") { - $default_value = "n"; -} else { - $default_value = "y"; -} -print "Use SMTP (y/n) [$default_value]: "; -$use_smtp = ; -if (($use_smtp =~ /^y\n/i) || (($use_smtp =~ /^\n/) && ($default_value eq "y"))) { - ############################################################ - # SMTP Server - ############################################################ - print " What is the SMTP server [$smtpServerAddress]: "; - $new_smtpServerAddress = ; - if ($new_smtpServerAddress eq "\n") { - $new_smtpServerAddress = $smtpServerAddress; +##################################################################################### + +# org_name +sub command1 { + print "We have tried to make the name SquirrelMail as transparent as\n"; + print "possible. If you set up an organization name, most places where\n"; + print "SquirrelMail would take credit will be credited to your organization.\n"; + print "\n"; + print "What is the name of your organization [$org_name]: "; + $new_org_name = ; + if ($new_org_name eq "\n") { + $new_org_name = $org_name; + } else { + $new_org_name =~ s/[\r|\n]//g; + } + return $new_org_name; +} + +# org_logo +sub command2 { + print "Your organization's logo is an image that will be displayed at\n"; + print "different times throughout SquirrelMail. This is asking for the\n"; + print "literal (/usr/local/squirrelmail/images/logo.jpg) or relative\n"; + print "(../images/logo.jpg) path to your logo.\n"; + print "\n"; + print "Where is the logo for your organization [$org_logo]: "; + $new_org_logo = ; + if ($new_org_logo eq "\n") { + $new_org_logo = $org_logo; } else { - $new_smtpServerAddress =~ s/[\r|\n]//g; + $new_org_logo =~ s/[\r|\n]//g; } - print FILE " ".'$smtpServerAddress = "' . $new_smtpServerAddress . "\";\n"; - - - - ############################################################ - # SMTP Port - ############################################################ - print " The port for your SMTP server [$smtpPort]: "; - $new_smtpPort = ; - if ($new_smtpPort eq "\n") { - $new_smtpPort = $smtpPort; + return $new_org_logo; +} + +# org_title +sub command3 { + print "A title is what is displayed at the top of the browser window in\n"; + print "the titlebar. Usually this will end up looking something like:\n"; + print "\"Netscape: $org_title\"\n"; + print "\n"; + print "The title of the web page [$org_title]: "; + $new_org_title = ; + if ($new_org_title eq "\n") { + $new_org_title = $org_title; } else { - $new_smtpPort =~ s/[\r|\n]//g; - } - print FILE " ".'$smtpPort = ' . $new_smtpPort . ";\n"; -} else { - ############################################################ - # Sendmail Path - ############################################################ - if ($sendmail_path[0] !~ /./) { - $sendmail_path = "/usr/sbin/sendmail"; + $new_org_title =~ s/[\r|\n]//g; } - print " Where is sendmail located [$sendmail_path]: "; - $new_sendmail_path = ; - if ($new_sendmail_path eq "\n") { - $new_sendmail_path = $sendmail_path; + return $new_org_title; +} + +# domain +sub command10 { + print "The domain is what is on the right side of the \@ in the email\n"; + print "address. If your address is somebody\@somewhere.com, then your\n"; + print "domain would be \"somewhere.com\".\n"; + print "\n"; + print "Your domain [$WHT$domain$NRM]: ".$WHT; + $new_domain = ; + if ($new_domain eq "\n") { + $new_domain = $domain; } else { - $new_sendmail_path =~ s/[\r|\n]//g; + $new_domain =~ s/[\r|\n]//g; } - print FILE " ".'$useSendmail'." = true;\n"; - print FILE " ".'$sendmail_path = "' . $new_sendmail_path . "\";\n"; -} - - - -print "\n-------------------------------------------------.\n"; -print " General Options )\n"; -print "-------------------------------------------------'\n"; -############################################################### -# MOTD -############################################################### -print "\nYou can now create the welcome message that is displayed\n"; -print "every time a user logs on. You can use HTML or just plain\n"; -print "text.\n\n(Type @ on a blank line to exit)\n"; -do { - print "] "; - $line = ; - $line =~ s/[\r|\n]//g; - $line =~ s/ /\ \ /g; - if ($line ne "@") { - $new_motd = $new_motd . $line; - } -} while ($line ne "@"); -print FILE " ".'$motd = "'.$new_motd."\";\n"; - - -############################################################ -# AUTO EXPUNGE -############################################################ -if ($auto_expunge eq "false") { - $default_value = "n"; -} else { - $default_value = "y"; -} -print "Should we automatically expunge deleted messages (y/n) [$default_value]: "; -$autoe = ; -if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) { - print FILE " \$auto_expunge = true;\n"; -} else { - print FILE " \$auto_expunge = false;\n"; + return $new_domain; +} + +##################################################################################### + +while (($command ne "q") && ($command ne "Q")) { + system "clear"; + print $WHT."General Information --\n".$NRM; + print "1 Name of organization : $WHT$org_name$NRM\n"; + print "2 Where is your logo : $WHT$org_logo$NRM\n"; + print "3 Title of web page : $WHT$org_title$NRM\n"; + print "\n"; + print $WHT."Server Information --\n".$NRM; + print "10 Domain : $WHT$domain$NRM\n"; + print "11 IMAP server : \n"; + print "12 IMAP port : \n"; + print "13 Use Sendmail? : \n"; + if (@vars[4] eq "true") { + print "14 Sendmail path : \n"; + } else { + print "15 SMTP server : \n"; + print "16 SMTP port : \n"; + } + print "\n"; + print $WHT."General Options --\n".$NRM; + print "20 Welcome message\n"; + print "21 Auto expunge : @vars[10]\n"; + print "22 Fodlers sub of INBOX : @vars[11]\n"; + print "\n"; + print "x Exit without saving\n"; + print "q Save and exit\n"; + print "\n"; + print "Command: "; + + $command = ; + $command =~ s/[\n|\r]//g; + + print "\n"; + + if ($command eq "1" ) { $org_name = command1 (); } + elsif ($command eq "2" ) { $org_logo = command2 (); } + elsif ($command eq "3" ) { $org_title = command3 (); } + + elsif ($command eq "10") { $domain = command10 (); } + elsif ($command eq "11") { $imapServerAddress = command11 (); } + elsif ($command eq "12") { $imapPort = command12 (); } + elsif ($command eq "13") { $use_sendmail = command3 (); } + elsif ($command eq "14") { $org_title = command3 (); } + elsif ($command eq "15") { $org_title = command3 (); } } - - -############################################################ -# default_sub_of_inbox -############################################################ -if ($default_sub_of_inbox eq "false") { - $default_value = "n"; -} else { - $default_value = "y"; -} -print "By default, are new folders subfolders of INBOX (y/n) [$default_value]: "; -$autoe = ; -if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) { - print FILE " \$default_sub_of_inbox = true;\n"; -} else { - print FILE " \$default_sub_of_inbox = false;\n"; -} - - - - -############################################################ -# show_contain_subfolders_option -############################################################ -print "\nSome IMAP daemons (UW) handle folders weird. They only allow a\n"; -print "folder to contain either messages or subfolders. Not both at the\n"; -print "same time. This option controls whether or not to display an \n"; -print "option during folder creation letting them choose if this folder\n"; -print "contains messages or folders.\n"; -if ($show_contain_subfolders_option eq "false") { - $default_value = "n"; -} else { - $default_value = "y"; -} -print "Show the option to contain subfolders (y/n) [$default_value]: "; -$autoe = ; -if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) { - print FILE " \$show_contain_subfolders_option = true;\n"; -} else { - print FILE " \$show_contain_subfolders_option = false;\n"; -} - - - - - -############################################################ -# auto_forward -############################################################ -print "\nThis option decides whether or not to use META tags to forward\n"; -print "users past some of the notification screens\n"; -if ($auto_forward eq "false") { - $default_value = "n"; -} else { - $default_value = "y"; -} -print "Automatically forward where possible (y/n) [$default_value]: "; -$autoe = ; -if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) { - print FILE " \$auto_forward = true;\n"; -} else { - print FILE " \$auto_forward = false;\n"; -} - - - - -############################################################ -# DEFAULT CHARSET -############################################################ -print "\nThis option controls what character set is used when sending mail\n"; -print "and when sending HTMl to the browser. Do not set this to US-ASCII,\n"; -print "use ISO-8859-1 instead. For cyrillic it is best to use KOI8-R,\n"; -print "since this implementation is faster than the alternatives.\n"; -print "Default charset [$default_charset]: "; -$new_default_charset = ; -if ($new_default_charset eq "\n") { - $new_default_charset = $default_charset; -} else { - $new_default_charset =~ s/[\r|\n]//g; -} -print FILE " ".'$default_charset = "' . $new_default_charset . "\";\n"; - - - - -############################################################ -# DATA DIRECTORY -############################################################ -print "\nIt is a possible security hole to have a writable directory\n"; -print "under the web server's root directory (ex: /home/httpd/html).\n"; -print "For this reason, it is possible to put the data directory\n"; -print "anywhere you would like. The path name can be absolute or\n"; -print "relative (to the config directory). It doesn't matter. Here are\n"; -print "two examples:\n"; -print " Absolute:\n"; -print " /usr/local/squirrelmail/data/;\n"; -print " Relative (to the config directory):\n"; -print " ../data/;\n"; -print "Where is the data directory [$data_dir]: "; -$new_data_dir = ; -if ($new_data_dir eq "\n") { - $new_data_dir = $data_dir; -} else { - $new_data_dir =~ s/[\r|\n]//g; -} -print FILE " ".'$data_dir = "' . $new_data_dir . "\";\n"; - - - - -############################################################ -# ATTACHMENT DIRECTORY -############################################################ -print "\nPath to directory used for storing attachments while a mail is\n"; -print "being sent. There are a few security considerations regarding this\n"; -print "directory:\n"; -print " - It should have the permission 733 (rwx-wx-wx) to make it\n"; -print " impossible for a random person with access to the webserver to\n"; -print " list files in this directory. Confidential data might be laying\n"; -print " around there\n"; -print " - Since the webserver is not able to list the files in the content\n"; -print " is also impossible for the webserver to delete files lying around\n"; -print " there for too long.\n"; -print " - It should probably be another directory than data_dir.\n"; -print "Where is the attachment directory [$attachment_dir]: "; -$new_attachment_dir = ; -if ($new_attachment_dir eq "\n") { - $new_attachment_dir = $attachment_dir; -} else { - $new_attachment_dir =~ s/[\r|\n]//g; -} -print FILE " ".'$attachment_dir = "' . $new_attachment_dir . "\";\n"; - - - - -############################################################ -# DEFAULT LEFT SIZE -############################################################ -print "What is the default left folder list size (pixels) [$default_left_size]: "; -$new_default_left_size = ; -if ($new_default_left_size eq "\n") { - $new_default_left_size = $default_left_size; -} else { - $new_default_left_size =~ s/[\r|\n]//g; -} -print FILE " ".'$default_left_size = "' . $new_default_left_size . "\";\n"; - - - - - - - -print "\n-------------------------------------------------.\n"; -print " Special Folders )\n"; -print "-------------------------------------------------'\n"; - -############################################################ -# Trash folder -############################################################ -print "What is the default trash folder [$trash_folder]: "; -$new_trash_folder = ; -if ($new_trash_folder eq "\n") { - $new_trash_folder = $trash_folder; -} else { - $new_trash_folder =~ s/[\r|\n]//g; -} -print FILE " ".'$trash_folder = "' . $new_trash_folder . "\";\n"; - - - -############################################################ -# Default move to trash -############################################################ -if ($default_move_to_trash eq "true") { - $default_value = "y"; -} else { - $default_value = "n"; -} -print "By default, should deleted messages be moved to $new_trash_folder (y/n) [$default_value]: "; -$move_trash = ; -if (($move_trash =~ /^y\n/i) || (($move_trash =~ /^\n/) && ($default_value eq "y"))) { - print FILE " \$default_move_to_trash = true;\n"; -} else { - print FILE " \$default_move_to_trash = false;\n"; -} - - - -############################################################ -# Sent folder -############################################################ -print "What is the default sent folder [$sent_folder]: "; -$new_sent_folder = ; -if ($new_sent_folder eq "\n") { - $new_sent_folder = $sent_folder; -} else { - $new_sent_folder =~ s/[\r|\n]//g; -} -print FILE " ".'$sent_folder = "' . $new_sent_folder . "\";\n"; - - - - -############################################################ -# Special Folders -############################################################ -print "\nSpecial folders are folders that can't be manipulated like normal\n"; -print "user-created folders. A couple of examples of these would be the\n"; -print "trash folder, the sent folder, etc.\n"; -print "Special Folders:\n"; -$count = 0; -print "\n"; -while ($count < @special_folders) { - print " $count) " . $special_folders[$count] . "\n"; - $count++; -} -print "[folders] command (?=help) > "; -$input = ; -$input =~ s/[\r|\n]//g; -while ($input ne "d") { - ## ADD - if ($input =~ /^\s*\+\s*.*/) { - $input =~ s/^\s*\+\s*//; - $special_folders[$#special_folders+1] = $input; - } - - elsif ($input =~ /^\s*-\s*[0-9]?/) { - if ($input =~ /[0-9]+\s*$/) { - $rem_num = $input; - $rem_num =~ s/^\s*-\s*//g; - $rem_num =~ s/\s*$//; - } else { - $rem_num = $#special_folders; - } - - if ($rem_num == 0) { - print "You cannot remove INBOX. It is a very special folder.\n"; - } else { - $count = 0; - @new_special_folders = (); - while ($count <= $#special_folders) { - if ($count != $rem_num) { - @new_special_folders = (@new_special_folders, $special_folders[$count]); - } - $count++; - } - @special_folders = @new_special_folders; - } - } - - elsif ($input =~ /^\s*l\s*/) { - $count = 0; - print "\n"; - while ($count < @special_folders) { - print " $count) " . $special_folders[$count] . "\n"; - $count++; - } - } elsif ($input =~ /^\s*\?\s*/) { - print ".-------------------------.\n"; - print "| + Folder (add folder) |\n"; - print "| - N (remove folder) |\n"; - print "| l (list folders) |\n"; - print "| d (done) |\n"; - print "`-------------------------'\n"; - } - - else { - print "Unrecognized command.\n"; - } - - print "[folders] command (?=help) > "; - $input = ; - $input =~ s/[\r|\n]//g; -} - -$count = 0; -while ($count <= $#special_folders) { - print FILE " \$special_folders[$count] = \"$special_folders[$count]\";\n"; - $count++; -} - - -############################################################ -# Use special folder color -############################################################ -if ($use_special_folder_color eq "true") { - $default_value = "y"; -} else { - $default_value = "n"; -} -print "\nHighlight special folders in a different color (y/n) [$default_value]: "; -$use_spec_folder = ; -if (($use_spec_folder =~ /^y\n/i) || (($use_spec_folder =~ /^\n/) && ($default_value eq "y"))) { - print FILE " \$use_special_folder_color = true;\n"; -} else { - print FILE " \$use_special_folder_color = false;\n"; -} - - - - -############################################################ -# list_special_folders_first -############################################################ -if ($list_special_folders_first eq "false") { - $default_value = "n"; -} else { - $default_value = "y"; -} -print "Should special folders be listed first (y/n) [$default_value]: "; -$autoe = ; -if (($autoe =~ /^y\n/i) || (($autoe =~ /^\n/) && ($default_value eq "y"))) { - print FILE " \$list_special_folders_first = true;\n"; -} else { - print FILE " \$list_special_folders_first = false;\n"; -} - - - - -############################################################ -# Themes -############################################################ -print "\nNow we will define the themes that you wish to use. If you have added\n"; -print "a theme of your own, just follow the instructions (?) about how to add\n"; -print "them. You can also change the default theme.\n"; -print "[theme] command (?=help) > "; -$input = ; -$input =~ s/[\r|\n]//g; -$theme_default = 0; -while ($input ne "d") { - if ($input =~ /^\s*l\s*/i) { - $count = 0; - while ($count <= $#theme_name) { - if ($count == $theme_default) { - print " *"; - } else { - print " "; - } - $name = $theme_name[$count]; - $num_spaces = 25 - length($name); - for ($i = 0; $i < $num_spaces;$i++) { - $name = $name . " "; - } - - print " $count. $name"; - print "($theme_path[$count])\n"; - - $count++; - } - } elsif ($input =~ /^\s*m\s*[0-9]+/i) { - $old_def = $theme_default; - $theme_default = $input; - $theme_default =~ s/^\s*m\s*//; - if (($theme_default > $#theme_name) || ($theme_default < 0)) { - print "Cannot set default theme to $theme_default. That theme does not exist.\n"; - $theme_default = $old_def; - } - } elsif ($input =~ /^\s*\+/) { - print "What is the name of this theme: "; - $name = ; - $name =~ s/[\r|\n]//g; - $theme_name[$#theme_name+1] = $name; - print "Be sure to put ../config/ before the filename.\n"; - print "What file is this stored in (ex: ../config/default_theme.php): "; - $name = ; - $name =~ s/[\r|\n]//g; - $theme_path[$#theme_path+1] = $name; - } elsif ($input =~ /^\s*-\s*[0-9]?/) { - if ($input =~ /[0-9]+\s*$/) { - $rem_num = $input; - $rem_num =~ s/^\s*-\s*//g; - $rem_num =~ s/\s*$//; - } else { - $rem_num = $#theme_name; - } - if ($rem_num == $theme_default) { - print "You cannot remove the default theme!\n"; - } else { - $count = 0; - @new_theme_name = (); - @new_theme_path = (); - while ($count <= $#theme_name) { - if ($count != $rem_num) { - @new_theme_name = (@new_theme_name, $theme_name[$count]); - @new_theme_path = (@new_theme_path, $theme_path[$count]); - } - $count++; - } - @theme_name = @new_theme_name; - @theme_path = @new_theme_path; - if ($theme_default > $rem_num) { - $theme_default--; - } - } - } elsif ($input =~ /^\s*\?\s*/) { - print ".-------------------------.\n"; - print "| + (add theme) |\n"; - print "| - N (remove theme) |\n"; - print "| m N (mark default) |\n"; - print "| l (list themes) |\n"; - print "| d (done) |\n"; - print "`-------------------------'\n"; - } - print "[theme] command (?=help) > "; - $input = ; - $input =~ s/[\r|\n]//g; -} - -$count = 0; -print FILE " \$theme[0][\"NAME\"] = \"$theme_name[$theme_default]\";\n"; -print FILE " \$theme[0][\"PATH\"] = \"$theme_path[$theme_default]\";\n"; -$index = 1; -while ($count < $#theme_name) { - if ($count != $theme_default) { - print FILE " \$theme[$index][\"NAME\"] = \"$theme_name[$count]\";\n"; - print FILE " \$theme[$index][\"PATH\"] = \"$theme_path[$count]\";\n"; - $index++; - } - $count++; -} - -print FILE "\n?>\n"; -close FILE; - - -print "\n\nFINISHED!\n"; -print "All changes have been written to cf.php. If you would like, I can write\n"; -print "the changes to config.php.\n"; -print "Overwrite config.php (y/n) [y]: "; -$autoe = ; -if (($autoe =~ /^y\n/i) || ($autoe =~ /^\n/)) { - system "mv -f cf.php config.php"; -} - - diff --git a/functions/array.php b/functions/array.php index be81def2..9e83a195 100644 --- a/functions/array.php +++ b/functions/array.php @@ -51,4 +51,17 @@ return $newArray; } + + function array_cleave($array1, $column) + { + $key=0; + $array2 = array(); + while ($key < count($array1)) { + array_push($array2, $array1[$key]["$column"]); + $key++; + } + + return ($array2); + } + ?> diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index 5912c3f2..f7237ca5 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -1,263 +1,285 @@ diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 37168877..6cef9ec7 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -11,7 +11,6 @@ $mailbox_info = true; function printMessageInfo($imapConnection, $t, $msg, $mailbox, $sort, $startMessage) { - //require ("../config/config.php"); global $color; $senderName = $msg["FROM"]; @@ -34,122 +33,88 @@ /** ** This function loops through a group of messages in the mailbox and shows them **/ - function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, &$msgs) { + function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) { + global $msgs, $msort; include ("../config/config.php"); - if ($numMessages >= 1) { - for ($q = 0; $q < $numMessages; $q++) { - sqimap_get_small_header ($imapConnection, $q+1, $f, $s, $d); - $from[$q] = $f; - $date[$q] = $d; - $subject[$q] = $s; - $flags[$q] = sqimap_get_flags ($imapConnection, $q+1); - } - } - - $j = 0; - while ($j < $numMessages) { - $date[$j] = ereg_replace(" ", " ", $date[$j]); - $tmpdate = explode(" ", trim($date[$j])); - - $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate); - $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]); - $messages[$j]["ID"] = $j+1; - $messages[$j]["FROM"] = decodeHeader($from[$j]); - $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]); - - $num = 0; - while ($num < count($flags[$j])) { - if ($flags[$j][$num] == "Deleted") { - $messages[$j]["FLAG_DELETED"] = true; - } - else if ($flags[$j][$num] == "Answered") { - $messages[$j]["FLAG_ANSWERED"] = true; + if (!$use_cache) { + if ($numMessages >= 1) { + for ($q = 0; $q < $numMessages; $q++) { + sqimap_get_small_header ($imapConnection, $q+1, $f, $s, $d); + $from[$q] = $f; + $date[$q] = $d; + $subject[$q] = $s; + $flags[$q] = sqimap_get_flags ($imapConnection, $q+1); } - else if ($flags[$j][$num] == "Seen") { - $messages[$j]["FLAG_SEEN"] = true; - } - else if ($flags[$j][$num] == "Flagged") { - $messages[$j]["FLAG_FLAGGED"] = true; + } + + $j = 0; + while ($j < $numMessages) { + $date[$j] = ereg_replace(" ", " ", $date[$j]); + $tmpdate = explode(" ", trim($date[$j])); + + $messages[$j]["TIME_STAMP"] = getTimeStamp($tmpdate); + $messages[$j]["DATE_STRING"] = getDateString($messages[$j]["TIME_STAMP"]); + $messages[$j]["ID"] = $j+1; + $messages[$j]["FROM"] = decodeHeader($from[$j]); + $messages[$j]["SUBJECT"] = decodeHeader($subject[$j]); + + $num = 0; + while ($num < count($flags[$j])) { + if ($flags[$j][$num] == "Deleted") { + $messages[$j]["FLAG_DELETED"] = true; + } + else if ($flags[$j][$num] == "Answered") { + $messages[$j]["FLAG_ANSWERED"] = true; + } + else if ($flags[$j][$num] == "Seen") { + $messages[$j]["FLAG_SEEN"] = true; + } + else if ($flags[$j][$num] == "Flagged") { + $messages[$j]["FLAG_FLAGGED"] = true; + } + $num++; } - $num++; + $j++; } - $j++; - } - - /** Find and remove the ones that are deleted */ - $i = 0; - $j = 0; - while ($j < $numMessages) { - if ($messages[$j]["FLAG_DELETED"] == true) { + + /** Find and remove the ones that are deleted */ + $i = 0; + $j = 0; + while ($j < $numMessages) { + if ($messages[$j]["FLAG_DELETED"] == true) { + $j++; + continue; + } + $msgs[$i] = $messages[$j]; + + $i++; $j++; - continue; } - $msgs[$i] = $messages[$j]; - - $i++; - $j++; - } - - $numMessages = $i; + $numMessages = $i; + } // There's gotta be messages in the array for it to sort them. - if ($numMessages > 0) { + if (($numMessages > 0) && (!$use_cache)) { /** 0 = Date (up) 4 = Subject (up) ** 1 = Date (dn) 5 = Subject (dn) ** 2 = Name (up) ** 3 = Name (dn) **/ - if ($sort == 0) - $msgs = ary_sort($msgs, "TIME_STAMP", -1); - else if ($sort == 1) - $msgs = ary_sort($msgs, "TIME_STAMP", 1); - else { - - $original = $msgs; - $i = 0; - while ($i < count($msgs)) { - $msgs[$i]["FROM"] = strtolower($msgs[$i]["FROM"]); - $msgs[$i]["SUBJECT"] = strtolower($msgs[$i]["SUBJECT"]); - $i++; - } - - if ($sort == 2) - $msgs = ary_sort($msgs, "FROM", -1); - else if ($sort == 3) - $msgs = ary_sort($msgs, "FROM", 1); - else if ($sort == 4) - $msgs = ary_sort($msgs, "SUBJECT", -1); - else if ($sort == 5) - $msgs = ary_sort($msgs, "SUBJECT", 1); - else - $msgs = ary_sort($msgs, "TIME_STAMP", -1); - - $i = 0; - while ($i < count($msgs)) { - $j = 0; - $loop = true; - while ($j < count($original)) { - if ($msgs[$i]["ID"] == $original[$j]["ID"]) { - $msgs[$i]["FROM"] = $original[$j]["FROM"]; - $msgs[$i]["SUBJECT"] = $original[$j]["SUBJECT"]; - - // exit out of this loop if we find the thing. - $j = count($original) + 1; - } - $j++; - } - $i++; - } + $msort = array_cleave ($msgs, "TIME_STAMP"); + if(($sort % 2) == 1) { + asort($msort); + } else { + arsort($msort); } + session_register("msort"); } - - displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $mailbox, $sort, $color,$show_num); + displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num); } // generic function to convert the msgs array into an HTML table - function displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $mailbox, $sort, $color,$show_num) { + function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) { // do a check to see if the config stuff has already been included or not if (!isset($imapServerAddress)) include("../config/config.php"); @@ -157,6 +122,8 @@ // if cache isn't already set, do it now if (!session_is_registered("msgs")) session_register("msgs"); + if (!session_is_registered("msort")) + session_register("msort"); if ($startMessage + ($show_num - 1) < $numMessages) { $endMessage = $startMessage + ($show_num-1); @@ -275,10 +242,21 @@ $i = $startMessage - 1; printMessageInfo($imapConnection, $t, $msgs[$i], $mailbox, $sort, $startMessage); } else { - for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) { - printMessageInfo($imapConnection, $t, $msgs[$i], $mailbox, $sort, $startMessage); + $i = $startMessage; + reset($msort); + do { + $key = key($msort); + next($msort); + $k++; + } while (isset ($key) && ($k < $i)); + + do { + printMessageInfo($imapConnection, $t, $msgs[$key], $mailbox, $sort, $startMessage); + $key = key($msort); $t++; - } + $i++; + next($msort); + } while ($i < ($endMessage+1)); } echo ""; -- 2.25.1