From a3439b271e1b5fa7e61362970dbbcc5bfc75e5b1 Mon Sep 17 00:00:00 2001 From: thomppj Date: Sun, 23 Dec 2001 06:08:34 +0000 Subject: [PATCH] Added sent_subfolders plugin, tweaked config stuff, other stuff. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1886 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- config/conf.pl | 500 +++++++++--------- config/config_default.php | 810 ++++++++++++++++-------------- functions/imap_mailbox.php | 63 ++- functions/mailbox_display.php | 22 +- functions/plugin.php | 15 +- plugins/sent_subfolders/setup.php | 239 +++++++++ src/compose.php | 4 +- src/left_main.php | 8 +- src/options.php | 12 +- 9 files changed, 1021 insertions(+), 652 deletions(-) create mode 100644 plugins/sent_subfolders/setup.php diff --git a/config/conf.pl b/config/conf.pl index 02c6c334..6f142521 100755 --- a/config/conf.pl +++ b/config/conf.pl @@ -6,7 +6,7 @@ # # $Id$ ############################################################ -$conf_pl_version = "x64"; +$conf_pl_version = "1.2.0"; ############################################################ # Some people try to run this as a CGI. That's wrong! @@ -24,22 +24,21 @@ if(defined($ENV{'PATH_INFO'}) || defined($ENV{'QUERY_STRING'}) || if ( -e "config.php") { open (FILE, "config.php"); while ($line = ) { - if ($line =~ /^\s+\$/) { - $line =~ s/^\s+\$//; - $var = $line; + $line =~ s/^\s+//; + $line =~ s/^\$//; + $var = $line; - $var =~ s/=/EQUALS/; - if ($var =~ /^([a-z]|[A-Z])/) { - @o = split(/\s*EQUALS\s*/, $var); - if ($o[0] eq "config_version") { - $o[1] =~ s/[\n|\r]//g; - $o[1] =~ s/\";\s*$//; - $o[1] =~ s/;$//; - $o[1] =~ s/^\"//; - - $config_version = $o[1]; - close (FILE); - } + $var =~ s/=/EQUALS/; + if ($var =~ /^([a-z]|[A-Z])/) { + @o = split(/\s*EQUALS\s*/, $var); + if ($o[0] eq "config_version") { + $o[1] =~ s/[\n|\r]//g; + $o[1] =~ s/[\'|\"];\s*$//; + $o[1] =~ s/;$//; + $o[1] =~ s/^[\'|\"]//; + + $config_version = $o[1]; + close (FILE); } } } @@ -48,11 +47,13 @@ if ( -e "config.php") { if ($config_version ne $conf_pl_version) { system "clear"; print $WHT."WARNING:\n".$NRM; - print " The file \"config/config.php\" was found, but it is for an older version of\n"; - print " SquirrelMail. It is possible to still read the defaults from this file\n"; - print " but be warned that many preferences change between versions. It is\n"; - print " recommended that you start with a clean config.php for each upgrade that\n"; - print " you do. To do this, just move config/config.php out of the way.\n\n"; + print " The file \"config/config.php\" was found, but it is for\n"; + print " an older version of SquirrelMail. It is possible to still\n"; + print " read the defaults from this file but be warned that many\n"; + print " preferences change between versions. It is recommended that\n"; + print " you start with a clean config.php for each upgrade that you\n"; + print " do. To do this, just move config/config.php out of the way.\n"; + print "\n"; print "Continue loading with the old config.php [y/N]? "; $ctu = ; if (($ctu !~ /^y\n/i) || ($ctu =~ /^\n/)) { @@ -75,22 +76,21 @@ if ( -e "config.php") { } elsif (-e "config_default.php") { open (FILE, "config_default.php"); while ($line = ) { - if ($line =~ /^\s+\$/) { - $line =~ s/^\s+\$//; - $var = $line; + $line =~ s/^\s+//; + $line =~ s/^\$//; + $var = $line; - $var =~ s/=/EQUALS/; - if ($var =~ /^([a-z]|[A-Z])/) { - @o = split(/\s*EQUALS\s*/, $var); - if ($o[0] eq "config_version") { - $o[1] =~ s/[\n|\r]//g; - $o[1] =~ s/\";\s*$//; - $o[1] =~ s/;$//; - $o[1] =~ s/^\"//; - - $config_version = $o[1]; - close (FILE); - } + $var =~ s/=/EQUALS/; + if ($var =~ /^([a-z]|[A-Z])/) { + @o = split(/\s*EQUALS\s*/, $var); + if ($o[0] eq "config_version") { + $o[1] =~ s/[\n|\r]//g; + $o[1] =~ s/[\'|\"];\s*$//; + $o[1] =~ s/;$//; + $o[1] =~ s/^[\'|\"]//; + + $config_version = $o[1]; + close (FILE); } } } @@ -99,12 +99,14 @@ if ( -e "config.php") { if ($config_version ne $conf_pl_version) { system "clear"; print $WHT."WARNING:\n".$NRM; - print " You are trying to use a \"config_default.php\" from an older version of\n"; - print " SquirrelMail. This is HIGHLY unrecommended. You should get the\n"; - print " \"config_default.php\" that matches the version of SquirrelMail that you\n"; - print " are running. You can get this from the SquirrelMail web page by going\n"; - print " to: http://www.squirrelmail.org.\n\n"; - print "Continue loading with the old config_default.php (not a good idea) [y/N]? "; + print " You are trying to use a 'config_default.php' from an older\n"; + print " version of SquirrelMail. This is HIGHLY unrecommended. You\n"; + print " should get the 'config_default.php' that matches the version\n"; + print " of SquirrelMail that you are running. You can get this from\n"; + print " the SquirrelMail web page by going to the following URL:\n"; + print " http://www.squirrelmail.org.\n"; + print "\n"; + print "Continue loading with old config_default.php (a bad idea) [y/N]? "; $ctu = ; if (($ctu !~ /^y\n/i) || ($ctu =~ /^\n/)) { exit; @@ -123,99 +125,97 @@ if ( -e "config.php") { $config = 2; open (FILE, "config_default.php"); } else { - print "No configuration file found. Please get config_default.php or\n"; - print "config.php before running this again. This program needs a\n"; - print "default config file to get default values.\n"; + print "No configuration file found. Please get config_default.php\n"; + print "or config.php before running this again. This program needs\n"; + print "a default config file to get default values.\n"; exit; } -# Reads and parses the current configuration file (either -# config.php or config_default.php). - +# Read and parse the current configuration file +# (either config.php or config_default.php). while ($line = ) { - if ($line =~ /^\s+\$/) { - $line =~ s/^\s+\$//; - $var = $line; + $line =~ s/^\s+//; + $line =~ s/^\$//; + $var = $line; - $var =~ s/=/EQUALS/; - if ($var =~ /^([a-z]|[A-Z])/) { - @options = split(/\s*EQUALS\s*/, $var); - $options[1] =~ s/[\n|\r]//g; - $options[1] =~ s/\";\s*$//; - $options[1] =~ s/;$//; - $options[1] =~ s/^\"//; - - if ($options[0] =~ /^theme\[[0-9]+\]\["PATH"\]/) { - $sub = $options[0]; - $sub =~ s/\]\["PATH"\]//; - $sub =~ s/.*\[//; - if (-e "../themes") { - $options[1] =~ s/^\.\.\/config/\.\.\/themes/; - } - $theme_path[$sub] = $options[1]; - } elsif ($options[0] =~ /^theme\[[0-9]+\]\["NAME"\]/) { - $sub = $options[0]; - $sub =~ s/\]\["NAME"\]//; - $sub =~ s/.*\[//; - $theme_name[$sub] = $options[1]; - } elsif ($options[0] =~ /^plugins\[[0-9]+\]/) { - $sub = $options[0]; - $sub =~ s/\]//; - $sub =~ s/^plugins\[//; - $plugins[$sub] = $options[1]; - } elsif ($options[0] =~ /^ldap_server\[[0-9]+\]/) { - $sub = $options[0]; - $sub =~ s/\]//; - $sub =~ s/^ldap_server\[//; - $continue = 0; - while (($tmp = ) && ($continue != 1)) { - if ($tmp =~ /\);\s*$/) { - $continue = 1; - } - - if ($tmp =~ /^\s*\"host\"/i) { - $tmp =~ s/^\s*\"host\"\s*=>\s*\"//i; - $tmp =~ s/\",\s*$//; - $tmp =~ s/\"\);\s*$//; - $host = $tmp; - } elsif ($tmp =~ /^\s*\"base\"/i) { - $tmp =~ s/^\s*\"base\"\s*=>\s*\"//i; - $tmp =~ s/\",\s*$//; - $tmp =~ s/\"\);\s*$//; - $base = $tmp; - } elsif ($tmp =~ /^\s*\"charset\"/i) { - $tmp =~ s/^\s*\"charset\"\s*=>\s*\"//i; - $tmp =~ s/\",\s*$//; - $tmp =~ s/\"\);\s*$//; - $charset = $tmp; - } elsif ($tmp =~ /^\s*\"port\"/i) { - $tmp =~ s/^\s*\"port\"\s*=>\s*\"//i; - $tmp =~ s/\",\s*$//; - $tmp =~ s/\"\);\s*$//; - $port = $tmp; - } elsif ($tmp =~ /^\s*\"maxrows\"/i) { - $tmp =~ s/^\s*\"maxrows\"\s*=>\s*\"//i; - $tmp =~ s/\",\s*$//; - $tmp =~ s/\"\);\s*$//; - $maxrows = $tmp; - } elsif ($tmp =~ /^\s*\"name\"/i) { - $tmp =~ s/^\s*\"name\"\s*=>\s*\"//i; - $tmp =~ s/\",\s*$//; - $tmp =~ s/\"\);\s*$//; - $name = $tmp; - } - } - $ldap_host[$sub] = $host; - $ldap_base[$sub] = $base; - $ldap_name[$sub] = $name; - $ldap_port[$sub] = $port; - $ldap_maxrows[$sub] = $maxrows; - $ldap_charset[$sub] = $charset; - } else { - ${$options[0]} = $options[1]; + $var =~ s/=/EQUALS/; + if ($var =~ /^([a-z]|[A-Z])/) { + @options = split(/\s*EQUALS\s*/, $var); + $options[1] =~ s/[\n|\r]//g; + $options[1] =~ s/[\'|\"];\s*$//; + $options[1] =~ s/;$//; + $options[1] =~ s/^[\'|\"]//; + + if ($options[0] =~ /^theme\[[0-9]+\]\[['|"]PATH['|"]\]/) { + $sub = $options[0]; + $sub =~ s/\]\[['|"]PATH['|"]\]//; + $sub =~ s/.*\[//; + if (-e "../themes") { + $options[1] =~ s/^\.\.\/config/\.\.\/themes/; } + $theme_path[$sub] = $options[1]; + } elsif ($options[0] =~ /^theme\[[0-9]+\]\[['|"]NAME['|"]\]/) { + $sub = $options[0]; + $sub =~ s/\]\[['|"]NAME['|"]\]//; + $sub =~ s/.*\[//; + $theme_name[$sub] = $options[1]; + } elsif ($options[0] =~ /^plugins\[[0-9]+\]/) { + $sub = $options[0]; + $sub =~ s/\]//; + $sub =~ s/^plugins\[//; + $plugins[$sub] = $options[1]; + } elsif ($options[0] =~ /^ldap_server\[[0-9]+\]/) { + $sub = $options[0]; + $sub =~ s/\]//; + $sub =~ s/^ldap_server\[//; + $continue = 0; + while (($tmp = ) && ($continue != 1)) { + if ($tmp =~ /\);\s*$/) { + $continue = 1; + } + + if ($tmp =~ /^\s*[\'|\"]host[\'|\"]/i) { + $tmp =~ s/^\s*[\'|\"]host[\'|\"]\s*=>\s*[\'|\"]//i; + $tmp =~ s/[\'|\"],?\s*$//; + $tmp =~ s/[\'|\"]\);\s*$//; + $host = $tmp; + } elsif ($tmp =~ /^\s*[\'|\"]base[\'|\"]/i) { + $tmp =~ s/^\s*[\'|\"]base[\'|\"]\s*=>\s*[\'|\"]//i; + $tmp =~ s/[\'|\"],?\s*$//; + $tmp =~ s/[\'|\"]\);\s*$//; + $base = $tmp; + } elsif ($tmp =~ /^\s*[\'|\"]charset[\'|\"]/i) { + $tmp =~ s/^\s*[\'|\"]charset[\'|\"]\s*=>\s*[\'|\"]//i; + $tmp =~ s/[\'|\"],?\s*$//; + $tmp =~ s/[\'|\"]\);\s*$//; + $charset = $tmp; + } elsif ($tmp =~ /^\s*[\'|\"]port[\'|\"]/i) { + $tmp =~ s/^\s*[\'|\"]port[\'|\"]\s*=>\s*[\'|\"]//i; + $tmp =~ s/[\'|\"],?\s*$//; + $tmp =~ s/[\'|\"]\);\s*$//; + $port = $tmp; + } elsif ($tmp =~ /^\s*[\'|\"]maxrows[\'|\"]/i) { + $tmp =~ s/^\s*[\'|\"]maxrows[\'|\"]\s*=>\s*[\'|\"]//i; + $tmp =~ s/[\'|\"],?\s*$//; + $tmp =~ s/[\'|\"]\);\s*$//; + $maxrows = $tmp; + } elsif ($tmp =~ /^\s*[\'|\"]name[\'|\"]/i) { + $tmp =~ s/^\s*[\'|\"]name[\'|\"]\s*=>\s*[\'|\"]//i; + $tmp =~ s/[\'|\"],?\s*$//; + $tmp =~ s/[\'|\"]\);\s*$//; + $name = $tmp; + } + } + $ldap_host[$sub] = $host; + $ldap_base[$sub] = $base; + $ldap_name[$sub] = $name; + $ldap_port[$sub] = $port; + $ldap_maxrows[$sub] = $maxrows; + $ldap_charset[$sub] = $charset; + } else { + ${$options[0]} = $options[1]; } - } + } } close FILE; if ($useSendmail ne "true") { @@ -237,22 +237,22 @@ if (!$invert_time) { $invert_time = "false"; } if (!$force_username_lowercase) { - $force_username_lowercase = "false"; + $force_username_lowercase = "false"; } if (!$optional_delimiter) { - $optional_delimiter = "detect"; + $optional_delimiter = "detect"; } if (!$use_authenticated_smtp) { $use_authenticated_smtp = "false"; } if (!$auto_create_special) { - $auto_create_special = "false"; + $auto_create_special = "false"; } if(!$default_use_priority) { - $default_use_priority = "true"; + $default_use_priority = "true"; } if(!$hide_sm_attributions) { - $hide_sm_attributions = "false"; + $hide_sm_attributions = "false"; } ##################################################################################### @@ -270,7 +270,7 @@ while (($command ne "q") && ($command ne "Q")) { print $WHT."SquirrelMail Configuration : ".$NRM; if ($config == 1) { print "Read: config.php"; } elsif ($config == 2) { print "Read: config_default.php"; } - print "\n"; + print " ($print_config_version)\n"; print "---------------------------------------------------------\n"; if ($menu == 0) { @@ -789,7 +789,7 @@ sub command111 { print "folders. For example, Cyrus uses '.' as the delimiter and a complete\n"; print "folder would look like 'INBOX.Friends.Bob', while UW uses '/' and would\n"; print "look like 'INBOX/Friends/Bob'. Normally this should be left at 'detect'\n"; - print "but if you are sure you konw what delimiter your server uses, you can\n"; + print "but if you are sure you know what delimiter your server uses, you can\n"; print "specify it here.\n"; print "\nTo have it autodetect the delimiter, set it to 'detect'.\n\n"; print "[$WHT$optional_delimiter$NRM]: $WHT"; @@ -1763,136 +1763,154 @@ sub command62 { sub save_data { - open (FILE, ">config.php"); - - print FILE "config.php"); - print FILE "\tglobal \$print_config_version, \$config_version, \$config_use_color;\n"; + print CF " \"$ldap_host[$count]\",\n"; - print FILE "\t\t\t\"base\" => \"$ldap_base[$count]\""; + print CF "\$ldap_server[$count] = array(\n"; + print CF " 'host' => '$ldap_host[$count]',\n"; + print CF " 'base' => '$ldap_base[$count]'"; if ($ldap_name[$count]) { - print FILE ",\n\t\t\t\"name\" => \"$ldap_name[$count]\""; + print CF ",\n"; + print CF " 'name' => '$ldap_name[$count]'"; } if ($ldap_port[$count]) { - print FILE ",\n\t\t\t\"port\" => \"$ldap_port[$count]\""; + print CF ",\n"; + print CF " 'port' => '$ldap_port[$count]'"; } if ($ldap_charset[$count]) { - print FILE ",\n\t\t\t\"charset\" => \"$ldap_charset[$count]\""; + print CF ",\n"; + print CF " 'charset' => '$ldap_charset[$count]'"; } if ($ldap_maxrows[$count]) { - print FILE ",\n\t\t\t\"maxrows\" => \"$ldap_maxrows[$count]\""; + print CF ",\n"; + print CF " 'maxrows' => '$ldap_maxrows[$count]'"; } - print FILE ");\n\n"; + print CF "\n"; + print CF ");\n"; + print CF "\n"; } - print FILE "\tglobal \$motd;\n"; - print FILE "\t\$motd = \"$motd\";\n"; - - print FILE "\tglobal \$squirrelmail_default_language;\n"; - print FILE "\t\$squirrelmail_default_language = \"$squirrelmail_default_language\";\n"; + print CF "/**\n"; + print CF " * Make sure there are no characters after the PHP closing\n"; + print CF " * tag below (including newline characters and whitespace).\n"; + print CF " * Otherwise, that character will cause the headers to be\n"; + print CF " * sent and regular output to begin, which will majorly screw\n"; + print CF " * things up when we try to send more headers later.\n"; + print CF " */\n"; + print CF "?>"; - close FILE; + close CF; } sub set_defaults { diff --git a/config/config_default.php b/config/config_default.php index 2cc2802a..c724db6d 100644 --- a/config/config_default.php +++ b/config/config_default.php @@ -1,390 +1,442 @@ 'memberdir.netscape.com', + * 'name' => 'Netcenter Member Directory', + * 'base' => 'ou=member_directory,o=netcenter.com' + * ); + */ global $ldap_server; -// -// EXAMPLE: -// -// $ldap_server[0] = Array( -// "host" => "memberdir.netscape.com", -// "name" => "Netcenter Member Directory", -// "base" => "ou=member_directory,o=netcenter.com"); - -// Database-driven private addressbooks -// -// DSN (Data Source Name) for a database where the private -// addressbooks are stored. See doc/db-backend.txt for more info. -// If it is not defined, the addressbooks are stored in files -// in the data dir. -// -// global $addrbook_dsn; -// $addrbook_dsn = 'mysql://user:pass@hostname/dbname'; - - - // you have an option to chose between javascript or html version of - // address book searching. - // true = javascript - // false = html - global $default_use_javascript_addr_book; - $default_use_javascript_addr_book = false; - - // these next two options set the defaults for the way that the users see - // their folder list. - // $default_unseen_notify specifies whether or not the users will see - // the number of unseen in each folder by default - // and alsy which folders to do this to. - // 1=none, 2=inbox, 3=all - // $default_unseen_type specifies the type of notification to give the - // users by default. - // 1=(4), 2=(4,25) - global $default_unseen_notify, $default_unseen_type; - $default_unseen_notify = 2; - $default_unseen_type = 1; + +/** + * Database-driven private addressbooks + * DSN (Data Source Name) for a database where the private + * addressbooks are stored. See doc/db-backend.txt for more info. + * If it is not defined, the addressbooks are stored in files + * in the data dir. + */ +#global $addrbook_dsn; +#$addrbook_dsn = 'mysql://user:pass@hostname/dbname'; + +/** + * Users may search their addressbook via either a plain HTML or Javascript + * enhanced user interface. This option allows you to set the default choice. + * Set this default choice as either: + * true = javascript + * false = html + */ +global $default_use_javascript_addr_book; +$default_use_javascript_addr_book = false; + +/** + * These next two options set the defaults for the way that the + * users see their folder list. + * $default_unseen_notify + * Specifies whether or not the users will see the number of + * unseen in each folder by default and also which folders to + * do this to. Valid values are: 1=none, 2=inbox, 3=all. + * $default_unseen_type + * Specifies the type of notification to give the users by + * default. Valid choice are: 1=(4), 2=(4,25). + */ +global $default_unseen_notify, $default_unseen_type; +$default_unseen_notify = 2; +$default_unseen_type = 1; - // If you are running on a machine that doesn't have the tm_gmtoff - // value in your time structure and if you are in a time zone that - // has a negative offset, you need to set this value to 1. - // This is typically people in the US that are running Solaris 7. - global $invert_time; - $invert_time = false; - - global $plugins; - // To install plugins, just add elements to this array that have - // the plugin directory name relative to the /plugins/ directory. - // For instance, for the "sqclock" plugin, you'd put a line like - // the following: - // $plugins[0] = "sqclock"; - // $plugins[1] = "attachment_common"; - -// Do not add the closing PHP tag here just because we want to avoid -// the potential for parsing errors if there is a newline added +/** + * If you are running on a machine that doesn't have the tm_gmtoff + * value in your time structure and if you are in a time zone that + * has a negative offset, you need to set this value to 1. This is + * typically people in the US that are running Solaris 7. + */ +global $invert_time; +$invert_time = false; + +global $plugins; +/** + * To install plugins, just add elements to this array that have + * the plugin directory name relative to the /plugins/ directory. + * For instance, for the 'sqclock' plugin, you'd put a line like + * the following. + * $plugins[0] = 'sqclock'; + * $plugins[1] = 'attachment_common'; + */ + +/** + * Make sure there are no characters after the PHP closing + * tag below (including newline characters and whitespace). + * Otherwise, that character will cause the headers to be + * sent and regular output to begin, which will majorly screw + * things up when we try to send more headers later. + */ +?> diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index ab05c08e..9ce0ff41 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -220,14 +220,59 @@ function sqimap_mailbox_parse ($line, $line_lsub) return $boxes; } -/* Apparently you must call a user function with usort instead - * of calling a built-in directly. Stupid. - * Patch from dave_michmerhuizen@yahoo.com - * Allows case insensitivity when sorting folders +/** + * 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 :) */ -function user_strcasecmp($a, $b) -{ - return strcasecmp($a, $b); +function user_strcasecmp($a, $b) { + global $delimiter; + + /* Calculate the length of some strings. */ + $a_length = strlen($a); + $b_length = strlen($b); + $min_length = min($a_length, $b_length); + $delimiter_length = strlen($delimiter); + + /* Set the initial result value. */ + $result = 0; + + /* Check the strings... */ + for ($c = 0; $c < $min_length; ++$c) { + $a_del = substr($a, $c, $delimiter_length); + $b_del = substr($b, $c, $delimiter_length); + + if (($a_del == $delimiter) && ($b_del == $delimiter)) { + $result = 0; + } else if (($a_del == $delimiter) && ($b_del != $delimiter)) { + $result = 1; + } else if (($a_del != $delimiter) && ($b_del != $delimiter)) { + $result = -1; + } else { + $result = strcasecmp($a{$c}, $b{$c}); + } + + if ($result != 0) { + break; + } + } + + /* If one string is a prefix of the other... */ + if ($result == 0) { + if ($a_length < $b_length) { + $result = -1; + } else if ($a_length > $b_length) { + $result = 1; + } + } + + return ($result); } @@ -235,8 +280,7 @@ function user_strcasecmp($a, $b) ** 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) -{ +function sqimap_mailbox_list ($imap_stream) { global $data_dir, $username, $list_special_folders_first; global $folder_prefix, $trash_folder, $sent_folder, $draft_folder; global $move_to_trash, $move_to_sent, $save_as_draft; @@ -283,7 +327,6 @@ function sqimap_mailbox_list ($imap_stream) $sorted_lsub_ary = $new_ary; if (isset($sorted_lsub_ary)) { usort($sorted_lsub_ary, 'user_strcasecmp'); - /*sort($sorted_lsub_ary); */ } /** LIST array **/ diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index fbf271c6..dd38cfa3 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -62,7 +62,7 @@ function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start $bold_end = ''; } - if (($mailbox == $sent_folder) || ($mailbox == $draft_folder)) { + if (handleAsSent($mailbox)) { $italic = ''; $italic_end = ''; } else { @@ -188,7 +188,7 @@ function showMessagesForMailbox } sqimap_mailbox_select($imapConnection, $mailbox); - $issent = (($mailbox == $sent_folder) || ($mailbox == $draft_folder)); + $issent = handleAsSent($mailbox); if (!$use_cache) { /* If it is sorted... */ if ($num_msgs >= 1) { @@ -543,8 +543,7 @@ function mail_message_listing_beginning break; case 2: /* from */ - if (($mailbox == $sent_folder) - || ($mailbox == $draft_folder)) { + if (handleAsSent($mailbox)) { echo ' '. _("To") .''; } else { echo ' '. _("From") .''; @@ -891,4 +890,19 @@ function processSubject($subject) { return substr($subject, 0, $trim_val) . '...'; } +function handleAsSent($mailbox) { + global $sent_folder, $draft_folder; + global $handleAsSent_result; + + /* First check if this is the sent or draft folder. */ + $handleAsSent_result = (($mailbox == $sent_folder) + || ($mailbox == $draft_folder)); + + /* Then check the result of the handleAsSent hook. */ + do_hook('check_handleAsSent_result', $mailbox); + + /* And return the result. */ + return ($handleAsSent_result); +} + ?> diff --git a/functions/plugin.php b/functions/plugin.php index fdc7020d..392359fc 100644 --- a/functions/plugin.php +++ b/functions/plugin.php @@ -35,9 +35,9 @@ $squirrelmail_plugin_hooks = array(); // This function adds a plugin function use_plugin ($name) { - if (file_exists('../plugins/'.$name.'/setup.php')) { - include_once('../plugins/'.$name.'/setup.php'); - $function = 'squirrelmail_plugin_init_'.$name; + if (file_exists("../plugins/$name/setup.php")) { + include_once("../plugins/$name/setup.php"); + $function = "squirrelmail_plugin_init_$name"; if (function_exists($function)) { $function(); } @@ -48,13 +48,14 @@ $squirrelmail_plugin_hooks = array(); // This function executes a hook function do_hook ($name) { global $squirrelmail_plugin_hooks; - $Data = func_get_args(); - if (isset($squirrelmail_plugin_hooks[$name]) && - is_array($squirrelmail_plugin_hooks[$name])) { + $data = func_get_args(); + + if (isset($squirrelmail_plugin_hooks[$name]) + && is_array($squirrelmail_plugin_hooks[$name])) { foreach ($squirrelmail_plugin_hooks[$name] as $function) { // Add something to set correct gettext domain for plugin if (function_exists($function)) { - $function($Data); + $function($data); } } } diff --git a/plugins/sent_subfolders/setup.php b/plugins/sent_subfolders/setup.php new file mode 100644 index 00000000..4e98bd0a --- /dev/null +++ b/plugins/sent_subfolders/setup.php @@ -0,0 +1,239 @@ + 1)) { + /* Chop up the folder strings as needed. */ + $base_str = $sent_subfolders_base . $delimiter; + $mbox_str = substr($args[1], 0, strlen($base_str)); + + /* Perform the comparison. */ + $handleAsSent_result = + ( $handleAsSent_result + || ($base_str == $mbox_str) + || ($sent_subfolders_base == $args[1]) + ); + } +} + +function sent_subfolders_load_prefs() { + global $use_sent_subfolders; + global $sent_subfolders_setting, $sent_subfolders_base; + + $use_sent_subfolders = getPref + ($data_dir, $username, 'use_sent_subfolders', SMPREF_OFF); + + $sent_subfolders_setting = getPref + ($data_dir, $username, 'sent_subfolders_setting', SMPREF_SENT_SUBFOLDERS_DISABLED); + + $sent_subfolders_base = getPref + ($data_dir, $username, 'sent_subfolders_base', SMPREF_NONE); +} + +function sent_subfolders_optpage_loadhook_folders() { + global $optpage_data, $username, $key, $imapServerAddress, $imapPort; + + /* Get some imap data we need later. */ + $imapConnection = + sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); + $boxes = sqimap_mailbox_list($imapConnection); + sqimap_logout($imapConnection); + + /* Load the Sent Subfolder Options into an array. */ + $optgrp = _("Sent Subfolders Options"); + $optvals = array(); + + $optvals[] = array( + 'name' => 'sent_subfolders_setting', + 'caption' => _("Use Sent Subfolders"), + 'type' => SMOPT_TYPE_STRLIST, + 'refresh' => SMOPT_REFRESH_FOLDERLIST, + 'posvals' => array(SMPREF_SENT_SUBFOLDERS_DISABLED => _("Disabled"), + SMPREF_SENT_SUBFOLDERS_MONTHLY => _("Monthly"), + SMPREF_SENT_SUBFOLDERS_QUARTERLY => _("Quarterly"), + SMPREF_SENT_SUBFOLDERS_YEARLY => _("Yearly")), + 'save' => 'save_option_sent_subfolders_setting' + ); + + $sent_subfolders_base_values = array(); + foreach ($boxes as $folder) { + if (strtolower($folder['unformatted']) != 'inbox') { + $real_value = $folder['unformatted-dm']; + $disp_value = str_replace(' ', ' ', $folder['formatted']); + $sent_subfolders_base_values[$real_value] = $disp_value; + } + } + + $optvals[] = array( + 'name' => 'sent_subfolders_base', + 'caption' => _("Base Sent Folder"), + 'type' => SMOPT_TYPE_STRLIST, + 'refresh' => SMOPT_REFRESH_FOLDERLIST, + 'posvals' => $sent_subfolders_base_values + ); + + /* Add our option data to the global array. */ + $optpage_data['grps'][SMOPT_GRP_SENT_SUBFOLDERS] = $optgrp; + $optpage_data['vals'][SMOPT_GRP_SENT_SUBFOLDERS] = $optvals; +} + +function save_option_sent_subfolders_setting($option) { + global $data_dir, $username, $use_sent_subfolders; + + /* Set use_sent_subfolders as either on or off. */ + if ($option->new_value == SMPREF_SENT_SUBFOLDERS_DISABLED) { + setPref($data_dir, $username, 'use_sent_subfolders', SMPREF_OFF); + } else { + setPref($data_dir, $username, 'use_sent_subfolders', SMPREF_ON); + setPref($data_dir, $username, 'move_to_sent', SMPREF_ON); + } + + /* Now just save the option as normal. */ + save_option($option); +} + +function sent_subfolders_update_sentfolder() { + global $sent_folder, $delimiter, $auto_create_special, $auto_create_done; + global $sent_subfolders_base, $sent_subfolders_setting; + global $username, $data_dir, $key, $imapServerAddress, $imapPort; + global $use_sent_subfolders, $move_to_sent; + + if ($use_sent_subfolders && $move_to_sent) { + $year = date('Y'); + $month = date('m'); + $quarter = sent_subfolder_getQuarter($month); + + switch ($sent_subfolders_setting) { + case SMPREF_SENT_SUBFOLDERS_YEARLY: + $sent_subfolder = $sent_subfolders_base + . $delimiter . $year; + $year_folder = $sent_subfolder; + break; + case SMPREF_SENT_SUBFOLDERS_QUARTERLY: + $sent_subfolder = $sent_subfolders_base + . $delimiter . $year + . $delimiter . $quarter; + $year_folder = $sent_subfolders_base + . $delimiter . $year; + break; + case SMPREF_SENT_SUBFOLDERS_MONTHLY: + $sent_subfolder = $sent_subfolders_base + . $delimiter . $year + . $delimiter . $month; + $year_folder = $sent_subfolders_base + . $delimiter . $year; + break; + case SMPREF_SENT_SUBFOLDERS_DISABLED: + default: + $sent_subfolder = $sent_folder; + $year_folder = $sent_folder; + } + + /* If this folder is NOT the current sent folder, update stuff. */ + if ($sent_subfolder != $sent_folder) { + /* First, update the sent folder. */ + setPref($data_dir, $username, 'sent_folder', $sent_subfolder); + setPref($data_dir, $username, 'move_to_sent', SMPREF_ON); + $sent_folder = $sent_subfolder; + $move_to_sent = SMPREF_ON; + + /* Auto-create folders, if they do not yet exist. */ + if ($sent_folder != 'none') { + /* Create the imap connection. */ + $ic = sqimap_login + ($username, $key, $imapServerAddress, $imapPort, 10); + + /* Auto-create the year folder, if it does not yet exist. */ + if (!sqimap_mailbox_exists($ic, $year_folder)) { + sqimap_mailbox_create($ic, $year_folder, ''); + } else if (!sqimap_mailbox_is_subscribed($ic, $year_folder)) { + sqimap_subscribe($ic, $year_folder); + } + + /* Auto-create the subfolder, if it does not yet exist. */ + if (!sqimap_mailbox_exists($ic, $sent_folder)) { + sqimap_mailbox_create($ic, $sent_folder, ''); + } else if (!sqimap_mailbox_is_subscribed($ic, $sent_folder)) { + sqimap_subscribe($ic, $sent_folder); + } + + /* Close the imap connection. */ + sqimap_logout($ic); + } + } + } +} + +function sent_subfolder_getQuarter($month) { + switch ($month) { + case '01': + case '02': + case '03': $result = '1'; break; + case '04': + case '05': + case '06': $result = '2'; break; + case '07': + case '08': + case '09': $result = '3'; break; + case '10': + case '11': + case '12': $result = '4'; break; + default: $result = 'ERR'; + } + + /* Return the current quarter. */ + return ('Q' . $result); +} + +?> diff --git a/src/compose.php b/src/compose.php index 27dee5d9..bc3ab060 100644 --- a/src/compose.php +++ b/src/compose.php @@ -41,13 +41,11 @@ require_once('../functions/smtp.php'); require_once('../functions/display_messages.php'); require_once('../functions/plugin.php'); - if (!isset($attachments)) - { + if (!isset($attachments)) { $attachments = array(); session_register('attachments'); } - // This function is used when not sending or adding attachments function newMail () { global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body, diff --git a/src/left_main.php b/src/left_main.php index a3f2dfad..f3458cff 100644 --- a/src/left_main.php +++ b/src/left_main.php @@ -234,14 +234,12 @@ displayHtmlHeader( 'SquirrelMail', $xtra ); /* If requested and not yet complete, attempt to autocreate folders. */ if ($auto_create_special && !isset($auto_create_done)) { - $autocreate = array( $sent_folder, - $trash_folder, - $draft_folder ); + $autocreate = array($sent_folder, $trash_folder, $draft_folder); foreach( $autocreate as $folder ) { - if ($folder != '' && $folder != 'none') { + if (($folder != '') && ($folder != 'none')) { if ( !sqimap_mailbox_exists($imapConnection, $folder)) { sqimap_mailbox_create($imapConnection, $folder, ''); - } elseif ( !sqimap_mailbox_is_subscribed($imapConnection, $folder)) { + } else if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) { sqimap_subscribe($imapConnection, $folder); } } diff --git a/src/options.php b/src/options.php index 7cdb01fb..1d5e8fcc 100644 --- a/src/options.php +++ b/src/options.php @@ -97,29 +97,34 @@ $optpage_loader = ''; switch ($optpage) { case SMOPT_PAGE_MAIN: break; case SMOPT_PAGE_PERSONAL: - $optpage_name = _("Personal Information"); - $optpage_file = '../src/options_personal.php'; - $optpage_loader = 'load_optpage_data_personal'; + $optpage_name = _("Personal Information"); + $optpage_file = '../src/options_personal.php'; + $optpage_loader = 'load_optpage_data_personal'; + $optpage_loadhook = 'optpage_loadhook_personal'; break; case SMOPT_PAGE_DISPLAY: $optpage_name = _("Display Preferences"); $optpage_file = '../src/options_display.php'; $optpage_loader = 'load_optpage_data_display'; + $optpage_loadhook = 'optpage_loadhook_display'; break; case SMOPT_PAGE_HIGHLIGHT: $optpage_name = _("Message Highlighting"); $optpage_file = '../src/options_highlight.php'; $optpage_loader = 'load_optpage_data_highlight'; + $optpage_loadhook = 'optpage_loadhook_highlight'; break; case SMOPT_PAGE_FOLDER: $optpage_name = _("Folder Preferences"); $optpage_file = '../src/options_folder.php'; $optpage_loader = 'load_optpage_data_folder'; + $optpage_loadhook = 'optpage_loadhook_folder'; break; case SMOPT_PAGE_ORDER: $optpage_name = _("Index Order"); $optpage_file = '../src/options_order.php'; $optpage_loader = 'load_optpage_data_order'; + $optpage_loadhook = 'optpage_loadhook_order'; break; default: do_hook('optpage_set_loadinfo'); } @@ -135,6 +140,7 @@ if ($optpage != SMOPT_PAGE_MAIN) { /* Assemble the data for this option page. */ $optpage_data = array(); $optpage_data = $optpage_loader(); + do_hook($optpage_loadhook); $optpage_data['options'] = create_option_groups($optpage_data['grps'], $optpage_data['vals']); } -- 2.25.1