From df3988ea8b783a0aa96af7f007dd023123349f8b Mon Sep 17 00:00:00 2001
From: moodler <moodler>
Date: Sat, 16 Nov 2002 03:49:32 +0000
Subject: [PATCH] Separated code for IMAP into IMAP, POP3 and NNTP

---
 auth/README       | 18 ++++++++++++++++++
 auth/imap/lib.php | 15 +++------------
 auth/nntp/lib.php | 29 +++++++++++++++++++++++++++++
 auth/pop3/lib.php | 37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 87 insertions(+), 12 deletions(-)
 create mode 100644 auth/nntp/lib.php
 create mode 100644 auth/pop3/lib.php

diff --git a/auth/README b/auth/README
index a1bdff4867..6262f643bd 100644
--- a/auth/README
+++ b/auth/README
@@ -52,6 +52,24 @@ imap  - Uses an external IMAP server
       a new account is created
 
 
+pop3  - Uses an external POP3 server
+
+    - user logs in using username and password
+    - these are checked against a POP3 server
+    - if correct, user is logged in
+    - if the username doesn't already exist then
+      a new account is created
+
+
+nntp  - Uses an external NNTP server
+
+    - user logs in using username and password
+    - these are checked against an NNTP server
+    - if correct, user is logged in
+    - if the username doesn't already exist then
+      a new account is created
+
+
 db  - Uses an external database to check username/password
     
     - user logs in using username and password
diff --git a/auth/imap/lib.php b/auth/imap/lib.php
index 0f115e2b76..39b5b83e79 100644
--- a/auth/imap/lib.php
+++ b/auth/imap/lib.php
@@ -1,12 +1,12 @@
 <?PHP  // $Id$
-       // Authentication by looking up an IMAP, POP or NNTP server
+       // Authentication by looking up an IMAP server
 
 // This code is completely untested so far  -  IT NEEDS TESTERS!
 // Looks like it should work though ...
 
 $CFG->auth_imaphost   = "127.0.0.1";  // Should be IP number
-$CFG->auth_imaptype   = "imap";       // imap, imapssl, imapcert, pop3, pop3cert, nntp
-$CFG->auth_imapport   = "143";        // 143, 993, 100, 119
+$CFG->auth_imaptype   = "imap";       // imap, imapssl, imapcert
+$CFG->auth_imapport   = "143";        // 143, 993
 
 
 function auth_user_login ($username, $password) {
@@ -25,15 +25,6 @@ function auth_user_login ($username, $password) {
         case "imapcert":
             $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/imap/ssl/novalidate-cert}INBOX";
         break;
-        case "pop3":
-            $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/pop3}INBOX";
-        break;
-        case "pop3cert":
-            $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/pop3/ssl/novalidate-cert}INBOX";
-        break;
-        case "nntp":
-            $host = "{$CFG->auth_imaphost:$CFG->auth_imapport/nntp}";
-        break;
     }
 
     if ($connection = imap_open($host, $username, $password, OP_HALFOPEN)) {
diff --git a/auth/nntp/lib.php b/auth/nntp/lib.php
new file mode 100644
index 0000000000..4223df2917
--- /dev/null
+++ b/auth/nntp/lib.php
@@ -0,0 +1,29 @@
+<?PHP  // $Id$
+       // Authentication by looking up an IMAP, POP or NNTP server
+
+// This code is completely untested so far  -  IT NEEDS TESTERS!
+// Looks like it should work though ...
+
+$CFG->auth_nntphost   = "127.0.0.1";  // Should be IP number
+$CFG->auth_nntpport   = "119";      
+
+
+function auth_user_login ($username, $password) {
+// Returns true if the username and password work
+// and false if they are wrong or don't exist.
+
+    global $CFG;
+
+    $host = "{$CFG->auth_nntphost:$CFG->auth_nntpport/nntp}";
+
+    if ($connection = imap_open($host, $username, $password, OP_HALFOPEN)) {
+        imap_close($connection);
+        return true;
+
+    } else {
+        return false;
+    }
+}
+
+
+?>
diff --git a/auth/pop3/lib.php b/auth/pop3/lib.php
new file mode 100644
index 0000000000..179316e1b7
--- /dev/null
+++ b/auth/pop3/lib.php
@@ -0,0 +1,37 @@
+<?PHP  // $Id$
+       // Authentication by looking up a POP3 server
+
+// This code is completely untested so far  -  IT NEEDS TESTERS!
+// Looks like it should work though ...
+
+$CFG->auth_pop3host   = "127.0.0.1";  // Should be IP number
+$CFG->auth_pop3type   = "pop3";       // pop3, pop3cert
+$CFG->auth_pop3port   = "100";        // 143, 993, 100, 119
+
+
+function auth_user_login ($username, $password) {
+// Returns true if the username and password work
+// and false if they are wrong or don't exist.
+
+    global $CFG;
+
+    switch ($CFG->auth_pop3type) {
+        case "pop3":
+            $host = "{$CFG->auth_pop3host:$CFG->auth_pop3port/pop3}INBOX";
+        break;
+        case "pop3cert":
+            $host = "{$CFG->auth_pop3host:$CFG->auth_pop3port/pop3/ssl/novalidate-cert}INBOX";
+        break;
+    }
+
+    if ($connection = imap_open($host, $username, $password, OP_HALFOPEN)) {
+        imap_close($connection);
+        return true;
+
+    } else {
+        return false;
+    }
+}
+
+
+?>
-- 
2.39.5