# 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";
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 = <FILE>) {
- 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 "<?\n\t/** SquirrelMail configure script\n";
print FILE " ** Created using the configure script, config.pl.\n\t **/\n\n";
-
-print "\n-------------------------------------------------.\n";
-print " General Information )\n";
-print "-------------------------------------------------'\n";
-############################################################
-# Organization Name
-############################################################
-print $WHT."What is the name of your organization [$org_name]: $NRM";
-$new_org_name = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-if (($use_smtp =~ /^y\n/i) || (($use_smtp =~ /^\n/) && ($default_value eq "y"))) {
- ############################################################
- # SMTP Server
- ############################################################
- print " What is the SMTP server [$smtpServerAddress]: ";
- $new_smtpServerAddress = <STDIN>;
- 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 = <STDIN>;
+ 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 = <STDIN>;
+ 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 = <STDIN>;
- 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 = <STDIN>;
+ 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 = <STDIN>;
- 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 = <STDIN>;
+ 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 = <STDIN>;
- $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 = <STDIN>;
-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 = <STDIN>;
+ $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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-$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 = <STDIN>;
- $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 = <STDIN>;
-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 = <STDIN>;
-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 = <STDIN>;
-$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 = <STDIN>;
- $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 = <STDIN>;
- $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 = <STDIN>;
- $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 = <STDIN>;
-if (($autoe =~ /^y\n/i) || ($autoe =~ /^\n/)) {
- system "mv -f cf.php config.php";
-}
-
-
return $newArray;
}
+
+ function array_cleave($array1, $column)
+ {
+ $key=0;
+ $array2 = array();
+ while ($key < count($array1)) {
+ array_push($array2, $array1[$key]["$column"]);
+ $key++;
+ }
+
+ return ($array2);
+ }
+
?>
<?php
- /**
- ** imap_mailbox.php
- **
- ** This impliments all functions that manipulate mailboxes
- **/
-
- /******************************************************************************
- ** Expunges a mailbox
- ******************************************************************************/
- function sqimap_mailbox_expunge ($imap_stream, $mailbox) {
- sqimap_mailbox_select ($imap_stream, $mailbox);
- fputs ($imap_stream, "a001 EXPUNGE\r\n");
- $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
- }
-
-
- /******************************************************************************
- ** Checks whether or not the specified mailbox exists
- ******************************************************************************/
- function sqimap_mailbox_exists ($imap_stream, $mailbox) {
- $boxes = sqimap_mailbox_list ($imap_stream);
- $found = false;
- for ($i = 0; $i < count ($boxes); $i++) {
- if ($boxes[$i]["unformatted"] == $mailbox)
- $found = true;
- }
- return $found;
- }
-
-
-
- /******************************************************************************
- ** Selects a mailbox
- ******************************************************************************/
- function sqimap_mailbox_select ($imap_stream, $mailbox) {
- fputs ($imap_stream, "a001 SELECT \"$mailbox\"\r\n");
- $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
- }
-
-
-
- /******************************************************************************
- ** Creates a folder
- ******************************************************************************/
- function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
- if (strtolower($type) == "noselect") {
- $dm = sqimap_get_delimiter($imap_stream);
- $mailbox = $mailbox.$dm;
- }
- fputs ($imap_stream, "a001 CREATE \"$mailbox\"\r\n");
- $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
-
- sqimap_subscribe ($imap_stream, $mailbox);
- }
-
-
-
- /******************************************************************************
- ** Subscribes to an existing folder
- ******************************************************************************/
- function sqimap_subscribe ($imap_stream, $mailbox) {
- fputs ($imap_stream, "a001 SUBSCRIBE \"$mailbox\"\r\n");
- $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
- }
-
-
-
-
- /******************************************************************************
- ** Unsubscribes to an existing folder
- ******************************************************************************/
- function sqimap_unsubscribe ($imap_stream, $mailbox) {
- fputs ($imap_stream, "a001 UNSUBSCRIBE \"$mailbox\"\r\n");
- $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
- }
-
-
-
-
- /******************************************************************************
- ** This function simply deletes the given folder
- ******************************************************************************/
- function sqimap_mailbox_delete ($imap_stream, $mailbox) {
- fputs ($imap_stream, "a001 DELETE \"$mailbox\"\r\n");
- $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
- sqimap_unsubscribe ($imap_stream, $mailbox);
- }
-
-
-
- /******************************************************************************
- ** Returns sorted mailbox lists in several different ways.
- ** The array returned looks like this:
- ******************************************************************************/
- function sqimap_mailbox_list ($imap_stream) {
- global $load_prefs_php, $prefs_php, $config_php, $data_dir, $username;
- if (!isset($load_prefs_php))
- include "../src/load_prefs.php";
- else
- global $folder_prefix;
- global $special_folders, $list_special_folders_first, $default_folder_prefix;
-
- if (!function_exists ("ary_sort"))
- include ("../functions/array.php");
-
- $dm = sqimap_get_delimiter ($imap_stream);
-
- fputs ($imap_stream, "a001 LIST \"\" INBOX\r\n");
- $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
- $g = 0;
- $phase = "inbox";
- for ($i = 0; $i < count($read_ary); $i++) {
- if (substr ($read_ary[$i], 0, 4) != "a001") {
- $boxes[$g]["raw"] = $read_ary[$i];
-
- $mailbox = find_mailbox_name($read_ary[$i]);
- $dm_count = countCharInString($mailbox, $dm);
- if (substr($mailbox, -1) == $dm)
- $dm_count--;
-
- for ($j = 0; $j < $dm_count; $j++)
- $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
- $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
-
- $boxes[$g]["unformatted-dm"] = $mailbox;
- if (substr($mailbox, -1) == $dm)
- $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
- $boxes[$g]["unformatted"] = $mailbox;
- $boxes[$g]["id"] = $g;
-
- /** Now lets get the flags for this mailbox **/
- fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\r\n");
- $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
-
- $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+1);
- $flags = substr($flags, 0, strpos($flags, ")"));
- $flags = str_replace("\\", "", $flags);
- $flags = trim(strtolower($flags));
- if ($flags) {
- $boxes[$g]["flags"] = explode(" ", $flags);
- }
- }
- $g++;
-
- if (!$read_ary[$i+1]) {
- if ($phase == "inbox") {
- if ($folder_prefix && (substr($folder_prefix, -1) != $dm))
- $folder_prefix = $folder_prefix . $dm;
-
- fputs ($imap_stream, "a001 LSUB \"$folder_prefix\" *\r\n");
- $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
- $phase = "lsub";
- $i--;
- }
- }
- }
-
- $original = $boxes;
-
- /** Get the folders into lower case so sorting is not case sensative */
- for ($i = 0; $i < count($original); $i++) {
- $boxes[$i]["unformatted"] = strtolower($boxes[$i]["unformatted"]);
- }
-
- /** Sort them **/
- $boxes = ary_sort($boxes, "unformatted", 1);
-
- /** Get them back from the original array, still sorted by the id **/
- for ($i = 0; $i < count($boxes); $i++) {
- for ($j = 0; $j < count($original); $j++) {
- if ($boxes[$i]["id"] == $original[$j]["id"]) {
- $boxes[$i] = $original[$j];
- }
- }
- }
+ /**
+ ** imap_mailbox.php
+ **
+ ** This impliments all functions that manipulate mailboxes
+ **/
+
+ /******************************************************************************
+ ** Expunges a mailbox
+ ******************************************************************************/
+ function sqimap_mailbox_expunge ($imap_stream, $mailbox) {
+ sqimap_mailbox_select ($imap_stream, $mailbox);
+ fputs ($imap_stream, "a001 EXPUNGE\r\n");
+ $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+ }
+
+
+ /******************************************************************************
+ ** Checks whether or not the specified mailbox exists
+ ******************************************************************************/
+ function sqimap_mailbox_exists ($imap_stream, $mailbox) {
+ $boxes = sqimap_mailbox_list ($imap_stream);
+ $found = false;
+ for ($i = 0; $i < count ($boxes); $i++) {
+ if ($boxes[$i]["unformatted"] == $mailbox)
+ $found = true;
+ }
+ return $found;
+ }
+
+
+
+ /******************************************************************************
+ ** Selects a mailbox
+ ******************************************************************************/
+ function sqimap_mailbox_select ($imap_stream, $mailbox) {
+ fputs ($imap_stream, "a001 SELECT \"$mailbox\"\r\n");
+ $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+ }
+
+
+
+ /******************************************************************************
+ ** Creates a folder
+ ******************************************************************************/
+ function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
+ if (strtolower($type) == "noselect") {
+ $dm = sqimap_get_delimiter($imap_stream);
+ $mailbox = $mailbox.$dm;
+ }
+ fputs ($imap_stream, "a001 CREATE \"$mailbox\"\r\n");
+ $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+
+ sqimap_subscribe ($imap_stream, $mailbox);
+ }
+
+
+
+ /******************************************************************************
+ ** Subscribes to an existing folder
+ ******************************************************************************/
+ function sqimap_subscribe ($imap_stream, $mailbox) {
+ fputs ($imap_stream, "a001 SUBSCRIBE \"$mailbox\"\r\n");
+ $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+ }
+
+
+
+
+ /******************************************************************************
+ ** Unsubscribes to an existing folder
+ ******************************************************************************/
+ function sqimap_unsubscribe ($imap_stream, $mailbox) {
+ fputs ($imap_stream, "a001 UNSUBSCRIBE \"$mailbox\"\r\n");
+ $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+ }
+
+
+
+
+ /******************************************************************************
+ ** This function simply deletes the given folder
+ ******************************************************************************/
+ function sqimap_mailbox_delete ($imap_stream, $mailbox) {
+ fputs ($imap_stream, "a001 DELETE \"$mailbox\"\r\n");
+ $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+ sqimap_unsubscribe ($imap_stream, $mailbox);
+ }
+
+
+ /******************************************************************************
+ ** Formats a mailbox into 4 parts for the $boxes array
+ ******************************************************************************/
+ function sqimap_mailbox_parse ($line, $dm) {
+ for ($g=0; $g < count($line); $g++) {
+ $boxes[$g]["raw"] = $line[$g];
+
+ $mailbox = find_mailbox_name($line[$g]);
+ $dm_count = countCharInString($mailbox, $dm);
+ if (substr($mailbox, -1) == $dm)
+ $dm_count--;
+
+ for ($j = 0; $j < $dm_count; $j++)
+ $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
+ $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
+
+ $boxes[$g]["unformatted-dm"] = $mailbox;
+ if (substr($mailbox, -1) == $dm)
+ $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
+ $boxes[$g]["unformatted"] = $mailbox;
+ $boxes[$g]["id"] = $g;
+
+ $flags = substr($line[$g], strpos($line[$g], "(")+1);
+ $flags = substr($flags, 0, strpos($flags, ")"));
+ $flags = str_replace("\\", "", $flags);
+ $flags = trim(strtolower($flags));
+ if ($flags) {
+ $boxes[$g]["flags"] = explode(" ", $flags);
+ }
+ }
+ return $boxes;
+ }
+
+ /******************************************************************************
+ ** Returns sorted mailbox lists in several different ways.
+ ** The array returned looks like this:
+ ******************************************************************************/
+ function sqimap_mailbox_list ($imap_stream) {
+ global $load_prefs_php, $prefs_php, $config_php, $data_dir, $username;
+
+ if (!isset($load_prefs_php)) include "../src/load_prefs.php";
+ else global $folder_prefix;
+ if (!function_exists ("ary_sort")) include "../functions/array.php";
+
+ $dm = sqimap_get_delimiter ($imap_stream);
+
+ /** LIST array **/
+ fputs ($imap_stream, "a001 LIST \"\" \"$folder_prefix*\"\r\n");
+ $list_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+ for ($i=0;$i < count($list_ary); $i++) {
+ $sorted_list_ary[$i]["name"] = find_mailbox_name($list_ary[$i]);
+ $sorted_list_ary[$i]["raw"] = $list_ary[$i];
+ }
+ $list_sorted = array_cleave ($sorted_list_ary, "name");
+ asort($list_sorted);
+
+ /** LSUB array **/
+ fputs ($imap_stream, "a001 LSUB \"\" \"*\"\r\n");
+ $lsub_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+ for ($i=0;$i < count($lsub_ary); $i++) {
+ $sorted_lsub_ary[$i] = find_mailbox_name($lsub_ary[$i]);
+ if (substr($sorted_lsub_ary[$i], -1) == $dm)
+ $sorted_lsub_ary[$i] = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
+ }
+ sort($sorted_lsub_ary);
+
+
+ /** Now we'll get a list of subscribed folders WITH flags **/
+ fputs ($imap_stream, "a001 LIST \"\" \"INBOX\"\r\n");
+ $inbox_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+ $merged[0] = $inbox_ary[0];
+
+ $i = $j = 0;
+ $k = 1;
+
+ reset ($list_sorted);
+ for (reset($list_sorted); $key = key($list_sorted), isset($key);) {
+ if ($sorted_lsub_ary[$i] == $list_sorted[$key]) {
+ $merged[$k] = $sorted_list_ary[$key]["raw"];
+ $k++;
+ $i++;
+ next($list_sorted);
+ } else if ($sorted_lsub_ary[$i] < $list_sorted[$key]) {
+ $i++;
+ } else {
+ next($list_sorted);
+ }
+ }
+
+ return sqimap_mailbox_parse ($merged, $dm);
+ }
+
+/*
+ $original = $boxes;
+
+ for ($i = 0; $i < count($original); $i++) {
+ $boxes[$i]["unformatted"] = strtolower($boxes[$i]["unformatted"]);
+ }
+
+ $boxes = ary_sort($boxes, "unformatted", 1);
+
+ for ($i = 0; $i < count($boxes); $i++) {
+ for ($j = 0; $j < count($original); $j++) {
+ if ($boxes[$i]["id"] == $original[$j]["id"]) {
+ $boxes[$i] = $original[$j];
+ }
+ }
+ }
-
- for ($i = 0; $i < count($boxes); $i++) {
- if ($boxes[$i]["unformatted"] == $special_folders[0]) {
- $boxesnew[0] = $boxes[$i];
- $boxes[$i]["used"] = true;
- }
- }
-
- if ($list_special_folders_first == true) {
- for ($i = 0; $i < count($boxes); $i++) {
- for ($j = 1; $j < count($special_folders); $j++) {
- if (substr($boxes[$i]["unformatted"], 0, strlen($special_folders[$j])) == $special_folders[$j]) {
- $pos = count($boxesnew);
- $boxesnew[$pos] = $boxes[$i];
- $boxes[$i]["used"] = true;
- }
- }
- }
- }
-
- for ($i = 0; $i < count($boxes); $i++) {
- if (($boxes[$i]["unformatted"] != $special_folders[0]) &&
- ($boxes[$i]["used"] == false)) {
- $pos = count($boxesnew);
- $boxesnew[$pos] = $boxes[$i];
- $boxes[$i]["used"] = true;
- }
- }
-
- return $boxesnew;
- }
-
-
- /******************************************************************************
- ** Returns a list of all folders, subscribed or not
- ******************************************************************************/
- function sqimap_mailbox_list_all ($imap_stream) {
- global $special_folders, $list_special_folders_first, $folder_prefix;
-
- if (!function_exists ("ary_sort"))
- include ("../functions/array.php");
-
- $dm = sqimap_get_delimiter ($imap_stream);
-
- fputs ($imap_stream, "a001 LIST \"$folder_prefix\" *\r\n");
- $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
- $g = 0;
- $phase = "inbox";
- for ($i = 0; $i < count($read_ary); $i++) {
- if (substr ($read_ary[$i], 0, 4) != "a001") {
- $boxes[$g]["raw"] = $read_ary[$i];
-
- $mailbox = find_mailbox_name($read_ary[$i]);
- $dm_count = countCharInString($mailbox, $dm);
- if (substr($mailbox, -1) == $dm)
- $dm_count--;
-
- for ($j = 0; $j < $dm_count; $j++)
- $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
- $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
-
- $boxes[$g]["unformatted-dm"] = $mailbox;
- if (substr($mailbox, -1) == $dm)
- $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
- $boxes[$g]["unformatted"] = $mailbox;
- $boxes[$g]["id"] = $g;
-
- /** Now lets get the flags for this mailbox **/
- fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\r\n");
- $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
-
- $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+1);
- $flags = substr($flags, 0, strpos($flags, ")"));
- $flags = str_replace("\\", "", $flags);
- $flags = trim(strtolower($flags));
- if ($flags) {
- $boxes[$g]["flags"] = explode(" ", $flags);
- }
- }
- $g++;
- }
- $boxes = ary_sort ($boxes, "unformatted", 1);
- return $boxes;
- }
-
+
+ for ($i = 0; $i < count($boxes); $i++) {
+ if ($boxes[$i]["unformatted"] == $special_folders[0]) {
+ $boxesnew[0] = $boxes[$i];
+ $boxes[$i]["used"] = true;
+ }
+ }
+
+ if ($list_special_folders_first == true) {
+ for ($i = 0; $i < count($boxes); $i++) {
+ for ($j = 1; $j < count($special_folders); $j++) {
+ if (substr($boxes[$i]["unformatted"], 0, strlen($special_folders[$j])) == $special_folders[$j]) {
+ $pos = count($boxesnew);
+ $boxesnew[$pos] = $boxes[$i];
+ $boxes[$i]["used"] = true;
+ }
+ }
+ }
+ }
+
+ for ($i = 0; $i < count($boxes); $i++) {
+ if (($boxes[$i]["unformatted"] != $special_folders[0]) &&
+ ($boxes[$i]["used"] == false)) {
+ $pos = count($boxesnew);
+ $boxesnew[$pos] = $boxes[$i];
+ $boxes[$i]["used"] = true;
+ }
+ }
+
+ return $boxesnew;
+ }
+ */
+
+ /******************************************************************************
+ ** Returns a list of all folders, subscribed or not
+ ******************************************************************************/
+ function sqimap_mailbox_list_all ($imap_stream) {
+ global $special_folders, $list_special_folders_first, $folder_prefix;
+
+ if (!function_exists ("ary_sort"))
+ include ("../functions/array.php");
+
+ $dm = sqimap_get_delimiter ($imap_stream);
+
+ fputs ($imap_stream, "a001 LIST \"$folder_prefix\" *\r\n");
+ $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+ $g = 0;
+ $phase = "inbox";
+ for ($i = 0; $i < count($read_ary); $i++) {
+ if (substr ($read_ary[$i], 0, 4) != "a001") {
+ $boxes[$g]["raw"] = $read_ary[$i];
+
+ $mailbox = find_mailbox_name($read_ary[$i]);
+ $dm_count = countCharInString($mailbox, $dm);
+ if (substr($mailbox, -1) == $dm)
+ $dm_count--;
+
+ for ($j = 0; $j < $dm_count; $j++)
+ $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
+ $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
+
+ $boxes[$g]["unformatted-dm"] = $mailbox;
+ if (substr($mailbox, -1) == $dm)
+ $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
+ $boxes[$g]["unformatted"] = $mailbox;
+ $boxes[$g]["id"] = $g;
+
+ /** Now lets get the flags for this mailbox **/
+ fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\r\n");
+ $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
+
+ $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+1);
+ $flags = substr($flags, 0, strpos($flags, ")"));
+ $flags = str_replace("\\", "", $flags);
+ $flags = trim(strtolower($flags));
+ if ($flags) {
+ $boxes[$g]["flags"] = explode(" ", $flags);
+ }
+ }
+ $g++;
+ }
+ $boxes = ary_sort ($boxes, "unformatted", 1);
+ return $boxes;
+ }
+
?>
$mailbox_info = true;
function printMessageInfo($imapConnection, $t, $msg, $mailbox, $sort, $startMessage) {
- //require ("../config/config.php");
global $color;
$senderName = $msg["FROM"];
/**
** 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");
// 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);
$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 "</FORM></TABLE>";