+# IMAP authentication type
+# Possible values: plain, cram-md5, digest-md5
+# Now offers to detect supported mechs, assuming server & port are set correctly
+
+sub command112a {
+ print "If you have already set the hostname and port number, I can try to\n";
+ print "detect the mechanisms your IMAP server supports.\n";
+ print "I will try to detect CRAM-MD5 and DIGEST-MD5 support. I can't test\n";
+ print "for \"plain\" without knowing a username and password.\n";
+ print "Auto-detecting is optional - you can safely say \"n\" here.\n";
+ print "\nTry to detect supported mechanisms? [y/N]: ";
+ $inval=<STDIN>;
+ chomp($inval);
+ if ($inval =~ /^y\b/i) {
+ # Yes, let's try to detect.
+ print "Trying to detect IMAP capabilities...\n";
+ my $host = $imapServerAddress . ':'. $imapPort;
+ print "CRAM-MD5:\t";
+ my $tmp = detect_auth_support('IMAP',$host,'CRAM-MD5');
+ if (defined($tmp)) {
+ if ($tmp eq 'YES') {
+ print "$WHT SUPPORTED$NRM\n";
+ } else {
+ print "$WHT NOT SUPPORTED$NRM\n";
+ }
+ } else {
+ print $WHT . " ERROR DETECTING$NRM\n";
+ }
+
+ print "DIGEST-MD5:\t";
+ $tmp = detect_auth_support('IMAP',$host,'DIGEST-MD5');
+ if (defined($tmp)) {
+ if ($tmp eq 'YES') {
+ print "$WHT SUPPORTED$NRM\n";
+ } else {
+ print "$WHT NOT SUPPORTED$NRM\n";
+ }
+ } else {
+ print $WHT . " ERROR DETECTING$NRM\n";
+ }
+
+ }
+ print "\nWhat authentication mechanism do you want to use for IMAP connections?\n\n";
+ print $WHT . "plain" . $NRM . " - Plaintext. If you can do better, you probably should.\n";
+ print $WHT . "cram-md5" . $NRM . " - Slightly better than plaintext.\n";
+ print $WHT . "digest-md5" . $NRM . " - Privacy protection - better than cram-md5.\n";
+ print "\n*** YOUR IMAP SERVER MUST SUPPORT THE MECHANISM YOU CHOOSE HERE ***\n";
+ print "If you don't understand or are unsure, you probably want \"plain\"\n\n";
+ print "plain, cram-md5, or digest-md5 [$WHT$imap_auth_mech$NRM]: $WHT";
+ $inval=<STDIN>;
+ chomp($inval);
+ if ( ($inval =~ /^cram-md5\b/i) || ($inval =~ /^digest-md5\b/i) || ($inval =~ /^plain\b/i)) {
+ return lc($inval);
+ } else {
+ # user entered garbage or default value so nothing needs to be set
+ return $imap_auth_mech;
+ }
+}
+
+
+# SMTP authentication type
+# Possible choices: none, plain, cram-md5, digest-md5
+sub command112b {
+ print "If you have already set the hostname and port number, I can try to\n";
+ print "automatically detect the mechanisms your SMTP server supports.\n";
+ print "Auto-detection is *optional* - you can safely say \"n\" here.\n";
+ print "\nTry to detect auth mechanisms? [y/N]: ";
+ $inval=<STDIN>;
+ chomp($inval);
+ if ($inval =~ /^y\b/i) {
+ # Yes, let's try to detect.
+ print "Trying to detect supported methods (SMTP)...\n";
+
+ # Special case!
+ # Check none by trying to relay to junk@birdbrained.org
+ $host = $smtpServerAddress . ':' . $smtpPort;
+ use IO::Socket;
+ my $sock = IO::Socket::INET->new($host);
+ print "Testing none:\t\t$WHT";
+ if (!defined($sock)) {
+ print " ERROR TESTING\n";
+ close $sock;
+ } else {
+ print $sock "mail from: tester\@squirrelmail.org\n";
+ $got = <$sock>; # Discard
+ print $sock "rcpt to: junk\@birdbrained.org\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";
+ close $sock;
+ }
+ # Try plain (SquirrelMail default)
+ print "Testing plain:\t\t";
+ $tmp=detect_auth_support('SMTP',$host,'LOGIN');
+ if (defined($tmp)) {
+ if ($tmp eq 'YES') {
+ print $WHT . "SUPPORTED$NRM\n";
+ } else {
+ print $WHT . "NOT SUPPORTED$NRM\n";
+ }
+ } else {
+ print $WHT . "ERROR DETECTING$NRM\n";
+ }
+
+ # Try CRAM-MD5
+ print "Testing CRAM-MD5:\t";
+ $tmp=detect_auth_support('SMTP',$host,'CRAM-MD5');
+ if (defined($tmp)) {
+ if ($tmp eq 'YES') {
+ print $WHT . "SUPPORTED$NRM\n";
+ } else {
+ print $WHT . "NOT SUPPORTED$NRM\n";
+ }
+ } else {
+ print $WHT . "ERROR DETECTING$NRM\n";
+ }
+
+
+ print "Testing DIGEST-MD5:\t";
+ $tmp=detect_auth_support('SMTP',$host,'DIGEST-MD5');
+ if (defined($tmp)) {
+ if ($tmp eq 'YES') {
+ print $WHT . "SUPPORTED$NRM\n";
+ } else {
+ print $WHT . "NOT SUPPORTED$NRM\n";
+ }
+ } else {
+ print $WHT . "ERROR DETECTING$NRM\n";
+ }
+ }
+ print "\tWhat authentication mechanism do you want to use for SMTP connections?\n";
+ print $WHT . "none" . $NRM . " - Your SMTP server does not require authorization.\n";
+ print $WHT . "plain" . $NRM . " - Plaintext. If you can do better, you probably should.\n";
+ print $WHT . "cram-md5" . $NRM . " - Slightly better than plaintext.\n";
+ print $WHT . "digest-md5" . $NRM . " - Privacy protection - better than cram-md5.\n";
+ print "\n*** YOUR SMTP SERVER MUST SUPPORT THE MECHANISM YOU CHOOSE HERE ***\n";
+ print "If you don't understand or are unsure, you probably want \"none\"\n\n";
+ print "none, plain, cram-md5, or digest-md5 [$WHT$smtp_auth_mech$NRM]: $WHT";
+ $inval=<STDIN>;
+ chomp($inval);
+ if ($inval =~ /^none\b/i) {
+ # SMTP doesn't necessarily require logins
+ return "none";
+ }
+ if ( ($inval =~ /^cram-md5\b/i) || ($inval =~ /^digest-md5\b/i) ||
+ ($inval =~ /^plain\b/i)) {
+ return lc($inval);
+ } else {
+ # user entered garbage, or default value so nothing needs to be set
+ return $smtp_auth_mech;
+ }
+}
+
+# TLS
+# This sub is reused for IMAP and SMTP
+# Args: service name, default value
+sub command113 {
+ my($default_val,$service,$inval);
+ $service=$_[0];
+ $default_val=$_[1];
+ print "TLS (Transport Layer Security) encrypts the traffic between server and client.\n";
+ print "If you're familiar with SSL, you get the idea.\n";
+ print "To use this feature, your " . $service . " server must offer TLS\n";
+ print "capability, plus PHP 4.3.x with OpenSSL support.\n";
+ print "\nIf your " . $service . " server is localhost, you can safely disable this.\n";
+ print "If it is remote, you may wish to seriously consider enabling this.\n";
+ print "Enable TLS (y/n) [$WHT";
+ if ($default_val eq "true") {
+ print "y";
+ } else {
+ print "n";
+ }
+ print "$NRM]: $WHT";
+ $inval=<STDIN>;
+ $inval =~ tr/yn//cd;
+ return "true" if ( $inval eq "y" );
+ return "false" if ( $inval eq "n" );
+ return $default_val;
+
+
+}
+