浏览代码

Added sent_subfolders plugin, tweaked config stuff, other stuff.

thomppj 23 年之前
父节点
当前提交
fab2b3dba0
共有 9 个文件被更改,包括 1021 次插入652 次删除
  1. 259 241
      config/conf.pl
  2. 431 379
      config/config_default.php
  3. 53 10
      functions/imap_mailbox.php
  4. 18 4
      functions/mailbox_display.php
  5. 8 7
      functions/plugin.php
  6. 239 0
      plugins/sent_subfolders/setup.php
  7. 1 3
      src/compose.php
  8. 3 5
      src/left_main.php
  9. 9 3
      src/options.php

+ 259 - 241
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 = <FILE>) {
-      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 = <STDIN>;
       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 = <FILE>) {
-      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 = <STDIN>;
       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 = <FILE>) {
-   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 = <FILE>) && ($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 = <FILE>) && ($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 "<?php\n\t/** SquirrelMail configuration\n";
-   print FILE "\t ** Created using the configure script, conf.pl\n\t **/\n\n";
-   
-   print FILE "if (defined('config_php'))\n   return;\n";
-   print FILE "define('config_php', true);\n\n";
+   $tab = "    ";
+   open (CF, ">config.php");
 
-   print FILE "\tglobal \$print_config_version, \$config_version, \$config_use_color;\n";
+   print CF "<?php\n";
+   print CF "\n";
 
-   if ($print_config_version) {
-      print FILE "\t\$config_version = \"$print_config_version\";\n";
-   }
-   print FILE "\t\$config_use_color = $config_use_color;\n"; 
-   print FILE "\n";
-
-   print FILE "\tglobal \$org_name, \$org_logo, \$org_title, \$signout_page;\n";
-   print FILE "\t\$org_name   = \"$org_name\";\n";
-   print FILE "\t\$org_logo   = \"$org_logo\";\n";
-   print FILE "\t\$org_title  = \"$org_title\";\n";
-   print FILE "\t\$signout_page  = \"$signout_page\";\n";
-
-   print FILE "\n";
-
-   print FILE "\tglobal \$domain, \$imapServerAddress, \$imapPort;\n";
-   print FILE "\tglobal \$useSendmail, \$smtpServerAddress, \$smtpPort;\n";
-   print FILE "\tglobal \$sendmail_path, \$use_authenticated_smtp, \$imap_server_type;\n";
-   print FILE "\tglobal \$invert_time, \$optional_delimiter;\n";
-   print FILE "\t\$domain                 = \"$domain\";\n";
-   print FILE "\t\$imapServerAddress      = \"$imapServerAddress\";\n";
-   print FILE "\t\$imapPort               =  $imapPort;\n";
-   print FILE "\t\$useSendmail            =  $useSendmail;\n";
-   print FILE "\t\$smtpServerAddress      = \"$smtpServerAddress\";\n";
-   print FILE "\t\$smtpPort               =  $smtpPort;\n";
-   print FILE "\t\$sendmail_path          = \"$sendmail_path\";\n";
-   print FILE "\t\$use_authenticated_smtp = $use_authenticated_smtp;\n";
-   print FILE "\t\$imap_server_type       = \"$imap_server_type\";\n";
-   print FILE "\t\$invert_time            = $invert_time;\n";
-   print FILE "\t\$optional_delimiter     = \"$optional_delimiter\";\n";
+   print CF "/**\n";
+   print CF " * SquirrelMail Configuration File\n";
+   print CF " * Created using the configure script, conf.pl\n";
+   print CF " */\n";
+   print CF "\n";
    
-   print FILE "\n";
-
-   print FILE "\tglobal \$default_folder_prefix;\n";
-   print FILE "\tglobal \$trash_folder, \$default_move_to_trash;\n";
-   print FILE "\tglobal \$sent_folder, \$default_move_to_sent;\n";
-   print FILE "\tglobal \$draft_folder, \$default_save_to_draft;\n";
-   print FILE "\tglobal \$show_prefix_option, \$list_special_folders_first;\n";
-   print FILE "\tglobal \$use_special_folder_color, \$auto_expunge, \$default_sub_of_inbox;\n";
-   print FILE "\tglobal \$show_contain_subfolders_option, \$default_unseen_notify;\n";
-   print FILE "\tglobal \$default_unseen_type, \$auto_create_special;\n";
-   print FILE "\t\$default_folder_prefix            = \"$default_folder_prefix\";\n";
-   print FILE "\t\$trash_folder                     = \"$trash_folder\";\n";
-   print FILE "\t\$sent_folder                      = \"$sent_folder\";\n";
-   print FILE "\t\$draft_folder                     = \"$draft_folder\";\n";
-   print FILE "\t\$default_move_to_trash            =  $default_move_to_trash;\n";
-   print FILE "\t\$default_move_to_sent             =  $default_move_to_sent;\n";
-   print FILE "\t\$default_save_as_draft            =  $default_save_as_draft;\n";
-   print FILE "\t\$show_prefix_option               =  $show_prefix_option;\n";
-   print FILE "\t\$list_special_folders_first       =  $list_special_folders_first;\n";
-   print FILE "\t\$use_special_folder_color         =  $use_special_folder_color;\n";
-   print FILE "\t\$auto_expunge                     =  $auto_expunge;\n";
-   print FILE "\t\$default_sub_of_inbox             =  $default_sub_of_inbox;\n";
-   print FILE "\t\$show_contain_subfolders_option   =  $show_contain_subfolders_option;\n";
-   print FILE "\t\$default_unseen_notify            =  $default_unseen_notify;\n";
-   print FILE "\t\$default_unseen_type              =  $default_unseen_type;\n";
-   print FILE "\t\$auto_create_special              =  $auto_create_special;\n";
-   print FILE "\n";
-
-   print FILE "\tglobal \$default_charset;\n";
-   print FILE "\tglobal \$data_dir, \$attachment_dir, \$dir_hash_level;\n";
-   print FILE "\tglobal \$default_left_size, \$force_username_lowercase;\n";
-   print FILE "\tglobal \$default_use_priority, \$hide_sm_attributions;\n";
-   print FILE "\t\$default_charset          = \"$default_charset\";\n";
-   print FILE "\t\$data_dir                 = \"$data_dir\";\n";
-   print FILE "\t\$attachment_dir           = \"$attachment_dir\";\n";
-   print FILE "\t\$dir_hash_level           = $dir_hash_level;\n";
-   print FILE "\t\$default_left_size        =  $default_left_size;\n";
-   print FILE "\t\$force_username_lowercase = $force_username_lowercase;\n";
-   print FILE "\t\$default_use_priority     = $default_use_priority;\n";
-   print FILE "\t\$hide_sm_attributions     = $hide_sm_attributions;\n";
-
-   print FILE "\n";
-
-   print FILE "\tglobal \$plugins;\n";
+   print CF "global \$config_version, \$config_use_color;\n";
+   if ($print_config_version) {
+      print CF "\$config_version = '$print_config_version';\n";
+   }
+   print CF "\$config_use_color = $config_use_color;\n"; 
+   print CF "\n";
+
+   print CF "global \$org_name, \$org_logo, \$org_title, \$signout_page;\n";
+   print CF "\$org_name      = \"$org_name\";\n";
+   print CF "\$org_logo      = '$org_logo';\n";
+   print CF "\$org_title     = \"$org_title\";\n";
+   print CF "\$signout_page  = '$signout_page';\n";
+   print CF "\n";
+
+   print CF "global \$motd;\n";
+   print CF "\$motd = '$motd';\n";
+   print CF "\n";
+
+   print CF "global \$squirrelmail_default_language;\n";
+   print CF "\$squirrelmail_default_language = '$squirrelmail_default_language';\n";
+   print CF "\n";
+
+   print CF "global \$domain, \$imapServerAddress, \$imapPort;\n";
+   print CF "global \$useSendmail, \$smtpServerAddress, \$smtpPort;\n";
+   print CF "global \$sendmail_path, \$use_authenticated_smtp;\n";
+   print CF "global \$imap_server_type, \$invert_time;\n";
+   print CF "global \$optional_delimiter;\n";
+   print CF "\$domain                 = '$domain';\n";
+   print CF "\$imapServerAddress      = '$imapServerAddress';\n";
+   print CF "\$imapPort               = $imapPort;\n";
+   print CF "\$useSendmail            = $useSendmail;\n";
+   print CF "\$smtpServerAddress      = '$smtpServerAddress';\n";
+   print CF "\$smtpPort               = $smtpPort;\n";
+   print CF "\$sendmail_path          = '$sendmail_path';\n";
+   print CF "\$use_authenticated_smtp = $use_authenticated_smtp;\n";
+   print CF "\$imap_server_type       = '$imap_server_type';\n";
+   print CF "\$invert_time            = $invert_time;\n";
+   print CF "\$optional_delimiter     = '$optional_delimiter';\n";
+   print CF "\n";
+
+   print CF "global \$default_folder_prefix;\n";
+   print CF "global \$trash_folder, \$default_move_to_trash;\n";
+   print CF "global \$sent_folder, \$default_move_to_sent;\n";
+   print CF "global \$draft_folder, \$default_save_to_draft;\n";
+   print CF "global \$show_prefix_option, \$list_special_folders_first;\n";
+   print CF "global \$use_special_folder_color, \$auto_expunge;\n";
+   print CF "global \$default_sub_of_inbox;\n";
+   print CF "global \$show_contain_subfolders_option;\n";
+   print CF "global \$default_unseen_notify;\n";
+   print CF "global \$default_unseen_type, \$auto_create_special;\n";
+   print CF "\$default_folder_prefix          = '$default_folder_prefix';\n";
+   print CF "\$trash_folder                   = '$trash_folder';\n";
+   print CF "\$sent_folder                    = '$sent_folder';\n";
+   print CF "\$draft_folder                   = '$draft_folder';\n";
+   print CF "\$default_move_to_trash          = $default_move_to_trash;\n";
+   print CF "\$default_move_to_sent           = $default_move_to_sent;\n";
+   print CF "\$default_save_as_draft          = $default_save_as_draft;\n";
+   print CF "\$show_prefix_option             = $show_prefix_option;\n";
+   print CF "\$list_special_folders_first     = $list_special_folders_first;\n";
+   print CF "\$use_special_folder_color       = $use_special_folder_color;\n";
+   print CF "\$auto_expunge                   = $auto_expunge;\n";
+   print CF "\$default_sub_of_inbox           = $default_sub_of_inbox;\n";
+   print CF "\$show_contain_subfolders_option = $show_contain_subfolders_option;\n";
+   print CF "\$default_unseen_notify          = $default_unseen_notify;\n";
+   print CF "\$default_unseen_type            = $default_unseen_type;\n";
+   print CF "\$auto_create_special            = $auto_create_special;\n";
+   print CF "\n";
+
+   print CF "global \$default_charset;\n";
+   print CF "global \$data_dir, \$attachment_dir, \$dir_hash_level;\n";
+   print CF "global \$default_left_size, \$force_username_lowercase;\n";
+   print CF "global \$default_use_priority, \$hide_sm_attributions;\n";
+   print CF "\$default_charset          = '$default_charset';\n";
+   print CF "\$data_dir                 = '$data_dir';\n";
+   print CF "\$attachment_dir           = \"$attachment_dir\";\n";
+   print CF "\$dir_hash_level           = $dir_hash_level;\n";
+   print CF "\$default_left_size        = $default_left_size;\n";
+   print CF "\$force_username_lowercase = $force_username_lowercase;\n";
+   print CF "\$default_use_priority     = $default_use_priority;\n";
+   print CF "\$hide_sm_attributions     = $hide_sm_attributions;\n";
+   print CF "\n";
+
+   print CF "global \$plugins;\n";
    for ($ct=0; $ct <= $#plugins; $ct++) {
-      print FILE "\t\$plugins[$ct] = \"$plugins[$ct]\";\n";
+      print CF "\$plugins[$ct] = '$plugins[$ct]';\n";
    }
-   
-   print FILE "\n";
+   print CF "\n";
 
-   print FILE "\tglobal \$theme_css, \$theme;\n";
-   print FILE "\t\$theme_css = \"$theme_css\";\n";
+   print CF "global \$theme_css, \$theme;\n";
+   print CF "\$theme_css = '$theme_css';\n";
    for ($count=0; $count <= $#theme_name; $count++) {
-      print FILE "\t\$theme[$count][\"PATH\"] = \"$theme_path[$count]\";\n";
-      print FILE "\t\$theme[$count][\"NAME\"] = \"$theme_name[$count]\";\n";
+      print CF "\$theme[$count]['PATH'] = '$theme_path[$count]';\n";
+      print CF "\$theme[$count]['NAME'] = '$theme_name[$count]';\n";
    }
-   
-   print FILE "\n";
+   print CF "\n";
 
    if ($default_use_javascript_addr_book ne "true") {
       $default_use_javascript_addr_book = "false";
    }   
-   print FILE "\tglobal \$default_use_javascript_addr_book, \$ldap_server;\n";
-   print FILE "\t\$default_use_javascript_addr_book = $default_use_javascript_addr_book;\n";
+   print CF "global \$default_use_javascript_addr_book, \$ldap_server;\n";
+   print CF "\$default_use_javascript_addr_book = $default_use_javascript_addr_book;\n";
    for ($count=0; $count <= $#ldap_host; $count++) {
-      print FILE "\t\$ldap_server[$count] = Array(\n";
-      print FILE "\t\t\t\"host\" => \"$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 {

+ 431 - 379
config/config_default.php

@@ -1,390 +1,442 @@
 <?php
-//
-//  BEFORE EDITING THIS FILE!
-//
-//  Don't edit this file directly.  Copy it to config.php before you
-//  edit it.  However, it is best to use the configuration script
-//  conf.pl if at all possible.  That is the easiest and cleanest way
-//  to configure.
-//
-
-    // This makes sure we don't load it dozens of times
-    // don't change this
-    if (defined('config_php'))
-       return;
-    define('config_php', true);
-
-    // don't change
-    global $config_version;
-    $config_version = "x64";
-
-//  Organization's logo picture (blank if none)
-    global $org_logo;
-    $org_logo = "../images/sm_logo.png";
-
-//  Organization's name
-    global $org_name;
-    $org_name = "SquirrelMail";
-
-//  Webmail Title
-//  This is the title that goes at the top of the browser window
-    global $org_title;
-    $org_title = "SquirrelMail $version";
+/**
+ * BEFORE EDITING THIS FILE!
+ *
+ * Don't edit this file directly.  Copy it to config.php before you
+ * edit it.  However, it is best to use the configuration script
+ * conf.pl if at all possible.  That is the easiest and cleanest way
+ * to configure.
+ */
+
+/* Do not change this value. */
+global $config_version;
+$config_version = '1.2.0';
+
+/* Organization's logo picture (blank if none) */
+global $org_logo;
+$org_logo = '../images/sm_logo.png';
+
+/* Organization's name */
+global $org_name;
+$org_name = 'SquirrelMail';
+
+/**
+ * Webmail Title
+ *   This is the web page title that appears at the top of the browser window.
+ */
+global $org_title;
+$org_title = 'SquirrelMail $version';
     
-//  Default language
-//  This is the default language.  It is used as a last resort if SquirrelMail
-//  can't figure out which language to display.
-//  Use the two-letter code.
-    global $squirrelmail_default_language;
-    $squirrelmail_default_language = "en";
-
-//  The server that your imap server is on
-    global $imapServerAddress, $imapPort;
-    $imapServerAddress = "localhost";
-    $imapPort = 143;
-
-//  The domain where your email address is.
-//   Example:  in "luke@usa.om.org", usa.om.org is the domain.
-//             this is for all the messages sent out.  Reply address
-//             is generated by $username@$domain
-    global $domain;
-    $domain = "mydomain.com";
-
-//  Your SMTP server and port number (usually the same as the IMAP server)
-    global $smtpServerAddress, $smtpPort;
-    $smtpServerAddress = "localhost";
-    $smtpPort = 25;
-
-//  Uncomment this if you want to deliver locally using sendmail instead
-//  of connecting to a SMTP-server
-//    global $useSendmail, $sendmail_path;
-//    $useSendmail = true;
-//    $sendmail_path = "/usr/sbin/sendmail";
-
-//  This is displayed right after they log in
-   global $motd;
-   $motd = "";
-
-//  Whether or not to use a special color for special folders.  If not, special
-//  folders will be the same color as the other folders
-    global $use_special_folder_color;
-    $use_special_folder_color = true;
-
-//  The type of IMAP server you are running
-//  Valid type are the following (case is important).
-//  
-//  courier
-//  cyrus
-//  exchange
-//  uw
-//  other
-    global $imap_server_type;
-    $imap_server_type = "cyrus";
-
-// Rather than going to the signout.php page (which only allows you
-// to sign back in), setting signout_page allows you to sign
-// the user out and then redirect to whatever page you want.
-// For instance, the following would return the user to your
-// home page:    $signout_page = "/";
-// Set to the empty string to continue to use the default signout page.
-    global $signout_page;
-    $signout_page = "";
-
-//  Many servers store mail in your home directory.  With this, they
-//  store them in a subdirectory: mail/ or Mail/, etc.  If your
-//  server does this, please set this to what the default mail folder
-//  should be.  This is still a user preference, so they can change
-//  it if it is different for each user.
-//
-//  Example:
-//     $default_folder_prefix = "mail/";
-//        -- or --
-//     $default_folder_prefix = "Mail/folders/";
-//
-//  If you do not use this, please set it to "".
-    global $default_folder_prefix;
-    $default_folder_prefix = "";
-//  If you do not wish to give them the option to change this, set it to false.
-//  Otherwise, if it is true, they can change the folder prefix to be anything.
-    global $show_prefix_option;
-    $show_prefix_option = false;
-
-//  The following are related to deleting messages.
-//    $move_to_trash
-//         - if this is set to "true", when "delete" is pressed, it
-//           will attempt to move the selected messages to the folder
-//           named $trash_folder. If it's set to "false", we won't even
-//           attempt to move the messages, just delete them.
-//    $trash_folder
-//         - This is the path to the default trash folder. For Cyrus
-//           IMAP, it would be "INBOX.Trash", but for UW it would be
-//           "Trash". We need the full path name here.
-//    $auto_expunge
-//         - If this is true, when a message is moved or copied, the
-//           source mailbox will get expunged, removing all messages
-//           marked "Deleted".
-//    $sent_folder
-//         - This is the path to where Sent messages will be stored.
-
-    global $default_move_to_trash, $default_move_to_sent, $trash_folder,
-        $auto_expunge, $sent_folder, $draft_folder, $default_save_as_draft;
-    $default_move_to_trash = true;
-    $default_move_to_sent  = true;
-    $default_save_as_draft = true;
-    $trash_folder = "INBOX.Trash";
-    $auto_expunge = true;
-    $sent_folder = "INBOX.Sent";
-    $draft_folder = "INBOX.Drafts";
-
-//  Special Folders are folders that can't be manipulated like normal
-//  user created folders can. A couple of examples would be
-//  "INBOX.Trash", "INBOX.Drafts". We have them set to Netscape's
-//  default mailboxes, but this obviously can be changed. To add one,
-//  just add a new number to the array.
-
-    global $special_folders;
-    $special_folders[0] = "INBOX";   // The first one has to be the inbox (whatever the name is)
-    $special_folders[1] = $trash_folder;
-    $special_folders[2] = $sent_folder;
-    $special_folders[3] = "INBOX.Drafts";
-    $special_folders[4] = "INBOX.Templates";
-
-//  Should I create the Sent and Trash folders automatically for a new
-//  user that doesn't already have them created?
-    global $auto_create_special;
-    $auto_create_special = true;
-
-//  Whether or not to list the special folders first  (true/false)
-    global $list_special_folders_first;
-    $list_special_folders_first = true;
-
-//  Are all your folders subfolders of INBOX (i.e.  cyrus IMAP server)
-//  If you are not sure, set it to false.
-    global $default_sub_of_inbox;
-    $default_sub_of_inbox = true;
-
-//  Some IMAP daemons (UW) handle folders weird. They only allow a
-//  folder to contain either messages or other folders, not both at
-//  the same time. This option controls whether or not to display an
-//  option during folder creation. The option toggles which type of
-//  folder it should be.
-//
-//  If this option confuses you, make it "true". You can't hurt
-//  anything if it's true, but some servers will respond weird if it's
-//  false. (Cyrus works fine whether it's true OR false).
-    global $show_contain_subfolders_option;
-    $show_contain_subfolders_option = false;
-
-//  This option controls what character set is used when sending mail
-//  and when sending HTMl to the browser. Do not set this to US-ASCII,
-//  use ISO-8859-1 instead. For cyrillic it is best to use KOI8-R,
-//  since this implementation is faster than the alternatives.
-    global $default_charset;
-    $default_charset = "iso-8859-1";
-
-//  Path to the data/ directory
-//    It is a possible security hole to have a writable directory
-//    under the web server's root directory (ex: /home/httpd/html).
-//    For this reason, it is possible to put the data directory
-//    anywhere you would like. The path name can be absolute or
-//    relative (to the config directory). It doesn't matter. Here are
-//    two examples:
-//
-//  Absolute:
-//    $data_dir = "/usr/local/squirrelmail/data/";
-//
-//  Relative (to the config directory):
-//    $data_dir = "../data/";
-    global $data_dir;
-    $data_dir = "../data/";
-
-//  Path to directory used for storing attachments while a mail is
-//  being sent. There are a few security considerations regarding this
-//  directory:
-//    - It should have the permission 733 (rwx-wx-wx) to make it
-//      impossible for a random person with access to the webserver to
-//      list files in this directory. Confidential data might be laying
-//      around there
-//    - Since the webserver is not able to list the files in the content
-//      is also impossible for the webserver to delete files lying around 
-//      there for too long.
-//    - It should probably be another directory than data_dir.
-    global $attachment_dir;
-    $attachment_dir = $data_dir;
-
-// Hash level used for data directory.
-    global $dir_hash_level;
-    $dir_hash_level = 0;
-
-//  This is the default size of the folder list.  Default is 150,
-//  but you can set it to whatever you wish.
-   global $default_left_size;
-   $default_left_size = 150;
-
-//  Some IMAP servers allow a username (like "bob") to log in if they use
-//  uppercase in their name (like "Bob" or "BOB").  This creates extra
-//  preference files.  Toggling this option to true will transparently
-//  change all usernames to lowercase.
-   global $force_username_lowercase;
-   $force_username_lowercase = false;
-
-
-//  Themes
-//     You can define your own theme and put it in this directory.  You must
-//     call it as the example below.  You can name the theme whatever you
-//     want.  For an example of a theme, see the ones included in the config
-//     directory.
-//
-//  To add a new theme to the options that users can choose from, just add
-//  a new number to the array at the bottom, and follow the pattern.
-    global $theme;
-
-    // The first one HAS to be here, and is your system's default theme.
-    // It can be any theme you want
-    $theme[0]["PATH"] = "../themes/default_theme.php";
-    $theme[0]["NAME"] = "Default";
-
-    $theme[1]["PATH"] = "../themes/plain_blue_theme.php";
-    $theme[1]["NAME"] = "Plain Blue";
-
-    $theme[2]["PATH"] = "../themes/sandstorm_theme.php";
-    $theme[2]["NAME"] = "Sand Storm";
-
-    $theme[3]["PATH"] = "../themes/deepocean_theme.php";
-    $theme[3]["NAME"] = "Deep Ocean";
-
-    $theme[4]["PATH"] = "../themes/slashdot_theme.php";
-    $theme[4]["NAME"] = "Slashdot";
-
-    $theme[5]["PATH"] = "../themes/purple_theme.php";
-    $theme[5]["NAME"] = "Purple";
-
-    $theme[6]["PATH"] = "../themes/forest_theme.php";
-    $theme[6]["NAME"] = "Forest";
-
-    $theme[7]["PATH"] = "../themes/ice_theme.php";
-    $theme[7]["NAME"] = "Ice";
-
-    $theme[8]["PATH"] = "../themes/seaspray_theme.php";
-    $theme[8]["NAME"] = "Sea Spray";
-
-    $theme[9]["PATH"] = "../themes/bluesteel_theme.php";
-    $theme[9]["NAME"] = "Blue Steel";
-
-    $theme[10]["PATH"] = "../themes/dark_grey_theme.php";
-    $theme[10]["NAME"] = "Dark Grey";
-
-    $theme[11]["PATH"] = "../themes/high_contrast_theme.php";
-    $theme[11]["NAME"] = "High Contrast";
-
-    $theme[12]["PATH"] = "../themes/black_bean_burrito_theme.php";
-    $theme[12]["NAME"] = "Black Bean Burrito";
-
-    $theme[13]["PATH"] = "../themes/servery_theme.php";
-    $theme[13]["NAME"] = "Servery";
-
-    $theme[14]["PATH"] = "../themes/maize_theme.php";
-    $theme[14]["NAME"] = "Maize";
-
-    $theme[15]["PATH"] = "../themes/bluesnews_theme.php";
-    $theme[15]["NAME"] = "BluesNews";
-    
-    $theme[16]["PATH"] = "../themes/deepocean2_theme.php";
-    $theme[16]["NAME"] = "Deep Ocean 2";
+/**
+ * Default language
+ *   This is the default language. It is used as a last resort
+ *   if SquirrelMail can't figure out which language to display.
+ *   Use the two-letter code.
+ */
+global $squirrelmail_default_language;
+$squirrelmail_default_language = 'en';
+
+/* The dns name and port for your imap server. */
+global $imapServerAddress, $imapPort;
+$imapServerAddress = 'localhost';
+$imapPort = 143;
+
+/**
+ * The domain part of local email addresses.
+ *   This is for all messages sent out from this server.
+ *   Reply address is generated by $username@$domain
+ * Example: In bob@foo.com, foo.com is the domain.
+ */
+global $domain;
+$domain = 'mydomain.com';
+
+/* Your SMTP server and port number (usually the same as the IMAP server). */
+global $smtpServerAddress, $smtpPort;
+$smtpServerAddress = 'localhost';
+$smtpPort = 25;
+
+/**
+ * Uncomment this if you want to deliver locally using sendmail
+ * instead of connecting to a SMTP-server.
+ */
+#global $useSendmail, $sendmail_path;
+#$useSendmail = true;
+#$sendmail_path = '/usr/sbin/sendmail';
+
+/* This is a message that is displayed immediately after a user logs in. */
+global $motd;
+$motd = '';
+
+/**
+ * Whether or not to use a special color for special folders. If not,
+ * special folders will be the same color as the other folders.
+ */
+global $use_special_folder_color;
+$use_special_folder_color = true;
+
+/**
+ * The type of IMAP server you are running.
+ * Valid type are the following (case is important):
+ *   courier
+ *   cyrus
+ *   exchange
+ *   uw
+ *   other
+ */
+global $imap_server_type;
+$imap_server_type = 'cyrus';
+
+/**
+ * Rather than going to the signout.php page (which only allows you
+ * to sign back in), setting signout_page allows you to sign the user
+ * out and then redirect to whatever page you want. For instance,
+ * the following would return the user to your home page:
+ *   $signout_page = '/';
+ * Set to the empty string to continue to use the default signout page.
+ */
+global $signout_page;
+$signout_page = '';
+
+/**
+ * Many servers store mail in your home directory. With this, they
+ * store them in a subdirectory: mail/ or Mail/, etc. If your server
+ * does this, please set this to what the default mail folder should
+ * be. This is still a user preference, so they can change it if it
+ * is different for each user.
+ *
+ * Example:
+ *     $default_folder_prefix = 'mail/';
+ *        -- or --
+ *     $default_folder_prefix = 'Mail/folders/';
+ *
+ * If you do not use this, set it to the empty string.
+ */
+global $default_folder_prefix;
+$default_folder_prefix = '';
+
+/**
+ * If you do not wish to give them the option to change this, set it
+ * to false. Otherwise, if it is true, they can change the folder prefix
+ * to be anything.
+ */
+global $show_prefix_option;
+$show_prefix_option = false;
+
+/**
+ * The following are related to deleting messages.
+ *   $move_to_trash
+ *      if this is set to 'true', when 'delete' is pressed, it
+ *      will attempt to move the selected messages to the folder
+ *      named $trash_folder. If it's set to 'false', we won't even
+ *      attempt to move the messages, just delete them.
+ *   $trash_folder
+ *      This is the path to the default trash folder. For Cyrus
+ *      IMAP, it would be 'INBOX.Trash', but for UW it would be
+ *      'Trash'. We need the full path name here.
+ *   $auto_expunge
+ *      If this is true, when a message is moved or copied, the
+ *      source mailbox will get expunged, removing all messages
+ *      marked 'Deleted'.
+ *   $sent_folder
+ *      This is the path to where Sent messages will be stored.
+ */
+global $default_move_to_trash, $default_move_to_sent, $default_save_as_draft;
+global $trash_folder, $sent_folder, $draft_folder, $auto_expunge;
+$default_move_to_trash = true;
+$default_move_to_sent  = true;
+$default_save_as_draft = true;
+$trash_folder = 'INBOX.Trash';
+$sent_folder  = 'INBOX.Sent';
+$draft_folder = 'INBOX.Drafts';
+$auto_expunge = true;
+
+/**
+ * Special Folders are folders that can't be manipulated like normal user
+ * created folders can. A couple of examples would be 'INBOX.Trash', 
+ * 'INBOX.Drafts'. We have them set to Netscape's default mailboxes, but
+ * this obviously can be changed. To add one, just add a new number to the
+ * array.
+ */
+global $special_folders;
+$special_folders[0] = 'INBOX'; /* The first special folder should always */
+                               /* be the inbox (whatever it is named).   */
+$special_folders[1] = $trash_folder;
+$special_folders[2] = $sent_folder;
+$special_folders[3] = $draft_folder;
+$special_folders[4] = 'INBOX.Templates';
+
+/**
+ * Should I create the Sent and Trash folders automatically for
+ * a new user that doesn't already have them created?
+ */
+global $auto_create_special;
+$auto_create_special = true;
+
+/* Whether or not to list the special folders first (true/false). */
+global $list_special_folders_first;
+$list_special_folders_first = true;
+
+/**
+ * Are all your folders subfolders of INBOX (i.e. cyrus IMAP server).
+ * If you are unsure, set it to false.
+ */
+global $default_sub_of_inbox;
+$default_sub_of_inbox = true;
+
+/**
+ * Some IMAP daemons (UW) handle folders weird. They only allow a
+ * folder to contain either messages or other folders, not both at
+ * the same time. This option controls whether or not to display an
+ * option during folder creation. The option toggles which type of
+ * folder it should be.
+ *
+ * If this option confuses you, just set it to 'true'. You can not hurt 
+ * anything if it's true, but some servers will respond weird if it's
+ * false. (Cyrus works fine whether it's true OR false).
+ */
+global $show_contain_subfolders_option;
+$show_contain_subfolders_option = false;
+
+/**
+ * This option controls what character set is used when sending mail
+ * and when sending HTMl to the browser. Do not set this to US-ASCII,
+ * use ISO-8859-1 instead. For cyrillic it is best to use KOI8-R,
+ * since this implementation is faster than the alternatives.
+ */
+global $default_charset;
+$default_charset = 'iso-8859-1';
+
+/**
+ * Path to the data/ directory
+ *   It is a possible security hole to have a writable directory
+ *   under the web server's root directory (ex: /home/httpd/html).
+ *   For this reason, it is possible to put the data directory
+ *   anywhere you would like. The path name can be absolute or
+ *   relative (to the config directory). It doesn't matter. Here
+ *   are two examples:
+ *
+ * Absolute:
+ *   $data_dir = '/usr/local/squirrelmail/data/';
+ *
+ * Relative (to the config directory):
+ *   $data_dir = '../data/';
+ */
+global $data_dir;
+$data_dir = '../data/';
+
+/**
+ * Path to directory used for storing attachments while a mail is
+ * being sent. There are a few security considerations regarding
+ * this directory:
+ *    + It should have the permission 733 (rwx-wx-wx) to make it
+ *      impossible for a random person with access to the webserver to
+ *      list files in this directory. Confidential data might be laying
+ *      around there.
+ *    + Since the webserver is not able to list the files in the content
+ *       is also impossible for the webserver to delete files lying around 
+ *       there for too long.
+ *    + It should probably be another directory than data_dir.
+ */
+global $attachment_dir;
+$attachment_dir = "$data_dir";
+
+/* Hash level used for data directory. */
+global $dir_hash_level;
+$dir_hash_level = 0;
+
+/**
+ * This is the default size of the folder list. Default
+ * is 150, but you can set it to whatever you wish.
+ */
+global $default_left_size;
+$default_left_size = 150;
+
+/**
+ * Some IMAP servers allow a username (like 'bob') to log in if they use
+ * uppercase in their name (like 'Bob' or 'BOB'). This creates extra
+ * preference files.  Toggling this option to true will transparently
+ * change all usernames to lowercase.
+ */
+global $force_username_lowercase;
+$force_username_lowercase = false;
+
+/**
+ * Themes
+ *   You can define your own theme and put it in this directory.
+ *   You must call it as the example below. You can name the theme
+ *   whatever you want. For an example of a theme, see the ones
+ *   included in the config directory.
+ *
+ * To add a new theme to the options that users can choose from, just
+ * add a new number to the array at the bottom, and follow the pattern.
+ */
+global $theme;
+
+/**
+ * The first one HAS to be here, and is your system's default
+ * theme. It can be any theme you want.
+ */
+$theme[0]['PATH'] = '../themes/default_theme.php';
+$theme[0]['NAME'] = 'Default';
+
+$theme[1]['PATH'] = '../themes/plain_blue_theme.php';
+$theme[1]['NAME'] = 'Plain Blue';
+
+$theme[2]['PATH'] = '../themes/sandstorm_theme.php';
+$theme[2]['NAME'] = 'Sand Storm';
+
+$theme[3]['PATH'] = '../themes/deepocean_theme.php';
+$theme[3]['NAME'] = 'Deep Ocean';
+
+$theme[4]['PATH'] = '../themes/slashdot_theme.php';
+$theme[4]['NAME'] = 'Slashdot';
+
+$theme[5]['PATH'] = '../themes/purple_theme.php';
+$theme[5]['NAME'] = 'Purple';
+
+$theme[6]['PATH'] = '../themes/forest_theme.php';
+$theme[6]['NAME'] = 'Forest';
+
+$theme[7]['PATH'] = '../themes/ice_theme.php';
+$theme[7]['NAME'] = 'Ice';
+
+$theme[8]['PATH'] = '../themes/seaspray_theme.php';
+$theme[8]['NAME'] = 'Sea Spray';
+
+$theme[9]['PATH'] = '../themes/bluesteel_theme.php';
+$theme[9]['NAME'] = 'Blue Steel';
+
+$theme[10]['PATH'] = '../themes/dark_grey_theme.php';
+$theme[10]['NAME'] = 'Dark Grey';
+
+$theme[11]['PATH'] = '../themes/high_contrast_theme.php';
+$theme[11]['NAME'] = 'High Contrast';
+
+$theme[12]['PATH'] = '../themes/black_bean_burrito_theme.php';
+$theme[12]['NAME'] = 'Black Bean Burrito';
+
+$theme[13]['PATH'] = '../themes/servery_theme.php';
+$theme[13]['NAME'] = 'Servery';
+
+$theme[14]['PATH'] = '../themes/maize_theme.php';
+$theme[14]['NAME'] = 'Maize';
+
+$theme[15]['PATH'] = '../themes/bluesnews_theme.php';
+$theme[15]['NAME'] = 'BluesNews';
+
+$theme[16]['PATH'] = '../themes/deepocean2_theme.php';
+$theme[16]['NAME'] = 'Deep Ocean 2';
+
+$theme[17]['PATH'] = '../themes/blue_gray_theme.php';
+$theme[17]['NAME'] = 'Blue Gray';
+
+$theme[18]['PATH'] = '../themes/dompie_theme.php';
+$theme[18]['NAME'] = 'Dompie';
+
+$theme[19]['PATH'] = '../themes/methodical_theme.php';
+$theme[19]['NAME'] = 'Methodical';
+
+$theme[20]['PATH'] = '../themes/greenhouse_effect.php';
+$theme[20]['NAME'] = 'Greenhouse Effect (Changes)';
 
-    $theme[17]["PATH"] = "../themes/blue_gray_theme.php";
-    $theme[17]["NAME"] = "Blue Gray";
+$theme[21]['PATH'] = '../themes/in_the_pink.php';
+$theme[21]['NAME'] = 'In The Pink (Changes)';
 
-    $theme[18]["PATH"] = "../themes/dompie_theme.php";
-    $theme[18]["NAME"] = "Dompie";
+$theme[22]['PATH'] = '../themes/kind_of_blue.php';
+$theme[22]['NAME'] = 'Kind of Blue (Changes)';
+
+$theme[23]['PATH'] = '../themes/monostochastic.php';
+$theme[23]['NAME'] = 'Monostochastic (Changes)';
 
-    $theme[19]["PATH"] = "../themes/methodical_theme.php";
-    $theme[19]["NAME"] = "Methodical";
+$theme[24]['PATH'] = '../themes/shades_of_grey.php';
+$theme[24]['NAME'] = 'Shades of Grey (Changes)';
 
-    $theme[20]["PATH"] = "../themes/greenhouse_effect.php";
-    $theme[20]["NAME"] = "Greenhouse Effect (Changes)";
-    
-    $theme[21]["PATH"] = "../themes/in_the_pink.php";
-    $theme[21]["NAME"] = "In The Pink (Changes)";
-    
-    $theme[22]["PATH"] = "../themes/kind_of_blue.php";
-    $theme[22]["NAME"] = "Kind of Blue (Changes)";
-    
-    $theme[23]["PATH"] = "../themes/monostochastic.php";
-    $theme[23]["NAME"] = "Monostochastic (Changes)";
-    
-    $theme[24]["PATH"] = "../themes/shades_of_grey.php";
-    $theme[24]["NAME"] = "Shades of Grey (Changes)";
-    
-    $theme[25]["PATH"] = "../themes/spice_of_life.php";
-    $theme[25]["NAME"] = "Spice of Life (Changes)";
+$theme[25]['PATH'] = '../themes/spice_of_life.php';
+$theme[25]['NAME'] = 'Spice of Life (Changes)';
 
-    $theme[26]["PATH"] = "../themes/spice_of_life_lite.php";
-    $theme[26]["NAME"] = "Spice of Life - Lite (Changes)";
+$theme[26]['PATH'] = '../themes/spice_of_life_lite.php';
+$theme[26]['NAME'] = 'Spice of Life - Lite (Changes)';
 
-    $theme[27]["PATH"] = "../themes/spice_of_life_dark.php";
-    $theme[27]["NAME"] = "Spice of Life - Dark (Changes)";
+$theme[27]['PATH'] = '../themes/spice_of_life_dark.php';
+$theme[27]['NAME'] = 'Spice of Life - Dark (Changes)';
 
-//  LDAP server(s)
-//
-//    Array of arrays with LDAP server parameters. See
-//    functions/abook_ldap_server.php for a list of possible
-//    parameters
-//
+$theme[28]['PATH'] = '../themes/christmas.php';
+$theme[28]['NAME'] = 'Holiday - Christmas';
+
+/**
+ * LDAP server(s)
+ *   Array of arrays with LDAP server parameters. See
+ *   functions/abook_ldap_server.php for a list of possible
+ *   parameters
+ *
+ * EXAMPLE:
+ *   $ldap_server[0] = Array(
+ *       'host' => '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.
+ */
+?>

+ 53 - 10
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 **/

+ 18 - 4
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 = '<i>';
         $italic_end = '</i>';
     } 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 '   <TD WIDTH="25%"><B>'. _("To") .'</B>';
             } else {
                 echo '   <TD WIDTH="25%"><B>'. _("From") .'</B>';
@@ -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);
+}
+
 ?>

