*** autoconf/Makefile.defines.in.orig	Thu Apr 13 18:55:58 2000
--- autoconf/Makefile.defines.in	Tue May 29 20:50:33 2001
***************
*** 29,39 ****
  INCLUDES	= $(INCS_X) $(INCS_XPM)
  
  LIBS_X		= @X_LIBS@ @x_libs@
  LIBS_XPM	= 
  LIBS_JPEG	= @JPEG_LIB@
  LIBS_XEXTS	= 
  LIBS_AFTERSTEP	= -lXt
! LIBRARIES	= $(LIBS_X) $(LIBS_XPM) $(LIBS_JPEG) $(LIBS_XEXTS) $(LIBS_AFTERSTEP)
  
  AFTER_BIN_DIR	= @bindir@
  AFTER_MAN_DIR	= @mandir@/man1
--- 29,40 ----
  INCLUDES	= $(INCS_X) $(INCS_XPM)
  
  LIBS_X		= @X_LIBS@ @x_libs@
+ LIBS_MD		= -lmd
  LIBS_XPM	= 
  LIBS_JPEG	= @JPEG_LIB@
  LIBS_XEXTS	= 
  LIBS_AFTERSTEP	= -lXt
! LIBRARIES	= $(LIBS_X) $(LIBS_MD) $(LIBS_XPM) $(LIBS_JPEG) $(LIBS_XEXTS) $(LIBS_AFTERSTEP)
  
  AFTER_BIN_DIR	= @bindir@
  AFTER_MAN_DIR	= @mandir@/man1
