moving functions to separate file, adding configuration files
[squirrelmail.git] / config / conf.pl
index 436388b8288c9de7da8b45f586e3865a4e1e07d0..73781d56c5a08dc74b86b8db427df999104eeb4a 100755 (executable)
@@ -53,13 +53,13 @@ if ( -e "config.php" ) {
         $var = $line;
 
         $var =~ s/=/EQUALS/;
-        if ( $var =~ /^([a-z]|[A-Z])/ ) {
+        if ( $var =~ /^([a-z])/i ) {
             @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/[\n\r]//g;
+                $o[1] =~ s/[\'\"];\s*$//;
                 $o[1] =~ s/;$//;
-                $o[1] =~ s/^[\'|\"]//;
+                $o[1] =~ s/^[\'\"]//;
 
                 $config_version = $o[1];
                 close(FILE);
@@ -106,13 +106,13 @@ if ( -e "config.php" ) {
         $var = $line;
 
         $var =~ s/=/EQUALS/;
-        if ( $var =~ /^([a-z]|[A-Z])/ ) {
+        if ( $var =~ /^([a-z])/i ) {
             @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/[\n\r]//g;
+                $o[1] =~ s/[\'\"];\s*$//;
                 $o[1] =~ s/;$//;
-                $o[1] =~ s/^[\'|\"]//;
+                $o[1] =~ s/^[\'\"]//;
 
                 $config_version = $o[1];
                 close(FILE);
@@ -165,27 +165,27 @@ while ( $line = <FILE> ) {
     $var = $line;
 
     $var =~ s/=/EQUALS/;
-    if ( $var =~ /^([a-z]|[A-Z])/ ) {
+    if ( $var =~ /^([a-z])/i ) {
         @options = split ( /\s*EQUALS\s*/, $var );
-        $options[1] =~ s/[\n|\r]//g;
-        $options[1] =~ s/[\'|\"];\s*$//;
+        $options[1] =~ s/[\n\r]//g;
+        $options[1] =~ s/[\'\"];\s*$//;
         $options[1] =~ s/;$//;
-        $options[1] =~ s/^[\'|\"]//;
+        $options[1] =~ s/^[\'\"]//;
         # de-escape escaped strings
         $options[1] =~ s/\\'/'/g;
         $options[1] =~ s/\\\\/\\/g;
 
-        if ( $options[0] =~ /^theme\[[0-9]+\]\[['|"]PATH['|"]\]/ ) {
+        if ( $options[0] =~ /^theme\[[0-9]+\]\[['"]PATH['"]\]/ ) {
             $sub = $options[0];
-            $sub =~ s/\]\[['|"]PATH['|"]\]//;
+            $sub =~ s/\]\[['"]PATH['"]\]//;
             $sub =~ s/.*\[//;
             if ( -e "../themes" ) {
                 $options[1] =~ s/^\.\.\/config/\.\.\/themes/;
             }
             $theme_path[$sub] = &change_to_rel_path($options[1]);
-        } elsif ( $options[0] =~ /^theme\[[0-9]+\]\[['|"]NAME['|"]\]/ ) {
+        } elsif ( $options[0] =~ /^theme\[[0-9]+\]\[['"]NAME['"]\]/ ) {
             $sub = $options[0];
-            $sub =~ s/\]\[['|"]NAME['|"]\]//;
+            $sub =~ s/\]\[['"]NAME['"]\]//;
             $sub =~ s/.*\[//;
             $theme_name[$sub] = $options[1];
         } elsif ( $options[0] =~ /^plugins\[[0-9]+\]/ ) {
@@ -203,50 +203,50 @@ while ( $line = <FILE> ) {
                     $continue = 1;
                 }
 
-                if ( $tmp =~ /^\s*[\'|\"]host[\'|\"]/i ) {
-                    $tmp =~ s/^\s*[\'|\"]host[\'|\"]\s*=>\s*[\'|\"]//i;
-                    $tmp =~ s/[\'|\"],?\s*$//;
-                    $tmp =~ s/[\'|\"]\);\s*$//;
+                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*$//;
+                } 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*$//;
+                } 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*$//;
+                } 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*$//;
+                } 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*$//;
+                } elsif ( $tmp =~ /^\s*[\'\"]name[\'\"]/i ) {
+                    $tmp =~ s/^\s*[\'\"]name[\'\"]\s*=>\s*[\'\"]//i;
+                    $tmp =~ s/[\'\"],?\s*$//;
+                    $tmp =~ s/[\'\"]\);\s*$//;
                     $name = $tmp;
-                } elsif ( $tmp =~ /^\s*[\'|\"]binddn[\'|\"]/i ) {
-                    $tmp =~ s/^\s*[\'|\"]binddn[\'|\"]\s*=>\s*[\'|\"]//i;
-                    $tmp =~ s/[\'|\"],?\s*$//;
-                    $tmp =~ s/[\'|\"]\);\s*$//;
+                } elsif ( $tmp =~ /^\s*[\'\"]binddn[\'\"]/i ) {
+                    $tmp =~ s/^\s*[\'\"]binddn[\'\"]\s*=>\s*[\'\"]//i;
+                    $tmp =~ s/[\'\"],?\s*$//;
+                    $tmp =~ s/[\'\"]\);\s*$//;
                     $binddn = $tmp;
-                } elsif ( $tmp =~ /^\s*[\'|\"]bindpw[\'|\"]/i ) {
-                    $tmp =~ s/^\s*[\'|\"]bindpw[\'|\"]\s*=>\s*[\'|\"]//i;
-                    $tmp =~ s/[\'|\"],?\s*$//;
-                    $tmp =~ s/[\'|\"]\);\s*$//;
+                } elsif ( $tmp =~ /^\s*[\'\"]bindpw[\'\"]/i ) {
+                    $tmp =~ s/^\s*[\'\"]bindpw[\'\"]\s*=>\s*[\'\"]//i;
+                    $tmp =~ s/[\'\"],?\s*$//;
+                    $tmp =~ s/[\'\"]\);\s*$//;
                     $bindpw = $tmp;
-                } elsif ( $tmp =~ /^\s*[\'|\"]protocol[\'|\"]/i ) {
-                    $tmp =~ s/^\s*[\'|\"]protocol[\'|\"]\s*=>\s*[\'|\"]?//i;
-                    $tmp =~ s/[\'|\"]?,?\s*$//;
-                    $tmp =~ s/[\'|\"]?\);\s*$//;
+                } elsif ( $tmp =~ /^\s*[\'\"]protocol[\'\"]/i ) {
+                    $tmp =~ s/^\s*[\'\"]protocol[\'\"]\s*=>\s*[\'\"]?//i;
+                    $tmp =~ s/[\'\"]?,?\s*$//;
+                    $tmp =~ s/[\'\"]?\);\s*$//;
                     $protocol = $tmp;
                 }
             }
@@ -292,7 +292,7 @@ $allow_thread_sort = 'false'            if ( !$allow_thread_sort );
 $allow_server_sort = 'false'            if ( !$allow_server_sort );
 $no_list_for_subscribe = 'false'        if ( !$no_list_for_subscribe );
 $allow_charset_search = 'true'          if ( !$allow_charset_search );
-$allow_advanced_search = '0'            if ( !$allow_advanced_search) ;
+$allow_advanced_search = 0              if ( !$allow_advanced_search) ;
 $prefs_user_field = 'user'              if ( !$prefs_user_field );
 $prefs_key_field = 'prefkey'            if ( !$prefs_key_field );
 $prefs_val_field = 'prefval'            if ( !$prefs_val_field );
@@ -306,7 +306,8 @@ $imap_auth_mech = 'login'               if ( !$imap_auth_mech );
 $session_name = 'SQMSESSID'             if ( !$session_name );
 $show_alternative_names = 'false'       if ( !$show_alternative_names );
 $available_languages = 'all'            if ( !$available_languages );
-$agresive_decoding = 'false'            if ( !$agresive_decoding );
+$aggressive_decoding = 'false'          if ( !$aggressive_decoding );
+$lossy_encoding = 'false'        if ( !$lossy_encoding );
 $advanced_tree = 'false'                if ( !$advanced_tree );
 $oldway = 'false'                       if ( !$oldway );
 $use_icons = 'false'                    if ( !$use_icons );
@@ -481,7 +482,7 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
         print "11. Allow server-side sorting   : $WHT$allow_server_sort$NRM\n";
         print "12. Allow server charset search : $WHT$allow_charset_search$NRM\n";
         print "13. Allow advanced search       : $WHT$allow_advanced_search$NRM\n";
-    print "14. PHP session name            : $WHT$session_name$NRM\n";
+        print "14. PHP session name            : $WHT$session_name$NRM\n";
         print "\n";
         print "R   Return to Main Menu\n";
     } elsif ( $menu == 5 ) {
@@ -572,7 +573,8 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
     print "2.  Default Charset                 : $WHT$default_charset$NRM\n";
     print "3.  Show alternative language names : $WHT$show_alternative_names$NRM\n";
     print "4.  Available languages             : $WHT$available_languages$NRM\n";
-    print "5.  Use agresive decoding           : $WHT$agresive_decoding$NRM\n";
+    print "5.  Enable aggressive decoding      : $WHT$aggressive_decoding$NRM\n";
+    print "6.  Enable lossy encoding           : $WHT$lossy_encoding$NRM\n";
     print "\n";
         print "R   Return to Main Menu\n";
     } elsif ( $menu == 11 ) {
@@ -588,9 +590,9 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
         print "R   Return to Main Menu\n";
     }
     if ( $config_use_color == 1 ) {
-        print "C.  Turn color off\n";
+        print "C   Turn color off\n";
     } else {
-        print "C.  Turn color on\n";
+        print "C   Turn color on\n";
     }
     print "S   Save data\n";
     print "Q   Quit\n";
@@ -598,7 +600,7 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
     print "\n";
     print "Command >> " . $WHT;
     $command = <STDIN>;
-    $command =~ s/[\n|\r]//g;
+    $command =~ s/[\n\r]//g;
     $command =~ tr/A-Z/a-z/;
     print "$NRM\n";
 
@@ -732,7 +734,8 @@ while ( ( $command ne "q" ) && ( $command ne "Q" ) ) {
             elsif ( $command == 2 ) { $default_charset           = commandA2(); }
             elsif ( $command == 3 ) { $show_alternative_names        = commandA3(); }
             elsif ( $command == 4 ) { $available_languages         = commandA4(); }
-            elsif ( $command == 5 ) { $agresive_decoding         = commandA5(); }
+            elsif ( $command == 5 ) { $aggressive_decoding         = commandA5(); }
+            elsif ( $command == 6 ) { $lossy_encoding         = commandA6(); }
         } elsif ( $menu == 11 ) {
             if    ( $command == 1 ) { $advanced_tree  = commandB1(); }
             elsif ( $command == 2 ) { $oldway            = commandB2(); }
@@ -769,7 +772,7 @@ sub command1 {
     if ( $new_org_name eq "\n" ) {
         $new_org_name = $org_name;
     } else {
-        $new_org_name =~ s/[\r|\n]//g;
+        $new_org_name =~ s/[\r\n]//g;
     $new_org_name =~ s/\"/&quot;/g;
     }
     return $new_org_name;
@@ -785,14 +788,14 @@ sub command2 {
     print "    to use the default logo, use ../images/sm_logo.png\n";
     print "  - To specify a logo defined outside the SquirrelMail source tree\n";
     print "    use the absolute URL the webserver would use to include the file\n";
-    print "    e.g. http://some.host.com/images/mylogo.gif or /images/mylogo.jpg\n";
+    print "    e.g. http://www.example.com/images/mylogo.gif or /images/mylogo.jpg\n";
     print "\n";
     print "[$WHT$org_logo$NRM]: $WHT";
     $new_org_logo = <STDIN>;
     if ( $new_org_logo eq "\n" ) {
         $new_org_logo = $org_logo;
     } else {
-        $new_org_logo =~ s/[\r|\n]//g;
+        $new_org_logo =~ s/[\r\n]//g;
     }
     return $new_org_logo;
 }
@@ -839,7 +842,7 @@ sub command3 {
     if ( $new_org_title eq "\n" ) {
         $new_org_title = $org_title;
     } else {
-        $new_org_title =~ s/[\r|\n]//g;
+        $new_org_title =~ s/[\r\n]//g;
     $new_org_title =~ s/\"/\'/g;
     }
     return $new_org_title;
@@ -857,7 +860,7 @@ sub command4 {
     if ( $new_signout_page eq "\n" ) {
         $new_signout_page = $signout_page;
     } else {
-        $new_signout_page =~ s/[\r|\n]//g;
+        $new_signout_page =~ s/[\r\n]//g;
         $new_signout_page =~ s/^\s+$//g;
     }
     return $new_signout_page;
@@ -874,7 +877,7 @@ sub command6 {
     if ( $new_frame_top eq "\n" ) {
         $new_frame_top = '_top';
     } else {
-        $new_frame_top =~ s/[\r|\n]//g;
+        $new_frame_top =~ s/[\r\n]//g;
         $new_frame_top =~ s/^\s+$//g;
     }
     return $new_frame_top;
@@ -890,7 +893,7 @@ sub command7 {
     if ( $new_provider_uri eq "\n" ) {
         $new_provider_uri = 'http://www.squirrelmail.org/';
     } else {
-        $new_provider_uri =~ s/[\r|\n]//g;
+        $new_provider_uri =~ s/[\r\n]//g;
         $new_provider_uri =~ s/^\s+$//g;
     }
     return $new_provider_uri;
@@ -905,7 +908,7 @@ sub command8 {
     if ( $new_provider_name eq "\n" ) {
         $new_provider_name = 'SquirrelMail';
     } else {
-        $new_provider_name =~ s/[\r|\n]//g;
+        $new_provider_name =~ s/[\r\n]//g;
         $new_provider_name =~ s/^\s+$//g;
     }
     return $new_provider_name;
@@ -916,15 +919,15 @@ sub command8 {
 # domain
 sub command11 {
     print "The domain name is the suffix at the end of all email addresses.  If\n";
-    print "for example, your email address is jdoe\@myorg.com, then your domain\n";
-    print "would be myorg.com.\n";
+    print "for example, your email address is jdoe\@example.com, then your domain\n";
+    print "would be example.com.\n";
     print "\n";
     print "[$WHT$domain$NRM]: $WHT";
     $new_domain = <STDIN>;
     if ( $new_domain eq "\n" ) {
         $new_domain = $domain;
     } else {
-        $new_domain =~ s/[\r|\n]//g;
+        $new_domain =~ s/[\r\n]//g;
     }
     return $new_domain;
 }
@@ -937,7 +940,7 @@ sub command12 {
     if ( $new_imapServerAddress eq "\n" ) {
         $new_imapServerAddress = $imapServerAddress;
     } else {
-        $new_imapServerAddress =~ s/[\r|\n]//g;
+        $new_imapServerAddress =~ s/[\r\n]//g;
     }
     return $new_imapServerAddress;
 }
@@ -950,7 +953,7 @@ sub command13 {
     if ( $new_imapPort eq "\n" ) {
         $new_imapPort = $imapPort;
     } else {
-        $new_imapPort =~ s/[\r|\n]//g;
+        $new_imapPort =~ s/[\r\n]//g;
     }
     return $new_imapPort;
 }
@@ -990,7 +993,7 @@ sub command15 {
     if ( $new_sendmail_path eq "\n" ) {
         $new_sendmail_path = $sendmail_path;
     } else {
-        $new_sendmail_path =~ s/[\r|\n]//g;
+        $new_sendmail_path =~ s/[\r\n]//g;
     }
     return $new_sendmail_path;
 }
@@ -1003,7 +1006,7 @@ sub command16 {
     if ( $new_smtpServerAddress eq "\n" ) {
         $new_smtpServerAddress = $smtpServerAddress;
     } else {
-        $new_smtpServerAddress =~ s/[\r|\n]//g;
+        $new_smtpServerAddress =~ s/[\r\n]//g;
     }
     return $new_smtpServerAddress;
 }
@@ -1016,7 +1019,7 @@ sub command17 {
     if ( $new_smtpPort eq "\n" ) {
         $new_smtpPort = $smtpPort;
     } else {
-        $new_smtpPort =~ s/[\r|\n]//g;
+        $new_smtpPort =~ s/[\r\n]//g;
     }
     return $new_smtpPort;
 }
@@ -1078,7 +1081,7 @@ sub command19 {
     if ( $new_imap_server_type eq "\n" ) {
         $new_imap_server_type = $imap_server_type;
     } else {
-        $new_imap_server_type =~ s/[\r|\n]//g;
+        $new_imap_server_type =~ s/[\r\n]//g;
     }
     return $new_imap_server_type;
 }
@@ -1120,7 +1123,7 @@ sub command111 {
     if ( $new_optional_delimiter eq "\n" ) {
         $new_optional_delimiter = $optional_delimiter;
     } else {
-        $new_optional_delimiter =~ s/[\r|\n]//g;
+        $new_optional_delimiter =~ s/[\r\n]//g;
     }
     return $new_optional_delimiter;
 }
@@ -1215,17 +1218,19 @@ sub command112b {
                 print " ERROR TESTING\n";
                 close $sock;
             } else {
-                print $sock "mail from: tester\@squirrelmail.org\n";
+                print $sock "HELO $domain\r\n";
                 $got = <$sock>;  # Discard
-                print $sock "rcpt to: junk\@microsoft.com\n";
+                print $sock "MAIL FROM:<tester\@squirrelmail.org>\r\n";
+                $got = <$sock>;  # Discard
+                print $sock "RCPT TO:<junk\@microsoft.com\r\n";
                 $got = <$sock>;  # This is the important line
                 if ($got =~ /^250\b/) {  # SMTP will relay without auth
                     print "SUPPORTED$NRM\n";
                 } else {
                   print "NOT SUPPORTED$NRM\n";
                 }
-                print $sock "rset\n";
-                print $sock "quit\n";
+                print $sock "RSET\r\n";
+                print $sock "QUIT\r\n";
                 close $sock;
             }
             # Try login (SquirrelMail default)
@@ -1346,7 +1351,7 @@ sub command71 {
     do {
         print "] ";
         $line = <STDIN>;
-        $line =~ s/[\r|\n]//g;
+        $line =~ s/[\r\n]//g;
         if ( $line ne "@" ) {
             $line =~ s/  /\&nbsp;\&nbsp;/g;
             $line =~ s/\t/\&nbsp;\&nbsp;\&nbsp;\&nbsp;/g;
@@ -1362,7 +1367,7 @@ sub command71 {
 ################# PLUGINS ###################
 
 sub command81 {
-    $command =~ s/[\s|\n|\r]*//g;
+    $command =~ s/[\s\n\r]*//g;
     if ( $command > 0 ) {
         $command = $command - 1;
         if ( $command <= $#plugins ) {
@@ -1475,7 +1480,7 @@ sub command23a {
     if ( $new_trash_folder eq "\n" ) {
         $new_trash_folder = $trash_folder;
     } else {
-        $new_trash_folder =~ s/[\r|\n]//g;
+        $new_trash_folder =~ s/[\r\n]//g;
     }
     return $new_trash_folder;
 }
@@ -1496,7 +1501,7 @@ sub command23b {
     if ( $new_sent_folder eq "\n" ) {
         $new_sent_folder = $sent_folder;
     } else {
-        $new_sent_folder =~ s/[\r|\n]//g;
+        $new_sent_folder =~ s/[\r\n]//g;
     }
     return $new_sent_folder;
 }
@@ -1518,7 +1523,7 @@ sub command23c {
     if ( $new_draft_folder eq "\n" ) {
         $new_draft_folder = $draft_folder;
     } else {
-        $new_draft_folder =~ s/[\r|\n]//g;
+        $new_draft_folder =~ s/[\r\n]//g;
     }
     return $new_draft_folder;
 }
@@ -1730,10 +1735,10 @@ sub command212 {
 
     print "Which one should be default (1,2,3)? [$WHT$default_unseen_notify$NRM]: $WHT";
     $new_show = <STDIN>;
-    if ( $new_show =~ /^[1|2|3]\n/i ) {
+    if ( $new_show =~ /^[123]\n/i ) {
         $default_unseen_notify = $new_show;
     }
-    $default_unseen_notify =~ s/[\r|\n]//g;
+    $default_unseen_notify =~ s/[\r\n]//g;
     return $default_unseen_notify;
 }
 
@@ -1747,10 +1752,10 @@ sub command213 {
 
     print "Which one should be default (1,2)? [$WHT$default_unseen_type$NRM]: $WHT";
     $new_show = <STDIN>;
-    if ( $new_show =~ /^[1|2]\n/i ) {
+    if ( $new_show =~ /^[12]\n/i ) {
         $default_unseen_type = $new_show;
     }
-    $default_unseen_type =~ s/[\r|\n]//g;
+    $default_unseen_type =~ s/[\r\n]//g;
     return $default_unseen_type;
 }
 
@@ -1864,7 +1869,7 @@ sub command33a {
     if ( $new_data_dir eq "\n" ) {
         $new_data_dir = $data_dir;
     } else {
-        $new_data_dir =~ s/[\r|\n]//g;
+        $new_data_dir =~ s/[\r\n]//g;
     }
     if ( $new_data_dir =~ /^\s*$/ ) {
         $new_data_dir = "";
@@ -1904,7 +1909,7 @@ sub command33b {
     if ( $new_attachment_dir eq "\n" ) {
         $new_attachment_dir = $attachment_dir;
     } else {
-        $new_attachment_dir =~ s/[\r|\n]//g;
+        $new_attachment_dir =~ s/[\r\n]//g;
     }
     if ( $new_attachment_dir =~ /^\s*$/ ) {
         $new_attachment_dir = "";
@@ -1935,7 +1940,7 @@ sub command33c {
     if ( $new_dir_hash_level eq "\n" ) {
         $new_dir_hash_level = $dir_hash_level;
     } else {
-        $new_dir_hash_level =~ s/[\r|\n]//g;
+        $new_dir_hash_level =~ s/[\r\n]//g;
     }
     if ( ( int($new_dir_hash_level) < 0 )
         || ( int($new_dir_hash_level) > 4 )
@@ -1961,7 +1966,7 @@ sub command35 {
     if ( $new_default_left_size eq "\n" ) {
         $new_default_left_size = $default_left_size;
     } else {
-        $new_default_left_size =~ s/[\r|\n]//g;
+        $new_default_left_size =~ s/[\r\n]//g;
     }
     return $new_default_left_size;
 }
@@ -2148,18 +2153,20 @@ sub command314 {
 # command315 (UID support) obsoleted.
 
 # advanced search option
-
 sub command316 {
-    print "This option allows you to change the advanced search form.\n";
-    print "Set to 0 to disable the advanced search, 1 to have advanced\n";
-    print "and search only or 2 for both forms.\n";
-    print "[$WHT$allow_advanced_search$NRM]: $WHT";
-    $allows_advanced_search = <STDIN>;
-    chomp($allows_advanced_search);
-    if ( $allows_advanced_search eq "" ) {
-        $allows_advanced_searchn=0;
+    print "This option allows you to control the use of advanced search form.\n";
+    print "  0 = enable basic search only\n";
+    print "  1 = enable advanced search only\n";
+    print "  2 = enable both\n";
+    print "\n";
+
+    print "Allowed search (0,1,2)? [$WHT$allow_advanced_search$NRM]: $WHT";
+    $new_allow_advanced_search = <STDIN>;
+    if ( $new_allow_advanced_search =~ /^[012]\n/i ) {
+        $allow_advanced_search = $new_allow_advanced_search;
     }
-    return $allows_advanced_search;
+    $allow_advanced_search =~ s/[\r\n]//g;
+    return $allow_advanced_search;
 }
 
 
@@ -2184,7 +2191,7 @@ sub command41 {
     print "them.  You can also change the default theme.\n";
     print "[theme] command (?=help) > ";
     $input = <STDIN>;
-    $input =~ s/[\r|\n]//g;
+    $input =~ s/[\r\n]//g;
     while ( $input ne "d" ) {
         if ( $input =~ /^\s*l\s*/i ) {
             $count = 0;
@@ -2219,12 +2226,12 @@ sub command41 {
         } elsif ( $input =~ /^\s*\+/ ) {
             print "What is the name of this theme: ";
             $name = <STDIN>;
-            $name =~ s/[\r|\n]//g;
+            $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;
+            $name =~ s/[\r\n]//g;
             $theme_path[ $#theme_path + 1 ] = $name;
         } elsif ( $input =~ /^\s*-\s*[0-9]?/ ) {
             if ( $input =~ /[0-9]+\s*$/ ) {
@@ -2272,7 +2279,7 @@ sub command41 {
                         print "** Found theme: $filename\n";
                         print "   What is its name? ";
                         $nm = <STDIN>;
-                        $nm =~ s/[\n|\r]//g;
+                        $nm =~ s/[\n\r]//g;
                         $theme_name[ $#theme_name + 1 ] = $nm;
                         $theme_path[ $#theme_path + 1 ] = $filename;
                     }
@@ -2318,7 +2325,7 @@ sub command41 {
         }
         print "[theme] command (?=help) > ";
         $input = <STDIN>;
-        $input =~ s/[\r|\n]//g;
+        $input =~ s/[\r\n]//g;
     }
 }
 
@@ -2344,7 +2351,7 @@ sub command42 {
     if ( $new_theme_css eq "\n" ) {
         $new_theme_css = $theme_css;
     } else {
-        $new_theme_css =~ s/[\r|\n]//g;
+        $new_theme_css =~ s/[\r\n]//g;
     }
     $new_theme_css =~ s/^\s*//;
     return $new_theme_css;
@@ -2354,7 +2361,7 @@ sub command61 {
     print "You can now define different LDAP servers.\n";
     print "[ldap] command (?=help) > ";
     $input = <STDIN>;
-    $input =~ s/[\r|\n]//g;
+    $input =~ s/[\r\n]//g;
     while ( $input ne "d" ) {
         if ( $input =~ /^\s*l\s*/i ) {
             $count = 0;
@@ -2393,7 +2400,7 @@ sub command61 {
             print "this LDAP server resides.  Example: ldap.bigfoot.com\n";
             print "hostname: ";
             $name = <STDIN>;
-            $name =~ s/[\r|\n]//g;
+            $name =~ s/[\r\n]//g;
             $ldap_host[$sub] = $name;
 
             print "\n";
@@ -2403,7 +2410,7 @@ sub command61 {
             print "Example: ou=member_directory,o=netcenter.com\n";
             print "base: ";
             $name = <STDIN>;
-            $name =~ s/[\r|\n]//g;
+            $name =~ s/[\r\n]//g;
             $ldap_base[$sub] = $name;
 
             print "\n";
@@ -2412,7 +2419,7 @@ sub command61 {
             print "port is 389.  This is optional.  Press ENTER for default.\n";
             print "port: ";
             $name = <STDIN>;
-            $name =~ s/[\r|\n]//g;
+            $name =~ s/[\r\n]//g;
             $ldap_port[$sub] = $name;
 
             print "\n";
@@ -2421,7 +2428,7 @@ sub command61 {
             print "is also optional.  Press ENTER for default.\n";
             print "charset: ";
             $name = <STDIN>;
-            $name =~ s/[\r|\n]//g;
+            $name =~ s/[\r\n]//g;
             $ldap_charset[$sub] = $name;
 
             print "\n";
@@ -2430,7 +2437,7 @@ sub command61 {
             print "the search.  Default it \"LDAP: hostname\".  Press ENTER for default\n";
             print "name: ";
             $name = <STDIN>;
-            $name =~ s/[\r|\n]//g;
+            $name =~ s/[\r\n]//g;
             $ldap_name[$sub] = $name;
 
             print "\n";
@@ -2439,7 +2446,7 @@ sub command61 {
             print "Default is unlimited.  Press ENTER for default.\n";
             print "maxrows: ";
             $name = <STDIN>;
-            $name =~ s/[\r|\n]//g;
+            $name =~ s/[\r\n]//g;
             $ldap_maxrows[$sub] = $name;
 
             print "\n";
@@ -2448,7 +2455,7 @@ sub command61 {
             print "Default is none, anonymous bind.  Press ENTER for default.\n";
             print "binddn: ";
             $name = <STDIN>;
-            $name =~ s/[\r|\n]//g;
+            $name =~ s/[\r\n]//g;
             $ldap_binddn[$sub] = $name;
 
             print "\n";
@@ -2458,7 +2465,7 @@ sub command61 {
                 print "Now, please specify password for that DN.\n";
                 print "bindpw: ";
                 $name = <STDIN>;
-                $name =~ s/[\r|\n]//g;
+                $name =~ s/[\r\n]//g;
                 $ldap_bindpw[$sub] = $name;
 
                 print "\n";
@@ -2469,7 +2476,7 @@ sub command61 {
         print "Press ENTER for default.\n";
             print "protocol: ";
             $name = <STDIN>;
-            $name =~ s/[\r|\n]//g;
+            $name =~ s/[\r\n]//g;
             $ldap_protocol[$sub] = $name;
 
             print "\n";
@@ -2527,7 +2534,7 @@ sub command61 {
         }
         print "[ldap] command (?=help) > ";
         $input = <STDIN>;
-        $input =~ s/[\r|\n]//g;
+        $input =~ s/[\r\n]//g;
     }
 }
 
@@ -2578,7 +2585,7 @@ sub command91 {
     if ( $new_dsn eq "\n" ) {
         $new_dsn = "";
     } else {
-        $new_dsn =~ s/[\r|\n]//g;
+        $new_dsn =~ s/[\r\n]//g;
         $new_dsn =~ s/^\s+$//g;
     }
     return $new_dsn;
@@ -2593,7 +2600,7 @@ sub command92 {
     if ( $new_table eq "\n" ) {
         $new_table = $addrbook_table;
     } else {
-        $new_table =~ s/[\r|\n]//g;
+        $new_table =~ s/[\r\n]//g;
     }
     return $new_table;
 }
@@ -2618,7 +2625,7 @@ sub command93 {
     if ( $new_dsn eq "\n" ) {
         $new_dsn = "";
     } else {
-        $new_dsn =~ s/[\r|\n]//g;
+        $new_dsn =~ s/[\r\n]//g;
         $new_dsn =~ s/^\s+$//g;
     }
     return $new_dsn;
@@ -2633,7 +2640,7 @@ sub command94 {
     if ( $new_table eq "\n" ) {
         $new_table = $prefs_table;
     } else {
-        $new_table =~ s/[\r|\n]//g;
+        $new_table =~ s/[\r\n]//g;
     }
     return $new_table;
 }
@@ -2649,7 +2656,7 @@ sub command95 {
     if ( $new_field eq "\n" ) {
         $new_field = $prefs_user_field;
     } else {
-        $new_field =~ s/[\r|\n]//g;
+        $new_field =~ s/[\r\n]//g;
     }
     return $new_field;
 }
@@ -2663,7 +2670,7 @@ sub command96 {
     if ( $new_field eq "\n" ) {
         $new_field = $prefs_key_field;
     } else {
-        $new_field =~ s/[\r|\n]//g;
+        $new_field =~ s/[\r\n]//g;
     }
     return $new_field;
 }
@@ -2677,7 +2684,7 @@ sub command97 {
     if ( $new_field eq "\n" ) {
         $new_field = $prefs_val_field;
     } else {
-        $new_field =~ s/[\r|\n]//g;
+        $new_field =~ s/[\r\n]//g;
     }
     return $new_field;
 }
@@ -2702,7 +2709,7 @@ sub command98 {
     if ( $new_dsn eq "\n" ) {
         $new_dsn = "";
     } else {
-        $new_dsn =~ s/[\r|\n]//g;
+        $new_dsn =~ s/[\r\n]//g;
         $new_dsn =~ s/^\s+$//g;
     }
     return $new_dsn;
@@ -2717,7 +2724,7 @@ sub command99 {
     if ( $new_table eq "\n" ) {
         $new_table = $addrbook_global_table;
     } else {
-        $new_table =~ s/[\r|\n]//g;
+        $new_table =~ s/[\r\n]//g;
     }
     return $new_table;
 }
@@ -2772,20 +2779,17 @@ sub commandA1 {
     if ( $new_squirrelmail_default_language eq "\n" ) {
         $new_squirrelmail_default_language = $squirrelmail_default_language;
     } else {
-        $new_squirrelmail_default_language =~ s/[\r|\n]//g;
+        $new_squirrelmail_default_language =~ s/[\r\n]//g;
         $new_squirrelmail_default_language =~ s/^\s+$//g;
     }
     return $new_squirrelmail_default_language;
 }
 # Default Charset
 sub commandA2 {
-#    print "This option controls what character set is used when sending\n";
-#    print "mail and when sending HTML to the browser.  Do not set this\n";
-#    print "to US-ASCII, use ISO-8859-1 instead.  For cyrillic, it is best\n";
-#    print "to use KOI8-R, since this implementation is faster than most\n";
-#    print "of the alternatives\n";
-    print "This option is obsolate. Default charset depends on language\n";
-    print "you have selected in \"Default language\" option.\n";
+    print "This option controls what character set is used when sending\n";
+    print "mail and when sending HTML to the browser. Option works only\n";
+    print "with US English (en_US) translation. Other translations use\n";
+    print "charsets that are set in functions/i18n.php.\n";
     print "\n";
 
     print "[$WHT$default_charset$NRM]: $WHT";
@@ -2793,7 +2797,7 @@ sub commandA2 {
     if ( $new_default_charset eq "\n" ) {
         $new_default_charset = $default_charset;
     } else {
-        $new_default_charset =~ s/[\r|\n]//g;
+        $new_default_charset =~ s/[\r\n]//g;
     }
     return $new_default_charset;
 }
@@ -2829,30 +2833,19 @@ sub commandA4 {
     print "listed. If you enter special key \'none\' - user won't be able to change";
     print "language and interface will use language set it \"Default language\" option.\n";
     print "\n";
-    print "Valid language names are:\n";
-    print " ar (Arabic), bg_BG (Bulgarian), ca_ES (Catalan), cy_GB (Welsh)\n";
-    print " cs_CZ (Chech), da_DK (Danish), de_DE (German), el_GR (Greek),\n";
-    print " en_US (English), es_ES (Spanish), et_EE (Estonian), fi_FI (Finnish),\n";
-    print " fo_FO (Faroese), fr_FR (French), he_IL (Hebrew), hr_HR (Croatian),\n";
-    print " hu_HU (Hungarian), id_ID (Indonesian), is_IS (Icelandic), it_IT (Italian),\n";
-    print " ja_JP (Japanese), ko_KR (Korean), lt_LT (Lithuanian), ms_MY (Malay),\n";
-    print " nl_NL (Dutch), nn_NO (Norwegian (Nynorsk)), no_NO (Norwegian (Bokmal)),\n";
-    print " pl_PL (Polish), pt_BR (Portuguese (Brazil)), pt_PT (Portuguese (Portugal)),\n";
-    print " ro_RO (Romanian), ru_RU (Russian), sk_SK (Slovak), sl_SI (Slovenian),\n";
-    print " sr_YU (Serbian), sv_SE (Swedish), th_TH (Thai), tr_TR (Turkish),\n";
-    print " zh_CN (Chinese Simplified), zh_TW (Chinese Traditional).\n";
+    print "You can find valid language names in doc/i18n.txt.\n";
     print "\n";
     print "[$WHT$available_languages$NRM]: $WHT";
     $new_available_languages = <STDIN>;
     if ( $new_available_languages eq "\n" ) {
         $new_available_languages = $available_languages;
     } else {
-        $new_available_languages =~ s/[\r|\n]//g;
+        $new_available_languages =~ s/[\r\n]//g;
         $new_available_languages =~ s/^\s+$//g;
     }
     return $new_available_languages;
 }
-# Agresive decoding
+# Aggressive decoding
 sub commandA5 {
     print "Enable this option if you want to use CPU and memory intensive decoding\n";
     print "functions. This option allows reading multibyte charset, that are used\n";
@@ -2860,21 +2853,45 @@ sub commandA5 {
     print "even when you have disabled use of recode in Tweaks section.\n";
     print "\n";
 
-    if ( lc($agresive_decoding) eq 'true' ) {
+    if ( lc($aggressive_decoding) eq 'true' ) {
+        $default_value = "y";
+    } else {
+        $default_value = "n";
+    }
+    print "Enable aggressive decoding? (y/n) [$WHT$default_value$NRM]: $WHT";
+    $aggressive_decoding = <STDIN>;
+    if ( ( $aggressive_decoding =~ /^y\n/i ) || ( ( $aggressive_decoding =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
+        $aggressive_decoding = 'true';
+    } else {
+        $aggressive_decoding = 'false';
+    }
+    return $aggressive_decoding;
+}
+
+# Lossy encoding
+sub commandA6 {
+    print "Enable this option if you want to allow lossy charset encoding in message\n";
+    print "composition pages. This option allows charset conversions when output\n";
+    print "charset does not support all symbols used in original charset. Symbols\n";
+    print "unsupported by output charset will be replaced with question marks.\n";
+    print "\n";
+
+    if ( lc($lossy_encoding) eq 'true' ) {
         $default_value = "y";
     } else {
         $default_value = "n";
     }
-    print "Use agresive decoding? (y/n) [$WHT$default_value$NRM]: $WHT";
-    $agresive_decoding = <STDIN>;
-    if ( ( $agresive_decoding =~ /^y\n/i ) || ( ( $agresive_decoding =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
-        $agresive_decoding = 'true';
+    print "Enable lossy encoding? (y/n) [$WHT$default_value$NRM]: $WHT";
+    $lossy_encoding = <STDIN>;
+    if ( ( $lossy_encoding =~ /^y\n/i ) || ( ( $lossy_encoding =~ /^\n/ ) && ( $default_value eq "y" ) ) ) {
+        $lossy_encoding = 'true';
     } else {
-        $agresive_decoding = 'false';
+        $lossy_encoding = 'false';
     }
-    return $agresive_decoding;
+    return $lossy_encoding;
 }
 
+
 # Advanced tree
 sub commandB1 {
     print "Enable this option if you want to use DHTML based folder listing.\n";
@@ -3047,7 +3064,9 @@ sub save_data {
         # string
         print CF "\$available_languages   = '$available_languages';\n";
         # boolean
-        print CF "\$agresive_decoding   = $agresive_decoding;\n";
+        print CF "\$aggressive_decoding   = $aggressive_decoding;\n";
+        # boolean
+        print CF "\$lossy_encoding        = $lossy_encoding;\n";
         print CF "\n";
 
         # string
@@ -3141,8 +3160,10 @@ sub save_data {
         print CF "\$allow_thread_sort        = $allow_thread_sort;\n";
     # boolean
         print CF "\$allow_server_sort        = $allow_server_sort;\n";
-        # boolean
+    # boolean
         print CF "\$allow_charset_search     = $allow_charset_search;\n";
+    # integer
+        print CF "\$allow_advanced_search    = $allow_advanced_search;\n";
         print CF "\n";
     
     # all plugins are strings
@@ -3253,8 +3274,6 @@ sub save_data {
         print CF "\$use_smtp_tls = $use_smtp_tls;\n";
     # string
         print CF "\$session_name = '$session_name';\n";
-    # string
-        print CF "\$allow_advanced_search = '$allow_advanced_search';\n";
 
     print CF "\n";
 
@@ -3323,7 +3342,7 @@ sub set_defaults {
         print "    quit       = Do not change anything\n";
         print "Command >> ";
         $server = <STDIN>;
-        $server =~ s/[\r|\n]//g;
+        $server =~ s/[\r\n]//g;
 
         print "\n";
         if ( $server eq "cyrus" ) {
@@ -3538,8 +3557,8 @@ sub detect_auth_support {
     }
     
     if ($service eq 'SMTP') {
-        $cmd = "AUTH $mech\n";
-        $logout = "QUIT\n";
+        $cmd = "AUTH $mech\r\n";
+        $logout = "QUIT\r\n";
     } elsif ($service eq 'IMAP') {
         $cmd = "A01 AUTHENTICATE $mech\n";
         $logout = "C01 LOGOUT\n";
@@ -3558,7 +3577,7 @@ sub detect_auth_support {
 
     if ($service eq 'SMTP') {
         # Say hello first..
-        print $sock "helo $domain\n";
+        print $sock "HELO $domain\r\n";
         $discard = <$sock>; # Yeah yeah, you're happy to see me..
     }
     print $sock $cmd;
@@ -3573,6 +3592,7 @@ sub detect_auth_support {
     if ($service eq 'SMTP') {
         if (($response =~ /^535/) or ($response =~/^502/)) {
             # Not supported
+            print $sock $logout;
             close $sock;
             return 'NO';
         } elsif ($response =~ /^503/) {
@@ -3582,6 +3602,7 @@ sub detect_auth_support {
     } elsif ($service eq 'IMAP') {
         if ($response =~ /^A01/) {
             # Not supported
+            print $sock $logout;
             close $sock;
             return 'NO';
         }