+ 8 - 7
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);
                 }
             }
         }

+ 239 - 0
plugins/sent_subfolders/setup.php

@@ -0,0 +1,239 @@
+<?php
+
+/**
+ * setup.php -- Sent Subfolders Setup File
+ *
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This is a standard Squirrelmail-1.2 API for plugins.
+ *
+ * $Id$
+ */
+
+define('SMPREF_SENT_SUBFOLDERS_DISABLED',  0);
+define('SMPREF_SENT_SUBFOLDERS_YEARLY',    1);
+define('SMPREF_SENT_SUBFOLDERS_QUARTERLY', 2);
+define('SMPREF_SENT_SUBFOLDERS_MONTHLY',   3);
+define('SMOPT_GRP_SENT_SUBFOLDERS','SENT_SUBFOLDERS');
+
+function squirrelmail_plugin_init_sent_subfolders() {
+    /* Standard initialization API. */
+    global $squirrelmail_plugin_hooks;
+
+    /* The hooks to make the sent subfolders display correctly. */
+    $squirrelmail_plugin_hooks
+    ['check_handleAsSent_result']['sent_subfolders'] =
+        'sent_subfolders_check_handleAsSent';
+
+    /* The hooks to automatically update sent subfolders. */
+    $squirrelmail_plugin_hooks
+    ['left_main_before']['sent_subfolders'] =
+        'sent_subfolders_update_sentfolder';
+
+    $squirrelmail_plugin_hooks
+    ['compose_send']['sent_subfolders'] =
+        'sent_subfolders_update_sentfolder';
+
+    /* The hook to load the sent subfolders prefs. */
+    $squirrelmail_plugin_hooks
+    ['loading_prefs']['sent_subfolders'] =
+        'sent_subfolders_load_prefs';
+
+    /* The hooks to handle sent subfolders options. */
+    $squirrelmail_plugin_hooks
+    ['optpage_loadhook_folder']['sent_subfolders'] =
+        'sent_subfolders_optpage_loadhook_folders';
+}
+
+function sent_subfolders_check_handleAsSent() {
+    global $handleAsSent_result, $sent_subfolders_base;
+    global $use_sent_subfolders;
+    $sent_subfolders_base = 'INBOX.Sent';
+    $args = func_get_arg(0);
+
+    /* Only check the folder string if we have been passed a mailbox. */
+    if ($use_sent_subfolders && (count($args) > 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(' ', '&nbsp;', $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);
+}
+
+?>

+ 1 - 3
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,

+ 3 - 5
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);
             }
         }

+ 9 - 3
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']);
 }