-# authentication type
-# This sub gets reused for IMAP and SMTP, so pass in the server type as an arg
-# Second arg is the default value to use
-# Possible choices: plain, cram-md5, digest-md5
-# SMTP also can be disabled with 'none'
-sub command112 {
- my($default_val,$service,$inval);
- $service=$_[0];
- $default_val=$_[1];
- print "What authentication mechanism do you want to use for " . $service . " logins?\n";
- if ($service eq "SMTP") {
- 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. (Requires PHP mhash extension)\n";
- print $WHT . "digest-md5" . $NRM . " - Privacy protection - better than cram-md5. (Requires PHP mhash extension)\n";
- print "\n*** YOUR " . $service . " SERVER MUST SUPPORT THE MECHANISM YOU CHOOSE ***\n";
- print "If you don't understand or are unsure, you probably want \"plain\"\n\n";
- if ($service eq "SMTP") {
- print "none, ";
- }
- print "plain, cram-md5, or digest-md5 [$WHT$default_val$NRM]: $WHT";
+
+# 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@microsoft.com
+ $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\@microsoft.com\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 login (SquirrelMail default)
+ print "Testing login:\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 . "login" . $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 $WHT . "\n*** YOUR SMTP SERVER MUST SUPPORT THE MECHANISM YOU CHOOSE HERE ***\n" . $NRM;
+ print "If you don't understand or are unsure, you probably want \"none\"\n\n";
+ print "none, login, cram-md5, or digest-md5 [$WHT$smtp_auth_mech$NRM]: $WHT";