*** asmail.c.orig	Thu Apr 13 19:11:28 2000
--- asmail.c	Tue May 29 20:50:33 2001
***************
*** 969,974 ****
--- 969,975 ----
  int IsPopBox(char *string)
  {
      if ((string[0] == ':' && string[1] == ':') ||
+         (string[0] == '$' && string[1] == '$') ||
          (string[0] == '>' && string[1] == '>'))
          return 1;
      else
*** pop.c.orig	Thu Apr 13 19:08:02 2000
--- pop.c	Tue May 29 20:50:33 2001
***************
*** 28,33 ****
--- 28,36 ----
  #include <sys/types.h>
  #include <sys/time.h>
  
+ /* added by kuramoto */
+ #include <md5.h>
+ 
  #include "socklib.h"
  
  
***************
*** 50,55 ****
--- 53,60 ----
  {
     if (mailboxname[0] == ':' && mailboxname[1] == ':')
        return TYPE_POP;
+    if (mailboxname[0] == '$' && mailboxname[1] == '$')
+       return TYPE_APOP;
     if (mailboxname[0] == '>' && mailboxname[1] == '>')
        return TYPE_IMAP;
     return 0;
***************
*** 138,151 ****
  
  /* Same as imap - for pop3
   */
! int pop3(int sd, int *nm, int *om, char *user, char *password)
  {
      char input[200], output[200], strg[5];
      char *pnt;
      int i;
      
      /* We have connected, now we want to see a "+OK" */
      WAITOK;
      
      /* Server gently said hello. Now pass username and Password */
      sprintf(output, "USER %s\r\n", user);
--- 143,182 ----
  
  /* Same as imap - for pop3
   */
! int pop3(int sd, int *nm, int *om, char *user, char *password, int poptype)
  {
      char input[200], output[200], strg[5];
      char *pnt;
+     char md5con[128], md5key[128];
+     char chksum[64];
      int i;
      
      /* We have connected, now we want to see a "+OK" */
      WAITOK;
+ 
+ if(poptype == TYPE_APOP){
+     
+     /* Cut md5 keyword from reply of POP server. */
+     strncpy(md5key, strchr(input, '<'), 128);
+     strncpy(md5key, md5key, strlen(md5key) - strlen(strchr(md5key, '>')) + 1);
+ 
+     if(DEBUG) fprintf(stderr, "md5key = %s\n", md5key);
+ 
+     /* Now say MD5-checksum for APOP */
+     strncpy(md5con, md5key, 100);
+     strncat(md5con, password, 128);
+     MD5Data(md5con, strlen(md5con), chksum);
+ 
+     if(DEBUG) fprintf(stderr, "chksum = %s\n", chksum);
+ 
+     sprintf(output, "APOP %s %s\r\n", user, chksum);
+     Swrite(sd, output);
+     WAITOK;
+ 
+ } else {
+ 
+     /* We have connected, now we want to see a "+OK" */
+     WAITOK;
      
      /* Server gently said hello. Now pass username and Password */
      sprintf(output, "USER %s\r\n", user);
***************
*** 155,161 ****
      sprintf(output, "PASS %s\r\n", password);
      Swrite(sd, output);
      WAITOK;
!     
      Swrite(sd, "STAT\r\n");
      WAITOK;
      pnt = input + strlen(strg) + 1;
--- 186,194 ----
      sprintf(output, "PASS %s\r\n", password);
      Swrite(sd, output);
      WAITOK;
! 
! }
! 
      Swrite(sd, "STAT\r\n");
      WAITOK;
      pnt = input + strlen(strg) + 1;
***************
*** 234,239 ****
--- 267,273 ----
      if (sscanf(pnt, "%d", &port) != 1)
         switch (type) {
            case TYPE_POP: port = DEFAULTPORT; break;
+ 	  case TYPE_APOP: port = DEFAULTPORT; break;
            case TYPE_IMAP: port = DEFAULTIMAPPORT; break;
         }
  
***************
*** 260,267 ****
      }
      
      /* POP 3 or IMAP mailbox? */
      switch (type) {
!        case TYPE_POP: if (pop3(sd, nmail, oldmail, user, password) == -1) {
            		if (DEBUG) fprintf(stderr, "POP3 connection failed\n");
                          InDuty = 0;
                          return -1;
--- 294,309 ----
      }
      
      /* POP 3 or IMAP mailbox? */
+     if(DEBUG) fprintf(stderr, "Now checking type of server\n");
+ 
      switch (type) {
!        case TYPE_POP: if (pop3(sd, nmail, oldmail, user, password, TYPE_POP) == -1) {
!           		if (DEBUG) fprintf(stderr, "POP3 connection failed\n");
!                         InDuty = 0;
!                         return -1;
!                       }
!                       break;
!        case TYPE_APOP: if (pop3(sd, nmail, oldmail, user, password, TYPE_APOP) == -1) {
            		if (DEBUG) fprintf(stderr, "POP3 connection failed\n");
                          InDuty = 0;
                          return -1;
*** pop.h.orig	Thu Apr 13 19:09:00 2000
--- pop.h	Tue May 29 20:50:33 2001
***************
*** 20,29 ****
  #ifndef __POP_H
  #define __POP_H
  
! #define DEBUG 0
  
  #define TYPE_POP 1
  #define TYPE_IMAP 2
  
  #define ACK_MSG "+OK"
  #define ERR_MSG "+ERR"
--- 20,31 ----
  #ifndef __POP_H
  #define __POP_H
  
! #define DEBUG 0 
! #define APOP 110
  
  #define TYPE_POP 1
  #define TYPE_IMAP 2
+ #define TYPE_APOP 3
  
  #define ACK_MSG "+OK"
  #define ERR_MSG "+ERR"
***************
*** 35,41 ****
  
  int poptype(char *mailboxname);
  int imap(int sd, int *nm, int *om, char *user, char *password, char *mailbox);
! int pop3(int sd, int *nm, int *om, char *user, char *password);
  int pop(char *string, int *nmail, int *oldmail);
  
  #endif
--- 37,43 ----
  
  int poptype(char *mailboxname);
  int imap(int sd, int *nm, int *om, char *user, char *password, char *mailbox);
! int pop3(int sd, int *nm, int *om, char *user, char *password, int poptype);
  int pop(char *string, int *nmail, int *oldmail);
  
  #endif
