Description: Debian-specific changes in paths, program locations etc.
Forwarded: not-needed
Origin: vendor
Author: Thijs Kinkhorst <thijs@debain.org>

--- squirrelmail-1.4.21.orig/include/load_prefs.php
+++ squirrelmail-1.4.21/include/load_prefs.php
@@ -33,6 +33,11 @@ $found_theme = false;
 /* need to adjust $chosen_theme path with SM_PATH */
 $chosen_theme = preg_replace("/(\.\.\/){1,}/", SM_PATH, $chosen_theme);
 
+/* need to prepend path where none exists */
+if ( !preg_match("/\//", $chosen_theme) ) {
+    $chosen_theme = SM_PATH . "themes/" . $chosen_theme;
+}
+
 for ($i = 0; $i < count($theme); ++$i){
     if ($theme[$i]['PATH'] == $chosen_theme) {
         $found_theme = true;
--- squirrelmail-1.4.21.orig/include/options/display.php
+++ squirrelmail-1.4.21/include/options/display.php
@@ -88,23 +88,29 @@ function load_optpage_data_display() {
 
     $language_values = array();
     foreach ($languages as $lang_key => $lang_attributes) {
+        # Debian: cope with squirrelmail-locales not being installed: do not offer
+        # non-existant languages for selection. This has been fixed in 1.5.x upstream.
+        if ( isset($lang_attributes['NAME']) && ($lang_key != 'en_US') && ($lang_key != 'custom') &&
+            !file_exists ( SM_PATH . 'locale/'. $lang_key ) ) continue;
         if (isset($lang_attributes['NAME'])) {
             $language_values[$lang_key] = $lang_attributes['NAME'];
         }
     }
-
-    asort($language_values);
-    $language_values =
-        array_merge(array('' => _("Default")), $language_values);
-    $language = $squirrelmail_language;
-    $optvals[SMOPT_GRP_GENERAL][] = array(
-        'name'    => 'language',
-        'caption' => _("Language"),
-        'type'    => SMOPT_TYPE_STRLIST,
-        'refresh' => SMOPT_REFRESH_ALL,
-        'posvals' => $language_values,
-        'htmlencoded' => true
-    );
+    # Debian: only display this option if there's actually a choice.
+    if ( count($language_values) > 1) {
+        asort($language_values);
+        $language_values =
+            array_merge(array('' => _("Default")), $language_values);
+        $language = $squirrelmail_language;
+        $optvals[SMOPT_GRP_GENERAL][] = array(
+            'name'    => 'language',
+            'caption' => _("Language"),
+            'type'    => SMOPT_TYPE_STRLIST,
+            'refresh' => SMOPT_REFRESH_ALL,
+            'posvals' => $language_values,
+            'htmlencoded' => true
+        );
+    }
 
     /* Set values for the "use javascript" option. */
     $optvals[SMOPT_GRP_GENERAL][] = array(
--- squirrelmail-1.4.21.orig/plugins/fortune/fortune_functions.php
+++ squirrelmail-1.4.21/plugins/fortune/fortune_functions.php
@@ -24,7 +24,7 @@ function fortune_show() {
 
     global $color;
     
-    $fortune_location = '/usr/bin/fortune';
+    $fortune_location = '/usr/games/fortune';
     $exist = is_executable($fortune_location);
     
     if (!$exist) {
--- squirrelmail-1.4.21.orig/plugins/squirrelspell/sqspell_config.php
+++ squirrelmail-1.4.21/plugins/squirrelspell/sqspell_config.php
@@ -20,18 +20,30 @@ sqgetGlobalVar('username', $username, SQ
 /**
  * Example:
  *
- * $SQSPELL_APP = array( 'English' => 'ispell -a',
- *                     'Spanish' => 'ispell -d spanish -a' );
+ * $SQSPELL_APP = array( 'american (American English)' => 'ispell -a',
+ *                     'spanish (Spanish)' => 'ispell -d spanish -a' );
  * You can replace ispell with aspell keeping the same commandline:
- * $SQSPELL_APP = array( 'English' => 'aspell -a',
- *                     'Spanish' => 'aspell -d spanish -a' );
+ * $SQSPELL_APP = array( 'american (American English)' => 'aspell -a',
+ *                     'spanish (Spanish)' => 'aspell -d spanish -a' );
  */
-$SQSPELL_APP = array('English' => 'ispell -a',
-			'Spanish' => 'ispell -d spanish -a');
-$SQSPELL_APP_DEFAULT = 'English';
+
+# Debian: if dictionaries-common >= 2.81.1 is available, detect the
+# installed dictionaries automatically, else use the list below.
+if ( ! @include('/var/cache/dictionaries-common/sqspell.php') ) {
+    $SQSPELL_APP = array('american (American English)' => 'ispell -a',
+                 'spanish (Spanish)' => 'ispell -d spanish -a');
+}
+
+# Debian: if dictionaries-common >= 2.50 is available, detect the
+# default dictionary automatically.
+if ( is_readable ( '/etc/dictionaries-common/ispell-default' ) ) {
+    $SQSPELL_APP_DEFAULT = file_get_contents ( '/etc/dictionaries-common/ispell-default' );
+} else {
+    $SQSPELL_APP_DEFAULT = 'american (American English)';
+}
+
 $SQSPELL_WORDS_FILE = 
    getHashedFile($username, $data_dir, "$username.words");
 
 $SQSPELL_EREG = 'ereg';
 
-?>
\ No newline at end of file
--- squirrelmail-1.4.21.orig/functions/file_prefs.php
+++ squirrelmail-1.4.21/functions/file_prefs.php
@@ -185,17 +185,26 @@ function checkForPrefs($data_dir, $usern
 
     /* Then, check if the file exists. */
     if (!@file_exists($filename) ) {
-        /* First, check the $data_dir for the default preference file. */
+
+        /* If it does not exist, check for default_prefs */
+
+        /* First, check legacy locations: data dir */
         if(substr($data_dir,-1) != '/') {
             $data_dir .= '/';
         }
         $default_pref = $data_dir . 'default_pref';
 
-        /* If it is not there, check the internal data directory. */
+        /* or legacy location: internal data dir */
         if (!@file_exists($default_pref)) {
             $default_pref = SM_PATH . 'data/default_pref';
         }
 
+        /* If no legacies, check where we'd expect it to be located:
+         * under config/ */
+        if (!@file_exists($default_pref)) {
+            $default_pref = SM_PATH . 'config/default_pref';
+        }
+
         /* Otherwise, report an error. */
         $errTitle = sprintf( _("Error opening %s"), $default_pref );
         if (!is_readable($default_pref)) {
--- squirrelmail-1.4.21.orig/config/config_default.php
+++ squirrelmail-1.4.21/config/config_default.php
@@ -115,7 +115,7 @@ $provider_uri = 'http://squirrelmail.org
  * Example: In bob@example.com, example.com is the domain.
  * @global string $domain
  */
-$domain = 'example.com';
+$domain = trim(implode('', file('/etc/'.(file_exists('/etc/mailname')?'mail':'host').'name')));
 
 /**
  * Time offset inversion
@@ -487,7 +487,7 @@ $noselect_fix_enable = false;
  *   Here are two examples:
  *
  * Absolute:
- *   $data_dir = '/var/local/squirrelmail/data/';
+ *   $data_dir = '/var/lib/squirrelmail/data/';
  *
  * Relative (to main SM directory):
  *   $data_dir = SM_PATH . 'data/';
@@ -496,7 +496,7 @@ $noselect_fix_enable = false;
  *
  * @global string $data_dir
  */
-$data_dir = '/var/local/squirrelmail/data/';
+$data_dir = '/var/lib/squirrelmail/data/';
 
 /**
  * Attachments directory
@@ -514,7 +514,7 @@ $data_dir = '/var/local/squirrelmail/dat
  *    + It should probably be another directory than data_dir.
  * @global string $attachment_dir
  */
-$attachment_dir = '/var/local/squirrelmail/attach/';
+$attachment_dir = '/var/spool/squirrelmail/attach/';
 
 /**
  * Hash level used for data directory.
--- squirrelmail-1.4.21.orig/config/conf.pl
+++ squirrelmail-1.4.21/config/conf.pl
@@ -38,16 +38,17 @@ if ( defined( $ENV{'PATH_INFO'} )
 # (the Basename stuff above will sometimes return '.' as
 # the base directory, which is not helpful here). 
 ############################################################
-use Cwd;
-$dir = cwd();
+#use Cwd;
+#$dir = cwd();
+$dir = '/usr/share/squirrelmail/config';
   
 
 ############################################################              
 # First, lets read in the data already in there...
 ############################################################              
-if ( -e "config.php" ) {
+if ( -e "/etc/squirrelmail/config.php" ) {
     # Make sure that file is readable
-    if (! -r "config.php") {
+    if (! -r "/etc/squirrelmail/config.php") {
         clear_screen();
         print "WARNING:\n";
         print "The file \"config/config.php\" was found, but you don't\n";
@@ -57,7 +58,7 @@ if ( -e "config.php" ) {
         $ctu = <STDIN>;
         exit;
     }
-    open( FILE, "config.php" );
+    open( FILE, "/etc/squirrelmail/config.php" );
     while ( $line = <FILE> ) {
         $line =~ s/^\s+//;
         $line =~ s/^\$//;
@@ -108,9 +109,9 @@ if ( -e "config.php" ) {
     }
 
     $config = 1;
-    open( FILE, "config.php" );
-} elsif ( -e "config_default.php" ) {
-    open( FILE, "config_default.php" );
+    open( FILE, "/etc/squirrelmail/config.php" );
+} elsif ( -e "/etc/squirrelmail/config_default.php" ) {
+    open( FILE, "/etc/squirrelmail/config_default.php" );
     while ( $line = <FILE> ) {
         $line =~ s/^\s+//;
         $line =~ s/^\$//;
@@ -160,7 +161,7 @@ if ( -e "config.php" ) {
         $print_config_version = $config_version;
     }
     $config = 2;
-    open( FILE, "config_default.php" );
+    open( FILE, "/etc/squirrelmail/config_default.php" );
 } else {
     print "No configuration file found. Please get config_default.php\n";
     print "or config.php before running this again. This program needs\n";
@@ -190,8 +191,13 @@ while ( $line = <FILE> ) {
             $sub = $options[0];
             $sub =~ s/\]\[['|"]PATH['|"]\]//;
             $sub =~ s/.*\[//;
-            if ( -e "../themes" ) {
+            if ( -e "/usr/share/squirrelmail/themes" ) {
                 $options[1] =~ s/^\.\.\/config/\.\.\/themes/;
+                $options[1] =~ s/^SM_PATH \. \'config/\.\.\/themes/;
+                if ( $options[1] !~ /\// ) {
+                    # no path information courtesy early debs
+                    $options[1] = '../themes/' . $options[1];
+                }
             }
             $theme_path[$sub] = &change_to_rel_path($options[1]);
         } elsif ( $options[0] =~ /^theme\[[0-9]+\]\[['|"]NAME['|"]\]/ ) {
@@ -362,7 +368,7 @@ $check_referrer = ''
 
 if ( $ARGV[0] eq '--install-plugin' ) {
     print "Activating plugin " . $ARGV[1] . "\n";
-    if ( -d "../plugins/" . $ARGV[1]) {
+    if ( -d "/usr/share/squirrelmail/plugins/" . $ARGV[1]) {
         push @plugins, $ARGV[1];
         save_data();
         exit(0);
@@ -599,12 +605,12 @@ while ( ( $command ne "q" ) && ( $comman
             print "    $num. $plugins[$count]\n";
         }
         print "\n  Available Plugins:\n";
-        opendir( DIR, "../plugins" );
+        opendir( DIR, "/usr/share/squirrelmail/plugins" );
         @files          = sort(readdir(DIR));
         $pos            = 0;
         @unused_plugins = ();
         for ( $i = 0 ; $i <= $#files ; $i++ ) {
-            if ( -d "../plugins/" . $files[$i] && $files[$i] !~ /^\./ && $files[$i] ne "CVS" ) {
+            if ( -d "/usr/share/squirrelmail/plugins/" . $files[$i] && $files[$i] !~ /^\./ && $files[$i] ne "CVS" ) {
                 $match = 0;
                 for ( $k = 0 ; $k <= $#plugins ; $k++ ) {
                     if ( $plugins[$k] eq $files[$i] ) {
@@ -2566,8 +2572,6 @@ sub command41 {
             $name = <STDIN>;
             $name =~ s/[\r|\n]//g;
             $theme_name[ $#theme_name + 1 ] = $name;
-            print "Be sure to put ../themes/ before the filename.\n";
-            print "What file is this stored in (ex: ../themes/default_theme.php): ";
             $name = <STDIN>;
             $name =~ s/[\r|\n]//g;
             $theme_path[ $#theme_path + 1 ] = $name;
@@ -2601,7 +2605,7 @@ sub command41 {
         } elsif ( $input =~ /^\s*t\s*/i ) {
             print "\nStarting detection...\n\n";
 
-            opendir( DIR, "../themes" );
+            opendir( DIR, "/usr/share/squirrelmail/themes" );
             @files = grep { /\.php$/i } sort(readdir(DIR));
             $cnt = 0;
             while ( $cnt <= $#files ) {
@@ -2635,7 +2639,7 @@ sub command41 {
             print "\n";
             for ( $cnt = 0 ; $cnt <= $#theme_path ; $cnt++ ) {
                 $filename = $theme_path[$cnt];
-                if ( !( -e $filename ) ) {
+                if ( !( -e '/usr/share/squirrelmail/themes/' . $filename ) ) {
                     print "  Removing $filename (file not found)\n";
                     $offset         = 0;
                     @new_theme_name = ();
@@ -3288,7 +3292,7 @@ sub commandA3 {
 
 sub save_data {
     $tab = "    ";
-    if ( open( CF, ">config.php" ) ) {
+    if ( open( CF, ">/etc/squirrelmail/config.php" ) ) {
         print CF "<?php\n";
         print CF "\n";
 
@@ -3344,8 +3348,12 @@ sub save_data {
         print CF "\n";
 
     # Server settings
-    # string
-        print CF "\$domain                 = '$domain';\n";
+    # string or code
+        if ($domain =~ /^(implode|trim)\(/) {
+	    print CF "\$domain                 = $domain;\n";
+	} else {
+	    print CF "\$domain                 = '$domain';\n";
+	}
     # string
         print CF "\$imapServerAddress      = '$imapServerAddress';\n";
     # integer
