--- pine-4.64.orig/doc/tech-notes/background.html
+++ pine-4.64/doc/tech-notes/background.html
@@ -174,7 +174,7 @@
 <OL>
 
 <LI><EM>sendmail-path</EM> in
-<CODE>/usr/local/lib/pine.conf.fixed</CODE>
+<CODE>/etc/pine.conf.fixed</CODE>
 
 <LI><EM>smtp-server</EM> in <CODE>/usr/local/pine.conf.fixed</CODE>
 
@@ -186,9 +186,9 @@
 
 <LI><EM>smtp-server</EM> in the user's <CODE>.pinerc</CODE> file. 
 
-<LI><EM>sendmail-path</EM> in <CODE>/usr/local/lib/pine.conf</CODE>
+<LI><EM>sendmail-path</EM> in <CODE>/etc/pine.conf</CODE>
 
-<LI><EM>smtp-server</EM> in <CODE>/usr/local/pine.conf</CODE>
+<LI><EM>smtp-server</EM> in <CODE>/etc/pine.conf</CODE>
 
 <LI><CODE>DF_SENDMAIL_PATH</CODE> defined at compile time.
 
--- pine-4.64.orig/doc/tech-notes/installation.html
+++ pine-4.64/doc/tech-notes/installation.html
@@ -218,7 +218,7 @@
 <DD> The name of the file which holds <EM>Pine</EM>
 configuration information for
 all users on the system.  Default on UNIX systems is
-<CODE>/usr/local/lib/pine.conf</CODE>.
+<CODE>/etc/pine.conf</CODE>.
 
 <DT> SYSTEM_PINERC_FIXED
 
@@ -226,7 +226,7 @@
 SYSTEM_PINERC, but only for variables that the administrator wants to keep
 fixed.  That is, users are not allowed to change variables that are
 specified in the FIXED file.  Default on UNIX systems is
-<CODE>/usr/local/lib/pine.conf.fixed</CODE>.
+<CODE>/etc/pine.conf.fixed</CODE>.
 
 </DL> <P>
 
@@ -529,9 +529,9 @@
 are no <STRONG>required</STRONG> auxiliary files.  <P>
 
 There are, however, three optional auxiliary files: 
-<CODE>/usr/local/lib/pine.info</CODE>,
-<CODE>/usr/local/lib/pine.conf</CODE>, and
-<CODE>/usr/local/lib/pine.conf.fixed</CODE>.  The file
+<CODE>/etc/pine.info</CODE>,
+<CODE>/etc/pine.conf</CODE>, and
+<CODE>/etc/pine.conf.fixed</CODE>.  The file
 <CODE>pine.info</CODE> contains text on how to get further help on the
 local system.  It is part of the help text for the
 main menu and should probably refer to the local help desk or the system
@@ -650,15 +650,15 @@
 
 <DL COMPACT>
 
-<DT> /usr/local/lib/pine.conf
+<DT> /etc/pine.conf
 
 <DD> Pine's global configuration file. 
 
-<DT> /usr/local/lib/pine.conf.fixed
+<DT> /etc/pine.conf.fixed
 
 <DD> Non-overridable global configuration file. 
 
-<DT> /usr/local/lib/pine.info
+<DT> /etc/pine.info
 
 <DD> Local pointer to system administrator. 
 
--- pine-4.64.orig/doc/tech-notes/porting.html
+++ pine-4.64/doc/tech-notes/porting.html
@@ -307,11 +307,11 @@
 <DT>
  ___
 <DD>
-Reading of <CODE>/usr/local/lib/pine.conf</CODE> 
+Reading of <CODE>/etc/pine.conf</CODE> 
 <DT>
  ___
 <DD>
-Fixing variables and features in <CODE>/usr/local/lib/pine.conf.fixed</CODE> 
+Fixing variables and features in <CODE>/etc/pine.conf.fixed</CODE> 
 <DT>
  ___
 <DD>
--- pine-4.64.orig/doc/tech-notes/config.html
+++ pine-4.64/doc/tech-notes/config.html
@@ -7,8 +7,8 @@
 configuration. In most cases, the compiled-in preferences will suit users
 and administrators just fine. When running <EM>Pine</EM> on a UNIX system, the
 default built-in configuration can be changed by setting variables in the
-system configuration files, <CODE>/usr/local/lib/pine.conf</CODE>
-or <CODE>/usr/local/lib/pine.conf.fixed</CODE>.
+system configuration files, <CODE>/etc/pine.conf</CODE>
+or <CODE>/etc/pine.conf.fixed</CODE>.
 (Actually, these files are whatever the definitions for
 <CODE>SYSTEM_PINERC</CODE> and <CODE>SYSTEM_PINERC_FIXED</CODE>
 in pine/osdep/os-xxx.h are set to.)
@@ -2009,7 +2009,7 @@
 
 <DD> This option tells <EM>Pine</EM> where to look for the "news spool" for
 newsgroups when accessing news locally, rather than via NNTP.  The default
-path is usually <CODE>/usr/spool/news</CODE>. <P>
+path is usually <CODE>/var/spool/news</CODE>. <P>
 
 <DT> <A NAME="newsrc-path"><EM>newsrc-path</EM></A>
 
@@ -3048,7 +3048,7 @@
 alternate spell checker.
 If your Unix system has <EM>ispell</EM> it is probably reasonable to make
 it the default speller by configuring it as the default in the
-system configuration file, <CODE>/usr/local/lib/pine.conf</CODE>.
+system configuration file, <CODE>/etc/pine.conf</CODE>.
 
 <P>
 If this option is not set, then the system's <EM>spell</EM> command is used.
@@ -3559,16 +3559,16 @@
 
 <BLOCKQUOTE>
     <CODE>
-    url-viewers=_TEST("test -n '$&#123;DISPLAY}'")_  /usr/local/bin/netscape,
-		/usr/local/bin/lynx,
+    url-viewers=_TEST("test -n '$&#123;DISPLAY}'")_  /usr/bin/netscape,
+		/usr/bin/lynx,
 		C:&#92;BIN&#92;NETSCAPE.BAT </CODE><BR>
 </BLOCKQUOTE>
 
 This example shows that for the first browser in the list to be used the
 environment variable <CODE>DISPLAY</CODE> must be defined.
-If it is, then the file <CODE>/usr/local/bin/netscape</CODE> must exist.
+If it is, then the file <CODE>/usr/bin/netscape</CODE> must exist.
 If either condition is not met, then the file
-<CODE>/usr/local/bin/lynx</CODE> must exist.
+<CODE>/usr/bin/lynx</CODE> must exist.
 If it doesn't, then the final path and file must
 exist. Note that the last entry is a DOS/Windows path. This is one way
 to support <EM>Pine</EM> running on more than one architecture with the same
--- pine-4.64.orig/doc/tech-notes/low-level.html
+++ pine-4.64/doc/tech-notes/low-level.html
@@ -557,7 +557,7 @@
 
 <DD> If a Tenex-format (or empty) file named <EM>mail.txt</EM> exists in a
 <EM>Pine</EM> user's home directory, this triggers special processing in <EM>Pine</EM>. When
-<EM>INBOX</EM> is opened, mail is automatically moved from <EM>/usr/spool/mail</EM>
+<EM>INBOX</EM> is opened, mail is automatically moved from <EM>/var/mail</EM>
 into <EM>mail.txt</EM> in the user's home directory. 
 
 <DT>
@@ -570,11 +570,11 @@
 <DT> Netnews Format
 
 <DD> The netnews format is a ReadOnly format which uses directories under
-<CODE>/usr/spool/news</CODE> as folders.
-The <CODE>/usr/spool/news/</CODE> prefix is
+<CODE>/var/spool/news</CODE> as folders.
+The <CODE>/var/spool/news/</CODE> prefix is
 removed and all subsequent ``/'' (slash) characters are changed to ``.''
 (period).  For example, the netnews folder name <EM>comp.mail.misc</EM>
-refers to the directory name <CODE>/usr/spool/news/comp/mail/misc</CODE>.
+refers to the directory name <CODE>/var/spool/news/comp/mail/misc</CODE>.
 In addition, the news folder name must appear in the file
 <CODE>/usr/lib/news/active</CODE> for it to be recognized.
 Individual messages are
@@ -1088,7 +1088,7 @@
 
 The second selection is the standard UNIX print command.  The default is
 <EM>lpr</EM>, but it can be changed on a system basis to anything so
-desired in <CODE>/usr/local/lib/pine.conf</CODE>. <P>
+desired in <CODE>/etc/pine.conf</CODE>. <P>
 
 The third selection is
 the user's personal choice for a UNIX print command.  The text to be
--- pine-4.64.orig/doc/tech-notes/cmd-line.html
+++ pine-4.64/doc/tech-notes/cmd-line.html
@@ -87,7 +87,7 @@
 file, execute
 
 <PRE><CODE>
-		pine -conf > /usr/local/lib/pine.conf
+		pine -conf > /etc/pine.conf
 </CODE></PRE>
 <P>
 
@@ -95,7 +95,7 @@
 system configuration file, execute
 
 <PRE><CODE>
-		pine -P old-pine.conf -conf > /usr/local/lib/pine.conf
+		pine -P old-pine.conf -conf > /etc/pine.conf
 </CODE></PRE>
 <P>
 A system configuration file is not required.
@@ -273,7 +273,7 @@
 <DT> -P <EM>pinerc</EM>
 
 <DD> Uses the named file as the system wide configuration file instead of
-<EM>/usr/local/lib/pine.conf</EM> on UNIX, or nothing on <EM>PC-Pine</EM>.
+<EM>/etc/pine.conf</EM> on UNIX, or nothing on <EM>PC-Pine</EM>.
 Pinerc may be either a local file or a remote configuration folder.
 <P>
 
--- pine-4.64.orig/doc/tech-notes/config-notes.html
+++ pine-4.64/doc/tech-notes/config-notes.html
@@ -952,10 +952,10 @@
 </OL>
 <P>
 The fixed configuration file is normally
-<CODE>/usr/local/lib/pine.conf.fixed</CODE>.
+<CODE>/etc/pine.conf.fixed</CODE>.
 <P>
 The system-wide configuration file is normally
-<CODE>/usr/local/lib/pine.conf</CODE> for Unix <EM>Pine</EM> and is normally not
+<CODE>/etc/pine.conf</CODE> for Unix <EM>Pine</EM> and is normally not
 set for <EM>PC-Pine</EM>.
 For <EM>PC-Pine</EM>, if the environment variable <EM>$PINECONF</EM> is set, that
 is used for the system-wide configuration.
@@ -1273,8 +1273,8 @@
 
 <LI> An entry in <CODE>/etc/inetd.conf</CODE> for the alternate service.
 
-<LI> An entry in <CODE>/usr/local/lib/pine.conf</CODE>,
-<CODE>/usr/local/lib/pine.conf.fixed</CODE> or <CODE>~/.pinerc</CODE>. 
+<LI> An entry in <CODE>/etc/pine.conf</CODE>,
+<CODE>/etc/pine.conf.fixed</CODE> or <CODE>~/.pinerc</CODE>. 
 
 </UL>
 
--- pine-4.64.orig/doc/tech-notes.txt
+++ pine-4.64/doc/tech-notes.txt
@@ -333,14 +333,14 @@
           sendmail-path, smtp-server, and compile-time options. The first
           MTA specified in the following list is used:
           
-         1. _sendmail-path_ in /usr/local/lib/pine.conf.fixed
-         2. _smtp-server_ in /usr/local/pine.conf.fixed
+         1. _sendmail-path_ in /etc/pine.conf.fixed
+         2. _smtp-server_ in /etc/pine.conf.fixed
          3. _sendmail-path_ specified on the command line.
          4. _smtp-server_ specified on the command line.
          5. _sendmail-path_ in the user's .pinerc file.
          6. _smtp-server_ in the user's .pinerc file.
-         7. _sendmail-path_ in /usr/local/lib/pine.conf
-         8. _smtp-server_ in /usr/local/pine.conf
+         7. _sendmail-path_ in /etc/pine.conf
+         8. _smtp-server_ in /etc/pine.conf
          9. DF_SENDMAIL_PATH defined at compile time.
         10. SENDMAIL and SENDMAILFLAGS defined at compile time.
             
@@ -670,14 +670,14 @@
    SYSTEM_PINERC
           The name of the file which holds _Pine_ configuration
           information for all users on the system. Default on UNIX
-          systems is /usr/local/lib/pine.conf.
+          systems is /etc/pine.conf.
    SYSTEM_PINERC_FIXED
           The name of the file which holds the same type of information
           as for SYSTEM_PINERC, but only for variables that the
           administrator wants to keep fixed. That is, users are not
           allowed to change variables that are specified in the FIXED
           file. Default on UNIX systems is
-          /usr/local/lib/pine.conf.fixed.
+          /etc/pine.conf.fixed.
           
    There are a couple of more obscure options which are in the source
    code because a few people have asked for them or because we changed
@@ -876,8 +876,8 @@
    auxiliary files.
    
    There are, however, three optional auxiliary files:
-   /usr/local/lib/pine.info, /usr/local/lib/pine.conf, and
-   /usr/local/lib/pine.conf.fixed. The file pine.info contains text on
+   /etc/pine.info, /etc/pine.conf, and
+   /etc/pine.conf.fixed. The file pine.info contains text on
    how to get further help on the local system. It is part of the help
    text for the main menu and should probably refer to the local help
    desk or the system administrator. If this file doesn't exist a generic
@@ -976,11 +976,11 @@
    This section lists the various files which _Pine_ uses which are not
    email folders. All of these are the default names of files, they may
    vary based on _Pine_'s configuration.
-   /usr/local/lib/pine.conf
+   /etc/pine.conf
           Pine's global configuration file.
-   /usr/local/lib/pine.conf.fixed
+   /etc/pine.conf.fixed
           Non-overridable global configuration file.
-   /usr/local/lib/pine.info
+   /etc/pine.info
           Local pointer to system administrator.
    ~/.pinerc
           Personal configuration file for each user.
@@ -1200,10 +1200,10 @@
           Configuration: Prints a sample system configuration file to the
           screen or standard output. To generate an initial system
           configuration file, execute
-                pine -conf > /usr/local/lib/pine.conf
+                pine -conf > /etc/pine.conf
           To generate a system configuration file using settings from an
           old system configuration file, execute
-                pine -P old-pine.conf -conf > /usr/local/lib/pine.conf
+                pine -P old-pine.conf -conf > /etc/pine.conf
           A system configuration file is not required.
    -convert_sigs _-p pinerc_
           Convert signatures contained in signature files into literal
@@ -1318,7 +1318,7 @@
           configuration folder.
    -P _pinerc_
           Uses the named file as the system wide configuration file
-          instead of _/usr/local/lib/pine.conf_ on UNIX, or nothing on
+          instead of _/etc/pine.conf_ on UNIX, or nothing on
           _PC-Pine_. Pinerc may be either a local file or a remote
           configuration folder.
    -passfile _passfile_
@@ -1526,8 +1526,8 @@
    configuration. In most cases, the compiled-in preferences will suit
    users and administrators just fine. When running _Pine_ on a UNIX
    system, the default built-in configuration can be changed by setting
-   variables in the system configuration files, /usr/local/lib/pine.conf
-   or /usr/local/lib/pine.conf.fixed. (Actually, these files are whatever
+   variables in the system configuration files, /etc/pine.conf
+   or /etc/pine.conf.fixed. (Actually, these files are whatever
    the definitions for SYSTEM_PINERC and SYSTEM_PINERC_FIXED in
    pine/osdep/os-xxx.h are set to.) The location of the pine.conf file
    can be changed with the -P command line argument. Both _Pine_ and
@@ -3015,7 +3015,7 @@
    _news-spool-directory_
           This option tells _Pine_ where to look for the "news spool" for
           newsgroups when accessing news locally, rather than via NNTP.
-          The default path is usually /usr/spool/news.
+          The default path is usually /var/spool/news.
    _newsrc-path_
           This option overrides the default name _Pine_ uses for your
           "newsrc" news status and subscription file. If set, _Pine_ will
@@ -3761,7 +3761,7 @@
           spell checker. If your Unix system has _ispell_ it is probably
           reasonable to make it the default speller by configuring it as
           the default in the system configuration file,
-          /usr/local/lib/pine.conf.
+          /etc/pine.conf.
           If this option is not set, then the system's _spell_ command is
           used. The spell command does not work the same as the alternate
           speller. It produces a list of misspelled words on its standard
@@ -4156,12 +4156,12 @@
           relative to your home directory).
           Now for an example:
           
-     url-viewers=_TEST("test -n '${DISPLAY}'")_ /usr/local/bin/netscape,
-     /usr/local/bin/lynx, C:\BIN\NETSCAPE.BAT
+     url-viewers=_TEST("test -n '${DISPLAY}'")_ /usr/bin/netscape,
+     /usr/bin/lynx, C:\BIN\NETSCAPE.BAT
           This example shows that for the first browser in the list to be
           used the environment variable DISPLAY must be defined. If it
-          is, then the file /usr/local/bin/netscape must exist. If either
-          condition is not met, then the file /usr/local/bin/lynx must
+          is, then the file /usr/bin/netscape must exist. If either
+          condition is not met, then the file /usr/bin/lynx must
           exist. If it doesn't, then the final path and file must exist.
           Note that the last entry is a DOS/Windows path. This is one way
           to support _Pine_ running on more than one architecture with
@@ -10121,10 +10121,10 @@
     5. the system-wide _fixed_ configuration file (Unix _Pine_ only)
        
    The fixed configuration file is normally
-   /usr/local/lib/pine.conf.fixed.
+   /etc/pine.conf.fixed.
    
    The system-wide configuration file is normally
-   /usr/local/lib/pine.conf for Unix _Pine_ and is normally not set for
+   /etc/pine.conf for Unix _Pine_ and is normally not set for
    _PC-Pine_. For _PC-Pine_, if the environment variable _$PINECONF_ is
    set, that is used for the system-wide configuration. This location can
    be set or changed on the command line with the -P flag. The
@@ -10384,8 +10384,8 @@
      * A program that implements the SMTP or ESMTP protocol via stdio.
      * An entry in /etc/services for the alternate service.
      * An entry in /etc/inetd.conf for the alternate service.
-     * An entry in /usr/local/lib/pine.conf,
-       /usr/local/lib/pine.conf.fixed or ~/.pinerc.
+     * An entry in /etc/pine.conf,
+       /etc/pine.conf.fixed or ~/.pinerc.
      _________________________________________________________________
    
 MIME.Types file
@@ -11090,7 +11090,7 @@
           If a Tenex-format (or empty) file named _mail.txt_ exists in a
           _Pine_ user's home directory, this triggers special processing
           in _Pine_. When _INBOX_ is opened, mail is automatically moved
-          from _/usr/spool/mail_ into _mail.txt_ in the user's home
+          from _/var/mail_ into _mail.txt_ in the user's home
           directory.
           The format used by _PC-Pine_ is identical to the Tenex format,
           with two exceptions: the folder name ends with _.MTX_ instead
@@ -11099,11 +11099,11 @@
           newlines.
    Netnews Format
           The netnews format is a ReadOnly format which uses directories
-          under /usr/spool/news as folders. The /usr/spool/news/ prefix
+          under /var/spool/news as folders. The /var/spool/news/ prefix
           is removed and all subsequent ``/'' (slash) characters are
           changed to ``.'' (period). For example, the netnews folder name
           _comp.mail.misc_ refers to the directory name
-          /usr/spool/news/comp/mail/misc. In addition, the news folder
+          /var/spool/news/comp/mail/misc. In addition, the news folder
           name must appear in the file /usr/lib/news/active for it to be
           recognized. Individual messages are stored as files in that
           directory, with file names being the ASCII form of a number
@@ -11160,7 +11160,7 @@
    line flag to intentionally open a mailbox read-only.
    
    _Pine_ locking on UNIX systems works by creating lock files in _/tmp_
-   of the form _\usr\spool\mail\joe. _The system call _flock()_ is then
+   of the form _\var\mail\joe. _The system call _flock()_ is then
    used on these files; the existence of the file alone does not
    constitute a lock. This lock is created when the folder is opened and
    destroyed when it is closed. When the folder is actually being
@@ -11569,7 +11569,7 @@
    
    The second selection is the standard UNIX print command. The default
    is _lpr_, but it can be changed on a system basis to anything so
-   desired in /usr/local/lib/pine.conf.
+   desired in /etc/pine.conf.
    
    The third selection is the user's personal choice for a UNIX print
    command. The text to be printed is piped into the command. _Enscript_
@@ -12023,9 +12023,9 @@
           Error messages for incorrect terminal types (try "foo" and
           "vt52")
    ___
-          Reading of /usr/local/lib/pine.conf
+          Reading of /etc/pine.conf
    ___
-          Fixing variables and features in /usr/local/lib/pine.conf.fixed
+          Fixing variables and features in /etc/pine.conf.fixed
    ___
           Flag command (check message status changed in mail folder)
    ___
--- pine-4.64.orig/doc/pine.1
+++ pine-4.64/doc/pine.1
@@ -309,7 +309,7 @@
 .if n .ta 2.8i
 .if t .ta 2.1i
 
-/usr/spool/mail/xxxx	Default folder for incoming mail.
+/var/mail/xxxx		Default folder for incoming mail.
 .br
 ~/mail	Default directory for mail folders.
 .br
@@ -333,13 +333,13 @@
 .br
 /etc/mime.types	System-wide file ext. to MIME type mapping
 .br
-/usr/local/lib/pine.info	Local pointer to system administrator.
+/etc/pine.info	Local pointer to system administrator.
 .br
-/usr/local/lib/pine.conf	System-wide configuration file.
+/etc/pine.conf	System-wide configuration file.
 .br
-/usr/local/lib/pine.conf.fixed	 Non-overridable configuration file.
+/etc/pine.conf.fixed	 Non-overridable configuration file.
 .br
-/tmp/.\\usr\\spool\\mail\\xxxx	Per-folder mailbox lock files.
+/tmp/.\\var\\mail\\xxxx	Per-folder mailbox lock files.
 .br
 ~/.pine-interrupted-mail	Message which was interrupted.
 .br
--- pine-4.64.orig/build
+++ pine-4.64/build
@@ -1,4 +1,5 @@
 #!/bin/sh
+set -e
 #
 # $Id: build 14054 2005-05-04 21:22:22Z jpf $
 #
@@ -78,7 +79,7 @@
 # We will complain if we pass "none",
 # but this gets overridden if we find the ssl dir
 SSL=none
-DEFSSLD=/usr/local/ssl
+DEFSSLD=/usr
 SSLD=
 NOCC=
 LLIBS=
@@ -243,9 +244,9 @@
         if [ "$NOLDAP" != "1" -a -f contrib/ldap-setup -a \
 	     \( "$LLIBS" != "1" -o "$LFLAGS" != "1" \) ]
 	then
-	  contrib/ldap-setup $pinetarg $maketarg
+#	  contrib/ldap-setup $pinetarg $maketarg
 # Allow for override of either of these separately.
-	  case "$?" in
+	  case 3 in
 	    1) if [ "$LLIBS" != "1" ]
 	       then
 		 L1="'LDAPLIBS=../ldap/libraries/libldap.a ../ldap/libraries/liblber.a'"
--- pine-4.64.orig/pico/osdep/term.inf
+++ pine-4.64/pico/osdep/term.inf
@@ -139,8 +139,8 @@
      */
     kpinsert("\033[4J", KEY_PGUP, 1);
     kpinsert("\033[3J", KEY_PGDN, 1);
-    kpinsert("\033[2J", KEY_HOME, 1);
-    kpinsert("\033[N",  KEY_END, 1);
+    kpinsert("\033[1~", KEY_HOME, 1);
+    kpinsert("\033[4~", KEY_END, 1);
 
     /*
      * vt220?
--- pine-4.64.orig/pine/osdep/os-lnx.h
+++ pine-4.64/pine/osdep/os-lnx.h
@@ -163,10 +163,10 @@
 
 /*----- System-wide config file ----------------------------------------*/
 #ifndef SYSTEM_PINERC
-#define SYSTEM_PINERC             "/usr/local/lib/pine.conf"
+#define SYSTEM_PINERC             "/etc/pine.conf"
 #endif
 #ifndef SYSTEM_PINERC_FIXED
-#define SYSTEM_PINERC_FIXED       "/usr/local/lib/pine.conf.fixed"
+#define SYSTEM_PINERC_FIXED       "/etc/pine.conf.fixed"
 #endif
 
 
@@ -234,7 +234,7 @@
 
 /*--------- Program employed by users to change their password ---------*/
 #ifndef	PASSWD_PROG
-#define	PASSWD_PROG	"/bin/passwd"
+#define	PASSWD_PROG	"/usr/bin/passwd"
 #endif
 
 
--- pine-4.64.orig/pine/reply.c
+++ pine-4.64/pine/reply.c
@@ -4681,6 +4681,17 @@
 	*(*d)++ = 'X';				/* write mask */
 	*(*d)++ = '-';
     }
+    /* these are qmail headers (or rather standards which originated with qmail) */
+    if((*s == 'D' || *s == 'd')
+       && (!struncmp(s+1, "elivered-to:", 12))){
+	*(*d)++ = 'X';				/* write mask */
+	*(*d)++ = '-';
+    }
+    if((*s == 'M' || *s == 'm')
+       && (!struncmp(s+1, "ailing-list:", 12))){
+	*(*d)++ = 'X';				/* write mask */
+	*(*d)++ = '-';
+    }
 }
 
 
--- pine-4.64.orig/pine/init.c
+++ pine-4.64/pine/init.c
@@ -154,7 +154,7 @@
 CONF_TXT_T cf_text_ldap_server[] =		"LDAP servers for looking up addresses.";
 #endif	/* ENABLE_LDAP */
 
-CONF_TXT_T cf_text_inbox_path[] =		"Path of (local or remote) INBOX, e.g. ={mail.somewhere.edu}inbox\n# Normal Unix default is the local INBOX (usually /usr/spool/mail/$USER).";
+CONF_TXT_T cf_text_inbox_path[] =		"Path of (local or remote) INBOX, e.g. ={mail.somewhere.edu}inbox\n# Normal Unix default is the local INBOX (usually /var/mail/$USER).";
 
 CONF_TXT_T cf_text_incoming_folders[] =	"List of incoming msg folders besides INBOX, e.g. ={host2}inbox, {host3}inbox\n# Syntax: optnl-label {optnl-imap-host-name}folder-path";
 
@@ -346,7 +346,7 @@
 
 CONF_TXT_T cf_text_news_active[] =	"Path and filename of news configuration's active file.\n# The default is typically \"/usr/lib/news/active\".";
 
-CONF_TXT_T cf_text_news_spooldir[] =	"Directory containing system's news data.\n# The default is typically \"/usr/spool/news\"";
+CONF_TXT_T cf_text_news_spooldir[] =	"Directory containing system's news data.\n# The default is typically \"/var/spool/news\"";
 
 CONF_TXT_T cf_text_upload_cmd[] =	"Path and filename of the program used to upload text from your terminal\n# emulator's into Pine's composer.";
 
@@ -428,7 +428,7 @@
 
 /*----------------------------------------------------------------------
 These are the variables that control a number of pine functions.  They
-come out of the .pinerc and the /usr/local/lib/pine.conf files.  Some can
+come out of the .pinerc and the /etc/pine.conf files.  Some can
 be set by the user while in Pine.  Eventually all the local ones should
 be so and maybe the global ones too.
 
--- pine-4.64.orig/pine/send.c
+++ pine-4.64/pine/send.c
@@ -727,8 +727,10 @@
 		}
 	    }
 	    else{
+		/* Workaround for Maildir */
+		/*
 		q_status_message1(SM_ORDER | SM_DING, 3, 3,
-				  "Can't open Postponed mailbox: %.200s", mbox);
+				  "Can't open Postponed mailbox: %.200s", mbox); */
 		if(stream)
 		  pine_mail_close(stream);
 	    }
--- pine-4.64.orig/pine/filter.c
+++ pine-4.64/pine/filter.c
@@ -3064,7 +3064,7 @@
 #endif
 
 #ifndef SYSTEM_PINE_INFO_PATH
-#define SYSTEM_PINE_INFO_PATH "/usr/local/lib/pine.info"
+#define SYSTEM_PINE_INFO_PATH "/etc/pine.info"
 #endif
 #define CHTML_VAR_EXPAND(S) (!strcmp(S, "PINE_INFO_PATH")   \
 			     ? SYSTEM_PINE_INFO_PATH : S)
--- pine-4.64.orig/pine/makefile.lnx
+++ pine-4.64/pine/makefile.lnx
@@ -60,7 +60,7 @@
 LDAPOFILES=   addrbook.o adrbkcmd.o args.o bldaddr.o init.o \
 	      mailview.o other.o pine.o strings.o takeaddr.o
 
-STDLIBS=     -lncurses
+STDLIBS=     -lncurses -lcrypt
 LOCLIBS=     $(PICODIR)/libpico.a $(CCLIENTDIR)/c-client.a
 LIBS=        $(LOCLIBS) $(LDAPLIBS) $(STDLIBS) \
              `cat $(CCLIENTDIR)/LDFLAGS`
--- pine-4.64.orig/pine/mailindx.c
+++ pine-4.64/pine/mailindx.c
@@ -4941,10 +4941,10 @@
 	        break;
 
 	      case iSize:
-		/* 0 ... 9999 */
-		if((l = fetch_size(idata)) < 10*1000L)
+		/* 0 ... 99999 */
+		if((l = fetch_size(idata)) < 100*1000L)
 		  sprintf(str, "(%lu)", l);
-		/* 10K ... 999K */
+		/* 100K ... 999K */
 		else if(l < 1000L*1000L - 1000L/2){
 		    l = l/1000L + (l%1000L >= 1000L/2 ? 1L : 0L);
 		    sprintf(str, "(%luK)", l);
--- pine-4.64.orig/pine/pine-use.c
+++ pine-4.64/pine/pine-use.c
@@ -45,7 +45,7 @@
 #include <sys/stat.h>
 
 #ifndef MAILSPOOLPCTS
-#define MAILSPOOLPCTS "/usr/spool/mail/%s"
+#define MAILSPOOLPCTS "/var/mail/%s"
 /* #define MAILSPOOLPCTS "/usr/mail/%s" */
 #endif
 
--- pine-4.64.orig/pine/pine.c
+++ pine-4.64/pine/pine.c
@@ -529,6 +529,7 @@
 	pine_state->beginning_of_year = first_run_of_year();
     }
 
+    privs_drop();
     set_collation(F_OFF(F_DISABLE_SETLOCALE_COLLATE, ps_global),
 		  F_ON(F_ENABLE_SETLOCALE_CTYPE, ps_global));
 
--- pine-4.64.orig/imap/docs/imaprc.txt
+++ pine-4.64/imap/docs/imaprc.txt
@@ -155,8 +155,8 @@
    Sets the directory in which the user's data can be found.  A user's
    folders can be found in a subdirectory of the black box directory
    named with the user's username.  For example, if the blackbox
-   directory is /usr/spool/folders/, user jones' data can be found
-   in /usr/spool/folders/jones/.  The user's black-box directory is
+   directory is /var/spool/folders/, user jones' data can be found
+   in /var/spool/folders/jones/.  The user's black-box directory is
    the location of folders, .mminit, .imaprc, .newsrc, and all other
    files used by c-client; internally, it sets c-client's idea of the
    user's ``home directory'', overriding /etc/passwd.
@@ -398,14 +398,14 @@
     If non-zero, a warning message is given if an attempt to create a
     lock file fails.  Otherwise, EACCES is treated as a "silent failure",
     and it proceeds without trying to use the lock file.  This is for
-    the benefit of users on systems with paranoid /usr/spool/mail
-    protections which don't let users create /usr/spool/mail/$(USER).lock
+    the benefit of users on systems with paranoid /var/mail
+    protections which don't let users create /var/mail/$(USER).lock
     files; these unfortunate users would be harassed with a flood of
     error messages otherwise.  The problem is that on SVR4, if EACCES
     remains disabled and fcntl() locking is also disabled, then there is
     no locking at all which is doubleplus-ungood.
 
-    If the site is paranoid on /usr/spool/mail protections AND if there
+    If the site is paranoid on /var/mail protections AND if there
     is no fcntl() locking (SVR4) or usable flock() locking (e.g. NFS),
     then there is no way to win.  Find a different system to use.
 
--- pine-4.64.orig/imap/docs/locking.txt
+++ pine-4.64/imap/docs/locking.txt
@@ -242,7 +242,7 @@
 timeout for this lock, after which it is broken on the presumption
 that it is a stale lock.  If it can not create the .lock file due to
 an EACCES (protection failure) error, it once silently proceeded
-without this lock; this was for systems which protect /usr/spool/mail
+without this lock; this was for systems which protect /var/mail
 from unprivileged processes creating files.  Today, c-client reports
 an error unless it is built otherwise.  The purpose of this lock is to
 prevent against unfavorable interactions with mail delivery.
@@ -265,7 +265,7 @@
 
      Mail delivery daemons use lock (1), (2), or both.  Lock (1) works
 over NFS; lock (2) is the only one that works on sites that protect
-/usr/spool/mail against unprivileged file creation.  Prudent mail
+/var/mail against unprivileged file creation.  Prudent mail
 delivery daemons use both forms of locking, and of course so does
 c-client.
 
@@ -322,7 +322,7 @@
 the mail file is NFS-mounted.
 
      What this means is that there is *no* locking protection at all
-in the case of a client using an NFS-mounted /usr/spool/mail that does
+in the case of a client using an NFS-mounted /var/mail that does
 not permit file creation by unprivileged programs.  It is impossible,
 under these circumstances, for an unprivileged program to do anything
 about it.  Worse, if EACCES errors on .lock file creation are no-op'ed
--- pine-4.64.orig/imap/src/c-client/mail.c
+++ pine-4.64/imap/src/c-client/mail.c
@@ -776,6 +776,8 @@
 {
   int remote = ((*pat == '{') || (ref && *ref == '{'));
   DRIVER *d;
+  DRIVER *inbox_driver;
+  int only_maildir;
   if (ref && (strlen (ref) > NETMAXMBX)) {
     char tmp[MAILTMPLEN];
     sprintf (tmp,"Invalid LIST reference specification: %.80s",ref);
@@ -796,9 +798,15 @@
   }
 				/* otherwise do for all DTB's */
   else for (d = maildrivers; d; d = d->next)
+    {
+    only_maildir = ((inbox_driver = mail_valid( NIL, "INBOX", NIL )) &&
+       !strcmp( inbox_driver->name, "maildir" ) );
     if (d->scan && !((d->flags & DR_DISABLE) ||
-		     ((d->flags & DR_LOCAL) && remote)))
+		     ((d->flags & DR_LOCAL) && remote)) ||
+        (only_maildir && strcmp( d->name, "maildir" ) )
+       )
       (d->scan) (NIL,ref,pat,contents);
+    }
 }
 
 /* Mail list mailboxes
--- pine-4.64.orig/imap/src/c-client/mail.h
+++ pine-4.64/imap/src/c-client/mail.h
@@ -790,6 +790,7 @@
   unsigned int spare7 : 1;	/* seventh spare bit */
   unsigned int spare8 : 1;	/* eighth spare bit */
   void *sparep;			/* spare pointer */
+  void *maildirp;		/* for the Maildir driver */
   unsigned long user_flags;	/* user-assignable flags */
 } MESSAGECACHE;
 
--- pine-4.64.orig/imap/src/osdep/unix/env_unix.c
+++ pine-4.64/imap/src/osdep/unix/env_unix.c
@@ -988,12 +988,17 @@
   struct stat sb;
 				/* flush absurd file name */
   if (strlen (file) > 512) return NIL;
+
+  privs_set();
 				/* build lock filename */
   sprintf (base->lock,"%s.lock",file);
 				/* assume no pipe */
   base->pipei = base->pipeo = -1;
   do {				/* make sure not symlink */
-    if (!(j = chk_notsymlink (base->lock,&sb))) return NIL;
+    if (!(j = chk_notsymlink (base->lock,&sb))) {
+      privs_drop();
+      return NIL;
+    }
 				/* time out if file older than 5 minutes */
     if ((j > 0) && ((time (0)) >= (sb.st_ctime + locktimeout * 60))) i = 0;
 				/* try to create the lock */
@@ -1011,9 +1016,11 @@
       break;
     case T:			/* success, make sure others can break lock */
       chmod (base->lock,(int) lock_protection);
+      privs_drop();
       return LONGT;
     }
   } while (i--);		/* until out of retries */
+  privs_drop();
   if (retry < 0) {		/* still returning retry after locktimeout? */
     if (!(j = chk_notsymlink (base->lock,&sb))) return NIL;
     if ((j > 0) && ((time (0)) < (sb.st_ctime + locktimeout * 60))) {
@@ -1112,7 +1119,11 @@
 				/* nuke the pipes */
       close (base->pipei); close (base->pipeo);
     }
-    else ret = !unlink (base->lock);
+    else {
+     privs_set();
+     ret = !unlink (base->lock);
+     privs_drop();
+    }
   }
   return ret;
 }
--- pine-4.64.orig/imap/src/osdep/unix/env_unix.h
+++ pine-4.64/imap/src/osdep/unix/env_unix.h
@@ -56,7 +56,7 @@
  * for they are subtle and quick to anger.
  */
 
-#define MANDATORYLOCKPROT 0666	/* don't change this */
+#define MANDATORYLOCKPROT 0600	/* don't change this */
 
 /* Function prototypes */
 
--- pine-4.64.orig/imap/src/osdep/unix/Makefile
+++ pine-4.64/imap/src/osdep/unix/Makefile
@@ -21,7 +21,7 @@
 # Command line build parameters
 
 EXTRAAUTHENTICATORS=
-EXTRADRIVERS=mbox
+EXTRADRIVERS=maildir mbox
 PASSWDTYPE=std
 SSLTYPE=nopwd
 IP=4
@@ -41,8 +41,8 @@
 
 # Extended flags needed for SSL.  You may need to modify.
 
-SSLDIR=/usr/local/ssl
-SSLCERTS=$(SSLDIR)/certs
+SSLDIR=/usr
+SSLCERTS=/etc/ssl/certs
 SSLKEYS=$(SSLCERTS)
 SSLINCLUDE=$(SSLDIR)/include
 SSLLIB=$(SSLDIR)/lib
@@ -84,8 +84,8 @@
 SIGTYPE=bsd
 CRXTYPE=std
 ACTIVEFILE=/usr/lib/news/active
-SPOOLDIR=/usr/spool
-MAILSPOOL=$(SPOOLDIR)/mail
+SPOOLDIR=/var/spool
+MAILSPOOL=/var/mail
 NEWSSPOOL=$(SPOOLDIR)/news
 RSHPATH=/usr/ucb/rsh
 LOCKPGM=/etc/mlock
@@ -119,7 +119,7 @@
 # Standard distribution build parameters
 
 DEFAULTAUTHENTICATORS=md5 pla log
-DEFAULTDRIVERS=imap nntp pop3 mh mx mbx tenex mtx mmdf unix news phile
+DEFAULTDRIVERS=maildir imap nntp pop3 mh mx mbx tenex mtx mmdf unix news phile
 
 
 # Normally no need to change any of these
@@ -128,7 +128,7 @@
 BINARIES=osdep.o mail.o misc.o newsrc.o smanager.o utf8.o siglocal.o \
  dummy.o pseudo.o netmsg.o flstring.o fdstring.o \
  rfc822.o nntp.o smtp.o imap4r1.o pop3.o \
- unix.o mbx.o mmdf.o tenex.o mtx.o news.o phile.o mh.o mx.o
+ unix.o mbx.o mmdf.o tenex.o mtx.o news.o phile.o mh.o mx.o maildir.o privs.o
 CFLAGS=-g
 
 CAT=cat
@@ -636,7 +636,7 @@
 	 SPOOLDIR=/var/spool \
 	 ACTIVEFILE=/var/lib/news/active \
 	 RSHPATH=/usr/bin/rsh \
-	 BASECFLAGS="-g -fno-omit-frame-pointer $(GCCOPTLEVEL)" \
+#	 BASECFLAGS="-g -fno-omit-frame-pointer $(GCCOPTLEVEL)" \
 	 BASELDFLAGS="-lcrypt"
 
 sl4:	# Secure Linux using libc4
@@ -846,7 +846,8 @@
 tenex.o: mail.h misc.h osdep.h dummy.h
 unix.o: mail.h misc.h osdep.h unix.h pseudo.h dummy.h
 utf8.o: mail.h misc.h osdep.h utf8.h
-
+maildir.o: mail.h misc.h osdep.h maildir.h dummy.h
+privs.o: privs.c privs.h
 
 # OS-dependent
 
--- pine-4.64.orig/imap/src/osdep/unix/os_lnx.c
+++ pine-4.64/imap/src/osdep/unix/os_lnx.c
@@ -44,3 +44,5 @@
 #include "gr_waitp.c"
 #include "tz_sv4.c"
 #include "flocklnx.c"
+
+#include "privs.h"
--- pine-4.64.orig/imap/src/osdep/unix/os_slx.h
+++ pine-4.64/imap/src/osdep/unix/os_slx.h
@@ -41,6 +41,7 @@
 #include <fcntl.h>
 #include <syslog.h>
 #include <sys/file.h>
+#include <time.h>
 
 
 /* Linux gets this wrong */
--- pine-4.64.orig/imap/src/osdep/unix/maildir.c
+++ pine-4.64/imap/src/osdep/unix/maildir.c
@@ -0,0 +1,1299 @@
+/*
+ * Maildir Module for PINE 4.0x - fourth release, use with CARE! 
+ *
+ * Author:      Mattias Larsson <ml@techno.org>
+ *
+ * Version:     21.07.98
+ *
+ * Please read the README.maildir file before using this module!
+ *
+ * If you have any questions, please e-mail ml@techno.org 
+ *
+ * Multiple inboxes patch by Dean Gaudet <dgaudet@arctic.org>
+ * Maildir subfolders patch by Piotr Roszatycki <dexter@debian.org>
+ *
+ * =================================================
+ *
+ * Based on the IMAP2 maildir routines by:
+ *
+ * Author:      Eric Green
+ *              Bloodhounds International Inc.
+ *              thrytis@imaxx.net
+ *
+ * Additional contributions from:
+ *              Aidas Kasparas (kaspar@soften.ktu.lt)
+ *
+ * Date:        27 April 1997
+ * Last Edited: 13 June 1997
+ *
+ * Based (heavily) on mh.c and other c-client library files by Mark Crispin:
+ *
+ *              Mark Crispin
+ *              Networks and Distributed Computing
+ *              Computing & Communications
+ *              University of Washington
+ *              Administration Building, AG-44
+ *              Seattle, WA  98195
+ *              Internet: MRC@CAC.Washington.EDU
+ *
+ * Copyright 1995 by the University of Washington
+ *
+ *  Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appears in all copies and that both the
+ * above copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the University of Washington not be
+ * used in advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  This software is made
+ * available "as is", and
+ * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
+ * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
+ * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
+ * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* CONFIGURABLE OPTIONS - PLEASE CHECK THESE OUT */
+
+#undef NO_MAILDIR_FIDDLE	/* disallow Maildir with Maildir in the
+				name. This is useful in an ISP setup
+				using the IMAP daemon. #undef it if you
+				are running a normal pine and know what
+				you are doing */
+
+#undef NO_ABSOLUTE_PATHS	/* if you define this, all paths
+				use your HOMEDIR is the root instead
+				of the actual root of the machine. This
+				is also useful in an ISP setup with
+				IMAP */
+
+#undef NO_UID_VALIDITIY		/* define this if you want the UID's not
+				to be persistent over sessions. Use this
+				if you use another client to read the
+				maildir that screws up the special way
+				in which we store UIDs. Do not enable
+				unless you are sure you need it. */
+	
+/* END CONFIGURATION */
+
+#define MTA_DEBUG	/* debugging sent to stdout */
+#undef MTA_DEBUG
+
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+extern int errno;		/* just in case */
+#include "mail.h"
+#include "osdep.h"
+#include <pwd.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <utime.h>
+#include <string.h>
+#include "maildir.h"
+#include "misc.h"
+#include "dummy.h"
+
+/* Driver dispatch used by MAIL */
+
+DRIVER maildirdriver = {
+  "maildir",			/* driver name */
+				/* driver flags */
+  DR_MAIL|DR_LOCAL|DR_NOFAST|DR_NAMESPACE,
+  (DRIVER *) NIL,		/* next driver */
+  maildir_valid,			/* mailbox is valid for us */
+  maildir_parameters,		/* manipulate parameters */
+  NIL,			/* scan mailboxes */
+  maildir_list,			/* find mailboxes */
+  maildir_lsub,			/* find subscribed mailboxes */
+  maildir_sub,			/* subscribe to mailbox */
+  maildir_unsub,		/* unsubscribe from mailbox */
+  maildir_create,			/* create mailbox */
+  maildir_delete,			/* delete mailbox */
+  maildir_rename,			/* rename mailbox */
+  mail_status_default,		/* status of mailbox */
+  maildir_open,			/* open mailbox */
+  maildir_close,		/* close mailbox */
+  maildir_fast,			/* fetch message "fast" attributes */
+  NIL,				/* fetch message flags */
+  NIL,				/* fetch overview */
+  NIL,				/* fetch message envelopes */
+  maildir_fetchheader,		/* fetch message header */
+  maildir_fetchtext,		/* fetch message body */
+  NIL,				/* fetch partial message text */
+  NIL,				/* unique identifier */
+  NIL,				/* message number */
+  NIL,				/* modify flags */
+  maildir_flagmsg,		/* per-message modify flags */
+  NIL,				/* search for message based on criteria */
+  NIL,				/* sort messages */
+  NIL,				/* thread messages */
+  maildir_ping,			/* ping mailbox to see if still alive */
+  maildir_check,		/* check for new messages */
+  maildir_expunge,			/* expunge deleted messages */
+  maildir_copy,			/* copy messages to another mailbox */
+  maildir_append,			/* append string message to mailbox */
+  maildir_gc				/* garbage collect stream */
+};
+
+				/* prototype stream */
+MAILSTREAM maildirproto = {&maildirdriver};
+
+/* Check validity of mailbox
+ */
+ 
+DRIVER *maildir_valid (char *name)
+{
+  char tmp[MAILTMPLEN];
+  return maildir_isvalid(name,tmp,T) ? &maildirdriver : NIL;
+}
+
+int maildir_isvalid (char *name,char *tmp,long justname)
+{
+  struct stat sbuf;
+  
+  if (!name || (!*name) || 
+      ((*name == '#') && 
+       (*(name+1) == 0 ||
+	(*(name+1) != 'm' && *(name+1) != 'M') ||
+	(*(name+2) != 'd' && *(name+2) != 'D') ||
+	*(name+3) != '/')) || (*name == '.'))
+    return NIL;
+  
+  /* okay, anything containing the name Maildir will be ignored
+     this is to prevent anyone from fiddling with their incoming Maildir
+     directly, it should be accessed via the INBOX alias */
+
+  #ifdef NO_MAILDIR_FIDDLE
+  if (strstr(name, "Maildir")) {
+	return NIL; 
+	}
+  #endif
+ 				/* If we are requested only to check 
+  				   if the name is appropriate then we
+  				   have done! */
+  if (justname && *name == '#') return T;
+  
+
+				/* must be valid local mailbox */
+  if ((*name != '*') && (*name != '{') &&
+      maildir_file (tmp,name) &&
+				/* assume its maildir if its a dir */
+      stat (tmp,&sbuf) == 0 && S_ISDIR (sbuf.st_mode))
+    return T;
+
+				/* INBOX is for default Maildir */
+  if (!strcmp (ucase (strcpy (tmp,name)), "INBOX") &&
+      (stat (maildir_file (tmp,name),&sbuf) == 0) &&
+      S_ISDIR (sbuf.st_mode))
+    return T;
+
+  return NIL;
+}
+
+/* Maildir mail generate file string
+ */
+
+char *maildir_file (char *dst,char *name)
+{
+  char tmp[MAILTMPLEN];
+  
+  if (strlen (name) > 3 &&	/* safe do other comparisons */
+      (*name == '#') &&
+      (name[1] == 'm' || name[1] == 'M') &&
+      (name[2] == 'd' || name[2] == 'D') &&
+      (name[3] == '/'))
+    name += 4;
+
+#ifdef NO_ABSOLUTE_PATHS  
+  if (*name == '/') {	
+  /* we do not want to accept / absolute paths, so lets strip the first
+     / ... */
+    sprintf(dst,"%s/%s/cur", myhomedir(), name+1);
+
+/*    strncpy (dst, name, MAILTMPLEN - 2);
+    strncat (dst, "/cur", MAILTMPLEN - 2);
+    dst[MAILTMPLEN - 1] = '\0'; */
+  }
+  else
+    sprintf (dst,"%s/%s/cur",myhomedir (),
+	    strcmp (ucase (strcpy (tmp, name)), "INBOX") ? name : MAILDIRPATH);
+#else
+  if (*name == '/') {	
+    strncpy (dst, name, MAILTMPLEN - 2);
+    strncat (dst, "/cur", MAILTMPLEN - 2);
+    dst[MAILTMPLEN - 1] = '\0';
+  }
+  else
+    sprintf (dst,"%s/%s/cur",myhomedir (),
+	    strcmp (ucase (strcpy (tmp, name)), "INBOX") ? name : MAILDIRPATH);
+
+#endif 
+  
+  #ifdef MTA_DEBUG
+  printf("maildir_file '%s'\n", dst);
+  #endif
+  return dst;
+}
+
+/* Maildir open
+ */
+ 
+MAILSTREAM *maildir_open (MAILSTREAM *stream)
+{
+ char tmp[MAILTMPLEN],tmp2[MAILTMPLEN];
+
+ if (!stream) return &maildirproto;
+ if (LOCAL) {		/* recycle stream */
+	maildir_close (stream, 0);
+	stream->dtb = &maildirdriver;
+	mail_free_cache (stream);
+	stream->uid_last = 0;       /* default UID validity */
+	stream->uid_validity = time (0);
+	}
+
+	stream->uid_validity = 0; /* was time(0) */
+
+  if (stream->uid_last < time(0))
+  	stream->uid_last = time (0);  
+  
+    stream->local = fs_get (sizeof (MAILDIRLOCAL));
+  LOCAL->inbox = !strcmp (ucase (strcpy (tmp,stream->mailbox)),"INBOX") ||
+      !strcmp (stream->mailbox,maildir_file (tmp2,"INBOX"));
+  LOCAL->dir = cpystr (maildir_file (tmp,stream->mailbox)); /* copy dir name */
+                                /* make temporary buffer */
+  LOCAL->buf = (char *) fs_get ((LOCAL->buflen = MAXMESSAGESIZE) + 1);
+  LOCAL->scantime = 0;          /* not scanned yet */
+  stream->sequence++;
+  stream->nmsgs = stream->recent = 0;
+
+  if (!maildir_ping (stream)) return NIL;
+  return stream;		/* return stream to caller */
+}
+
+/* Maildir ping mailbox
+ */
+
+long maildir_ping_core (MAILSTREAM *stream)
+{
+  char tmp[MAILTMPLEN];
+  MESSAGECACHE *elt;
+  struct stat sbuf, sbuf2;
+  DIR *dir;
+  struct direct *d;
+  int reloadall = NIL;
+  int uidinvalid = NIL;
+  unsigned long old;
+  long i;
+  long nmsgs = stream->nmsgs;
+  long recent = stream->recent;
+  long nfiles = stream->nmsgs;
+  int silent = stream->silent;
+  char *s, *s2;
+  mailcache_t mc = (mailcache_t) mail_parameters (NIL,GET_CACHE,NIL);
+
+/*  maildir_copynew (LOCAL->dir);
+ */
+  
+  if (stat (LOCAL->dir,&sbuf) < 0) {
+    /* sprintf (tmp,"Unable to open maildir %.80s: %s",stream->mailbox,strerror (errno));
+    mm_log (tmp,ERROR); */
+    return NIL;
+  }
+
+  /* okay, lets try to figure out the Maildir UID validity. This is done
+     by checking the last modification time of the file .uidvalidity
+     in the rootdir of the Maildir. Any program reordering the files
+     in the directory have to touch this file */
+
+  sprintf(tmp, "%s/../.uidvalidity", LOCAL->dir);
+  
+  if (stat (tmp,&sbuf2) < 0) {
+	/* no uid validity file found, if uid_validity == 0, we have
+	   to set it to something other than 0, and then create the
+	   .uidvalidity file for future accesses */
+
+	if (stream->uid_validity == 0) {
+		FILE *fl;
+		struct utimbuf tbuf;
+		
+		stream->uid_validity = time(0);
+		tbuf.actime = stream->uid_validity;
+		tbuf.modtime = stream->uid_validity;
+
+		if ((fl = fopen(tmp, "w"))) {
+			fclose(fl);
+			chmod (tmp, S_IRUSR|S_IWUSR);
+			utime(tmp, &tbuf);
+			}
+		}
+		uidinvalid = T; /* UID's are invalid, update them */
+	} else {
+	/* valid file, lets set UID if uid_validity = 0 */
+	if (stream->uid_validity == 0) {
+	stream->uid_validity = sbuf2.st_mtime;
+		}
+	}
+
+  #ifdef NO_UID_VALIDITY
+  uidinvalid = T; /* force the UIDs to be invalid and reset every time,
+  		     useful in an environment without imap servers and
+  		     clients that screw up the UIDs.. i'd leave it to
+  		     OFF until I really need it though... */
+  #endif
+
+  stream->silent = T;  
+  if (sbuf.st_ctime != LOCAL->scantime) {
+    /* update the message list */
+    struct direct **names = NIL;
+    nfiles = scandir (LOCAL->dir,&names,maildir_select,maildir_namesort);
+
+    for (i = 0; i < nfiles; i++) {
+
+	/* check if file has executable bit set */
+	sprintf(tmp, "%s/%s", LOCAL->dir, names[i]->d_name);
+  	stat (tmp,&sbuf2);
+	if (sbuf2.st_mode & S_IXUSR) {
+		/* executable bit set, modtime is uid */
+		if (sbuf2.st_mtime > stream->uid_last)
+			stream->uid_last = sbuf2.st_mtime+1;
+		}
+	/* this is kept for backwards compatibility */
+        if ((s = strstr (names[i]->d_name,":3,")))
+		s += 3;
+        if (s && (s2 = strstr (s, ",U"))) {
+      		s2 += 2;
+		sscanf(s2, "%d", &old);
+		if (old > stream->uid_last) {
+			stream->uid_last = old+1;
+			}
+		}	
+	
+    }
+
+    mm_critical (stream);	/* go critical */
+    old = stream->uid_last;
+    LOCAL->scantime = sbuf.st_ctime;
+
+				/* check if old files same */
+    for (i = 0; i < stream->nmsgs; i++) {
+
+      if (strcmp ((char *) mail_elt (stream, i + 1)->maildirp,
+		  names[i]->d_name)) {
+	reloadall = T;
+	break;
+      }
+    }
+
+    if (reloadall) { /* files are out of order, rebuild cache */
+
+      i = 1;
+      while (i <= stream->nmsgs)
+				/* clean out cache */
+	if ((elt = (MESSAGECACHE *) (*mc) (stream,i,CH_ELT))) {
+	  fs_give ((void **) &elt->maildirp);
+	  mail_expunged (stream,i);
+	}
+	else
+	  i++;
+      
+      mm_log ("Warning: Mailbox has changed in an unexpected way.  Reloading.",
+	      WARN);
+      stream->nmsgs = 0;
+    }
+    nmsgs = stream->nmsgs;
+    
+    stream->nmsgs = nfiles; /* hm? */    
+
+    for (i = nmsgs; i < nfiles; i++) {
+
+      mail_exists(stream, i+1);
+				/* if newly seen, add to list */
+      (elt = mail_elt (stream, i + 1))->maildirp = (long) cpystr (names[i]->d_name);
+       elt->valid = T;
+
+      /* grab the flags */
+      if ((s = strstr (names[i]->d_name,":3,"))) {
+	s += 3;
+	if (strchr (s,'F'))
+	  elt->flagged = T;
+	if (strchr (s,'R'))
+	  elt->answered = T;
+	if (strchr (s,'S'))
+	  elt->seen = T;
+	if (strchr (s,'T'))
+	  elt->deleted = T;
+      } else if ((s = strstr (names[i]->d_name,":2,"))) {
+	/* this is the :2, id where all files go nowadays */
+	s += 3;
+	if (strchr (s,'F'))
+	  elt->flagged = T;
+	if (strchr (s,'R'))
+	  elt->answered = T;
+	if (strchr (s,'S'))
+	  elt->seen = T;
+	if (strchr (s,'T'))
+	  elt->deleted = T;
+	sprintf(tmp, "%s/%s", LOCAL->dir, names[i]->d_name);
+  	stat (tmp,&sbuf2);
+	if (sbuf2.st_mode & S_IXUSR) {
+		/* executable bit set, modtime is uid */
+		elt->private.uid = sbuf2.st_mtime;
+		}
+	/* and if we could not retrieve UID from modtime, or if
+	   UIDs are invalid, go here */
+	if (elt->private.uid == 0 || uidinvalid) {
+        	stream->uid_last = (elt = mail_elt (stream,i+1))->private.uid = stream->uid_last+1;
+		maildir_flagmsg(stream, elt);
+		}	
+	s = 0; /* make sure next if statement does not trigger */      
+      	}
+
+      if (s)
+      if ((s2 = strstr (s, ",U"))) {
+      	s2 += 2;
+	sscanf(s2, "%d", &elt->private.uid);
+	if (elt->private.uid == 0 || uidinvalid) {
+        	stream->uid_last = (elt = mail_elt (stream,i+1))->private.uid = stream->uid_last+1;
+		maildir_flagmsg(stream, elt);
+		}	
+	
+      	} else { /* assign new UID */
+        stream->uid_last = (elt = mail_elt (stream,i+1))->private.uid = stream->uid_last+1;
+	elt->recent = T;
+	recent++;
+	maildir_flagmsg(stream, elt); /* store the UID that we assigned to it */
+	}	
+
+
+
+    }
+
+    mm_nocritical (stream);	/* release critical */
+				/* free the names stuff */
+    for (i = 0; i < nfiles; i++)
+      fs_give ((void **) &names[i]);
+    if (names)
+      fs_give ((void **) &names);
+  }
+  stream->silent = silent;
+  mail_exists(stream,nfiles);
+/*  if (!reloadall)  */
+  	mail_recent (stream,recent);
+
+  return T;			/* return that we are alive */
+}
+
+long maildir_ping (MAILSTREAM *stream)
+{
+  maildir_copynew (LOCAL->dir);
+  return maildir_ping_core (stream);
+}
+
+void maildir_copynew (const char *mailbox)
+{
+  char tmp[MAILTMPLEN],file[MAILTMPLEN],newfile[MAILTMPLEN];
+  DIR *dir;
+  struct dirent *d;
+  struct stat sbuf;
+  
+  sprintf (tmp,"%s/../new",mailbox);
+  if (!(dir = opendir (tmp)))
+    return;
+
+  while (d = readdir (dir)) {
+    if (d->d_name[0] == '.')
+      continue;			/* skip .files */
+
+    sprintf (file,"%s/%s",tmp,d->d_name);
+				/* make sure this is a normal file */
+    if (stat (file,&sbuf) == 0 && S_ISREG (sbuf.st_mode)) {
+      
+      if (strstr (d->d_name,":3,")) /* this message already has flags */
+	sprintf (newfile,"%s/%s",mailbox,d->d_name);
+      else
+	sprintf (newfile,"%s/%s:3,",mailbox,d->d_name);
+      
+				/* move the new mail to the cur dir */
+      if (link (file,newfile) == -1)
+	mm_log("Unable to read new mail!",WARN);
+      else
+	unlink (file);	
+    }
+  }
+  closedir (dir);
+}
+
+int maildir_select (struct direct *name)
+{
+  if (name->d_name[0] != '.')
+    return T;
+
+  return NIL;
+}
+
+int maildir_namesort (struct direct **d1,struct direct **d2)
+{
+  unsigned long t1, t2;
+
+  /* If we can't sort on uid, sort on filename. However take
+      into account that the first part is decimal, and that it
+      will wrap from 9 to 10 digits on Sep 9, 2001. That means
+      we should compare the numbers and not use strcmp()  */
+  t1 = strtoul((*d1)->d_name, NULL, 10);
+  t2 = strtoul((*d2)->d_name, NULL, 10);
+  if (t1 > 0 && t2 > 0 && t1 != t2) return t1 - t2;
+
+  return strcmp ((*d1)->d_name,(*d2)->d_name);
+}
+
+
+/* Maildir garbage collect stream
+ */
+
+void maildir_gc (MAILSTREAM *stream,long gcflags)
+{
+  unsigned long i;
+  
+  if (gcflags & GC_TEXTS) {	/* garbage collect texts? */
+				/* flush texts from cache */
+/*    if (LOCAL->hdr) fs_give ((void **) &LOCAL->hdr);
+//    if (stream->text) fs_give ((void **) &stream->text);
+//    stream->msgno = 0;		invalidate stream text
+*/
+  }
+}
+
+/* Maildir close
+ */
+
+void maildir_close (MAILSTREAM *stream, long options)
+{
+  MESSAGECACHE *elt;
+  int i;
+  mailcache_t mc = (mailcache_t) mail_parameters (NIL,GET_CACHE,NIL);
+ 
+/*  CL_EXPUNGE OPTION SUPPORT HERE SOMEWHERE! */
+				/* clean out the cached paths */
+  for (i = 1; i <= stream->nmsgs; i++)
+    if ((elt = (MESSAGECACHE *) (*mc) (stream,i,CH_ELT)) && elt->maildirp) {
+      fs_give ((void **) &elt->maildirp);
+      elt->maildirp = 0; /* otherwise pine coredumps */  
+	}  
+  
+  if (LOCAL) {			/* only if a stream is open */
+    if (LOCAL->dir) fs_give ((void **) &LOCAL->dir);
+    maildir_gc (stream,GC_TEXTS); /* free local cache */
+				/* free local scratch buffer */
+    if (LOCAL->buf) fs_give ((void **) &LOCAL->buf);
+				/* nuke the local data */
+    fs_give ((void **) &stream->local);
+    stream->dtb = NIL;		/* log out the DTB */
+  }
+}
+
+void maildir_check (MAILSTREAM *stream)
+{
+  /* Perhaps in the future this will preserve flags */
+  if (maildir_ping (stream)) mm_log ("Check completed",(long) NIL);   
+}
+
+long maildir_fetchtext (MAILSTREAM *stream,unsigned long msgno,STRING *bs, long flags)
+{
+  unsigned long i;
+  MESSAGECACHE *elt;
+                                /* UID call "impossible" */
+  if (flags & FT_UID) return NIL;
+  elt = mail_elt (stream,msgno);/* get elt */
+                                /* snarf message if don't have it yet */
+  if (!elt->private.msg.text.text.data) {
+    maildir_fetchheader (stream,msgno,&i,flags);
+    if (!elt->private.msg.text.text.data) return NIL;
+  }
+  if (!(flags & FT_PEEK)) {     /* mark as seen */
+    mail_elt (stream,msgno)->seen = T;
+    maildir_flagmsg (stream, mail_elt(stream,msgno));
+    mm_flags (stream,msgno);
+  }
+  if (!elt->private.msg.text.text.data) return NIL;
+  INIT (bs,mail_string,elt->private.msg.text.text.data,
+        elt->private.msg.text.text.size);
+  return T;
+}
+
+
+/* Maildir fetch message header
+ */
+
+char *maildir_fetchheader (MAILSTREAM *stream,unsigned long msgno,
+		unsigned long *length, long flags)
+{
+  unsigned long i,hdrsize;
+  int fd;
+  char *t;
+  char tmp[MAILTMPLEN];
+  char *s,*b;
+  struct stat sbuf;
+  struct tm *tm;
+  MESSAGECACHE *elt;
+  *length = 0;                  /* default to empty */
+  if (flags & FT_UID) return "";/* UID call "impossible" */
+  elt = mail_elt (stream,msgno);/* get elt */
+  if (!elt->private.msg.header.text.data) {
+
+/*    maildir_gc (stream,GC_TEXTS);  invalidate current cache */
+				/* build message file name */
+    sprintf (tmp,"%s/%s",LOCAL->dir,(char *) elt->maildirp);
+    if ((fd = open (tmp,O_RDONLY,NIL)) >= 0) {
+      fstat (fd,&sbuf);		/* get size of message */
+				/* make plausible IMAPish date string */
+      tm = gmtime (&sbuf.st_mtime);
+      elt->day = tm->tm_mday; elt->month = tm->tm_mon + 1;
+      elt->year = tm->tm_year + 1900 - BASEYEAR;
+      elt->hours = tm->tm_hour; elt->minutes = tm->tm_min;
+      elt->seconds = tm->tm_sec;
+      elt->zhours = 0; elt->zminutes = 0;
+				/* slurp message */
+      read (fd,s = (char *) fs_get (sbuf.st_size + 1),sbuf.st_size);
+      s[sbuf.st_size] = '\0';	/* tie off file */
+      close (fd);		/* close file */
+
+      for (i = 0,b = s; *b && !(i && (*b == '\n')); i = (*b++ == '\n'));
+      hdrsize = (*b ? ++b:b)-s;	/* number of header bytes */
+
+      elt->rfc822_size =          /* size of entire message in CRLF form */
+       (elt->private.msg.header.text.size =
+        strcrlfcpy ((char **) &elt->private.msg.header.text.data,&i,s,
+                    hdrsize)) +
+          (elt->private.msg.text.text.size =
+           strcrlfcpy ((char **) &elt->private.msg.text.text.data,&i,b,
+                       sbuf.st_size - hdrsize));
+      fs_give ((void **) &s);
+    } else return "";
+
+  }
+
+  *length = elt->private.msg.header.text.size;
+  return (char *) elt->private.msg.header.text.data;
+}
+
+void maildir_fast (MAILSTREAM *stream,char *sequence,long flags)
+{
+  unsigned long i,j;
+				/* ugly and slow */
+  if (stream && LOCAL && ((flags & FT_UID) ?
+			  mail_uid_sequence (stream,sequence) :
+			  mail_sequence (stream,sequence)))
+    for (i = 1; i <= stream->nmsgs; i++)
+      if (mail_elt (stream,i)->sequence) maildir_fetchheader (stream,i,&j,NIL);
+}
+
+/* Maildir find list of subscribed mailboxes
+ * Accepts: mail stream
+ *	    pattern to search
+ */
+
+void maildir_list (MAILSTREAM *stream,char *ref, char *pat)
+{
+  DIR *dp;
+  struct direct *d;
+  struct stat sbuf;
+  char *s,*s2,*cp,*np,curdir[MAILTMPLEN],name[MAILTMPLEN],subdir[MAILTMPLEN],rname[MAILTMPLEN];
+
+  if (!ref) {
+    /*syslog(LOG_INFO, "maildir_list: ref=NIL");*/
+    ref = pat;
+  }
+
+  if (ref) {
+    if (!strncmp(ref,"#md/",4)) {
+	ref = ref+4;
+    }
+
+    strcpy(subdir, ref);
+  }
+
+  s = subdir;
+  s2 = 0;
+  while ((s = strstr(s, "/"))) {
+  	s2 = s;
+	s++;
+	}
+
+  if (s2) { /* pointer to last / */
+  	*s2 = '\0'; /* snip off string */
+	s2++;
+	/*syslog(LOG_INFO, "dir: '%s' pat: '%s'", subdir, s2);*/
+  	sprintf(name, "%s/%s", myhomedir(), subdir);
+	} else {
+	s2 = pat;
+	sprintf(name, "%s", myhomedir());
+	strcpy(subdir, "");
+	}
+
+ maildir_listwork(name, stream, s2, subdir, 1);
+
+ if (pmatch ("INBOX", pat))
+ 	mm_list (stream,NIL,"INBOX",LATT_NOINFERIORS);
+
+}
+
+void maildir_listwork(char *name1, MAILSTREAM *stream, char *s2, char *subdir, int flag)
+{
+  DIR *dp;
+  struct direct *d;
+  struct stat sbuf;
+  char *s,*cp,*np,curdir[MAILTMPLEN],rname[MAILTMPLEN],name[MAILTMPLEN];
+  char tmpname[MAILTMPLEN];
+  char tmpdir[MAILTMPLEN];
+  
+  strcpy(name, name1);
+  
+  /*syslog(LOG_INFO, "opendir: '%s'", name);
+  //syslog(LOG_INFO, "subdir: '%s'", subdir);
+   */ 
+  if (dp = opendir (name)) {	/* open directory */
+    while (d = readdir (dp))	/* scan directory, ignore all . names */
+      if (d->d_name[0] != '.' || d->d_name[1] != 0) {
+	/* we do not want to list Maildir to customers, because
+	   that might give them weird ideas :) */
+
+	if (subdir[0] != '\0' && subdir[0] != '%' && subdir[0] != '*')
+		sprintf(name, "%s/%s", subdir, d->d_name);
+	else
+		sprintf(name, "%s", d->d_name);
+	/*syslog(LOG_INFO, "ls: '%s'", name);*/
+
+	/* this matching might not be correctly implemented	*/
+	if (maildir_file(curdir, name) &&
+      		stat (curdir,&sbuf) == 0 && S_ISDIR (sbuf.st_mode)) {
+		/*syslog(LOG_INFO, "here for some stange reason");*/
+		if (1 || pmatch(d->d_name, s2)) {
+			if (strchr(name,'.')) {
+				strcpy(tmpname,strchr(name,'.'));
+				strcpy(name,"#md/Maildir/");
+				strcat(name,tmpname);
+			}
+			mm_list (stream,NIL,name,1);
+
+
+			/* call function recursive if last char % */
+			/*syslog(LOG_INFO, "s2: '%s'",s2);*/
+			if (s2[strlen(s2)-1] == '%'
+			||  s2[strlen(s2)-1] == '*') {
+				sprintf(rname, "%s/%s", name1, name);
+				/*syslog(LOG_INFO, "rname: '%s'", rname);*/
+				maildir_listwork(rname, stream, "%", name, 1);
+				}			
+			}
+		} else
+	if (strlen(curdir) > 4 && pmatch(d->d_name, s2)) { 
+  		int fnlen = strlen (curdir);
+  		curdir[fnlen - 4] = '\0';
+  		/*syslog(LOG_INFO, "fname: '%s'", curdir);*/
+	if (stat (curdir,&sbuf) == 0 && S_ISDIR (sbuf.st_mode)) {
+		/* okay, do not list with NoSelect, since Netscape
+		   does not f*cking honor this flag.. stupid netscape */
+		/*mm_list (stream,'/',name,LATT_NOSELECT);*/
+
+			/* call function recursive if last char % */
+			/*syslog(LOG_INFO, "s2: '%s'",s2);*/
+			if (s2[strlen(s2)-1] == '%' 
+			||  s2[strlen(s2)-1] == '*') {
+				sprintf(rname, "%s/%s", name1, name);
+				/*syslog(LOG_INFO, "rname: '%s'", rname);*/
+				maildir_listwork(rname, stream, "%", name, 1);
+				}			
+
+		}
+	    }
+
+	}
+      closedir (dp);		/* all done, flush directory */
+      }
+
+}
+
+
+
+
+
+void *maildir_parameters (long function,void *value)
+{
+  return NIL;
+}
+
+long maildir_create (MAILSTREAM *stream,char *mailbox)
+{
+  char tmp[MAILTMPLEN];
+  char err[MAILTMPLEN];
+  char *s, *s2;
+  int fnlen, i;
+  char *subdir_names[] = {"/cur","/new","/tmp",NULL};
+
+				/* must not already exist */
+  if (access (maildir_file (tmp,mailbox),F_OK) == 0) {
+    sprintf (err,"Can't create mailbox %s: mailbox already exists",mailbox);
+    mm_log (err,ERROR);
+    return NIL;
+  }
+  
+  maildir_file (tmp,mailbox);	/* get file name */
+  fnlen = strlen (tmp);
+  /*syslog(LOG_INFO, "fname: '%s'", tmp);*/
+  tmp[fnlen - 4] = '\0';	/* making main directory's name */
+  fnlen -= 4;
+
+  /* okay, try to add support for adding hiearchys of directories, this
+     is done by scanning for /'s.... */
+     
+  /*syslog(LOG_INFO, "tmp '%s'", tmp);*/
+  s = tmp;
+
+  while ((s = strstr(s, "/")) != 0) {
+	/*syslog(LOG_INFO, "Before make: '%s'", s);*/
+  	*s = '\0';
+  	/*syslog(LOG_INFO, "Trying to make: '%s'", tmp);*/
+	if (mkdir (tmp,0700) && *s != '\0') /* trying to make the dir */
+	  if (errno != EEXIST) {
+	    sprintf (err,"Can't create mailbox %s: %s %s",
+		     mailbox,tmp,strerror (errno));
+    	     mm_log (err,ERROR);
+             return NIL;
+	  }
+  	*s = '/';
+	s++;
+  	} 
+
+  if (mkdir (tmp,0700)) {	/* try to make new dir */
+    sprintf (err,"Can't create mailbox %s: %s %s",
+	     mailbox,tmp,strerror (errno));
+    mm_log (err,ERROR);
+    return NIL;
+  }
+
+  /*syslog(LOG_INFO, "create maildir");*/
+  for (i = 0; subdir_names[i]; i++) {
+    strcpy (tmp + fnlen,subdir_names[i]);
+
+    if (mkdir (tmp,0700)) {	/* try to make new dir */
+      sprintf (err,"Can't create mailbox %s: %s %s",
+	       mailbox,tmp,strerror (errno));
+      mm_log (err,ERROR);
+      return NIL;
+    }
+  }
+
+  return T;			/* return success */
+}
+
+void maildir_flagmsg (MAILSTREAM *stream,MESSAGECACHE *elt)
+{
+  char oldfile[MAILTMPLEN],newfile[MAILTMPLEN],fn[MAILTMPLEN];
+  struct utimbuf tbuf;
+  char *s;
+
+                                /* build the new filename */
+  sprintf (oldfile,"%s/%s",LOCAL->dir,(char *) elt->maildirp);
+  if ((s = strchr ((char *) elt->maildirp,':'))) *s = '\0';
+  sprintf (fn,"%s:2,%s%s%s%s",(char *) elt->maildirp,elt->flagged ? "F" : "",
+           elt->answered ? "R" : "",elt->seen ? "S" : "",
+           elt->deleted ? "T" : "");
+  sprintf (newfile,"%s/%s",LOCAL->dir,fn);
+                                /* rename the file with new flags */
+  if (rename (oldfile,newfile) < 0) {
+    sprintf(oldfile,"Unable to write flags to disk: %s",strerror (errno));
+    mm_log(oldfile,ERROR);
+    return;
+  }
+                                /* update the file name in cache */
+  fs_give ((void **) &elt->maildirp);
+  elt->maildirp = (long) cpystr (fn);
+
+  /* fix the UID on the file */
+  tbuf.actime = elt->private.uid;
+  tbuf.modtime = elt->private.uid;
+  chmod (newfile, S_IRUSR|S_IWUSR|S_IXUSR);
+  utime (newfile, &tbuf);
+
+}
+
+void maildir_expunge (MAILSTREAM *stream)
+{
+  MESSAGECACHE *elt;
+  unsigned long i = 1;
+  unsigned long n = 0;
+  unsigned long recent = stream->recent;
+  
+  maildir_gc (stream,GC_TEXTS);	/* invalidate texts */
+  mm_critical (stream);		/* go critical */
+  while (i <= stream->nmsgs) {	/* for each message */
+				/* if deleted, need to trash it */
+    if ((elt = mail_elt (stream,i))->deleted) {
+      sprintf (LOCAL->buf,"%s/%s",LOCAL->dir,(char *) elt->maildirp);
+      if (unlink (LOCAL->buf)) {/* try to delete the message */
+	sprintf (LOCAL->buf,"Expunge of message %ld failed, aborted: %s",i,
+		 strerror (errno));
+	mm_log (LOCAL->buf,WARN);
+	break;
+      }
+				/* free the cached filename */
+      if (elt->maildirp) {
+	      fs_give ((void **) &elt->maildirp);
+	      elt->maildirp = 0; /* otherwise pine coredumps */
+		}
+      if (elt->recent) --recent;/* if recent, note one less recent message */
+      mail_expunged (stream,i);	/* notify upper levels */
+      n++;			/* count up one more expunged message */
+    }
+    else i++;			/* otherwise try next message */
+  }
+  if (n) {			/* output the news if any expunged */
+    sprintf (LOCAL->buf,"Expunged %ld messages",n);
+    mm_log (LOCAL->buf,(long) NIL);
+  }
+  else mm_log ("No messages deleted, so no update needed",(long) NIL);
+  mm_nocritical (stream);	/* release critical */
+				/* notify upper level of new mailbox size */
+  mail_exists (stream,stream->nmsgs);
+  mail_recent (stream,recent);
+}
+
+/* dont forget to process options in here */
+long maildir_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options)
+{
+  STRING st;
+  MESSAGECACHE *elt;
+  struct stat sbuf;
+  int fd;
+  long i;
+  char *s,tmp[MAILTMPLEN];
+  char flags[MAILTMPLEN],date[MAILTMPLEN];
+				/* copy the messages */
+  if ((options & CP_UID) ? mail_uid_sequence (stream, sequence) : 
+  	mail_sequence (stream,sequence)) 
+  for (i = 1; i <= stream->nmsgs; i++)
+    if ((elt = mail_elt (stream,i))->sequence) {
+      sprintf (LOCAL->buf,"%s/%s",LOCAL->dir,(char *) elt->maildirp);
+      if ((fd = open (LOCAL->buf,O_RDONLY,NIL)) < 0) return NIL;
+      fstat (fd,&sbuf);		/* get size of message */
+				/* slurp message */
+      read (fd,s = (char *) fs_get (sbuf.st_size +1),sbuf.st_size);
+      s[sbuf.st_size] = '\0';	/* tie off file */
+      close (fd);		/* flush message file */
+      INIT (&st,mail_string,(void *) s,sbuf.st_size);
+	flags[0] = flags[1] = '\0';
+	if (elt->seen) strcat (flags," \\Seen");
+	if (elt->deleted) strcat (flags," \\Deleted");
+	if (elt->flagged) strcat (flags," \\Flagged");
+	if (elt->answered) strcat (flags," \\Answered");
+	if (elt->draft) strcat (flags," \\Draft");
+	flags[0] = '(';		/* open list */
+	strcat (flags,")");	/* close list */
+	mail_date (date,elt);	/* generate internal date */
+	if (!mail_append_full (NIL,mailbox,flags,date,&st)) return NIL;
+	if (options & CP_MOVE) elt->deleted = T;
+      fs_give ((void **) &s);	/* give back temporary space */
+    }
+  return T;			/* return success */
+}
+
+long maildir_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data)
+{
+  int fd;
+  char c,*s,*date,*flags;
+  char tmp[MAILTMPLEN],file[MAILTMPLEN],path1[MAILTMPLEN],path2[MAILTMPLEN];
+  MESSAGECACHE elt;
+  unsigned long i, uf;
+  long size = 0;
+  long ret = LONGT;
+  STRING *message;
+  
+  /*  
+     This is intentionaly made static.  Users can ask to save a LOT of messages
+     at once and this program can do that within one second. Dan's assumption
+     that time+pid+hostname always will be unique stops being true in this
+     case. So we will add yet another number to host part of message file's
+     name. Hostname is used only to make filename unique and Dan  explicitly
+     says that "<...>  Other than this [skipping filenames starting at dot] ,
+     readers should not attempt to parse filenames. <...>". Therefore this 
+     addition should be no problem. Am I right, Dan?   --AK
+  */ 
+  
+  static unsigned int transact = 0;
+
+/*  if (date) {			want to preserve date?
+    //syslog(LOG_INFO, "date: '%s'", date);
+				// yes, parse date into an elt
+    if (!mail_parse_date (&elt,date)) {
+      sprintf (tmp,"Bad date in append: %s",date);
+      mm_log (tmp,ERROR);
+      return NIL;
+    }
+  } */
+				/* N.B.: can't use LOCAL->buf for tmp */
+				/* make sure valid mailbox */
+  if (!maildir_isvalid (mailbox, tmp, NIL)) switch (errno) {
+  case ENOENT:			/* no such file? */
+    if ((mailbox[0] == '#') && ((mailbox[1] == 'M') || (mailbox[1] == 'm')) &&
+	((mailbox[2] == 'D') || (mailbox[2] == 'd')) &&
+	((mailbox[4] == 'I') || (mailbox[4] == 'i')) &&
+	((mailbox[5] == 'N') || (mailbox[5] == 'n')) &&
+	((mailbox[6] == 'B') || (mailbox[6] == 'b')) &&
+	((mailbox[7] == 'O') || (mailbox[7] == 'o')) &&
+	((mailbox[8] == 'X') || (mailbox[8] == 'x')) && !mailbox[8])
+      mh_create (NIL,"INBOX");
+    else {
+      mm_notify (stream,"[TRYCREATE] Must create mailbox before append",NIL);
+      return NIL;
+    }
+				/* falls through */
+  case 0:			/* merely empty file? */
+    break;
+  case EINVAL:
+    sprintf (tmp,"Invalid Maildir mailbox name: %.80s",mailbox);
+    mm_log (tmp,ERROR);
+    return NIL;
+  default:
+    sprintf (tmp,"Not a Maildir mailbox: %.80s",mailbox);
+    mm_log (tmp,ERROR);
+    return NIL;
+  }
+				/* get first message */
+  if (!(*af) (stream,data,&flags,&date,&message)) return NIL;
+
+  if (flags) 			/* get flags if given */
+    uf = maildir_getflags (user_flags (&maildirproto),flags);
+
+				/* build file name we will use */
+  sprintf (file,"%u.%d.%09u.%s:3,%s%s%s%s",
+	   time (0),getpid (),transact++,mylocalhost (),
+	   uf&fFLAGGED ? "F" : "",uf&fANSWERED ? "R" : "",
+	   uf&fSEEN ? "S" : "",uf&fDELETED ? "T" : "");
+				/* build tmp file name */
+  sprintf (path1,"%s/../tmp/%s",maildir_file (tmp,mailbox),file);
+  
+  if ((fd = open (path1,O_WRONLY|O_CREAT|O_EXCL,S_IREAD|S_IWRITE)) < 0) {
+    sprintf (tmp,"Can't open append mailbox: %s",strerror (errno));
+    mm_log (tmp,ERROR);
+    return NIL;
+  }
+  i = SIZE (message);		/* get size of message */
+  s = (char *) fs_get (i + 1);	/* get space for the data */
+				/* copy the data w/o CR's */
+  while (i--) if ((c = SNX (message)) != '\015') s[size++] = c;
+  mm_critical (stream);		/* go critical */
+				/* write the data */
+  if ((write (fd,s,size) < 0) || fsync (fd)) {
+    unlink (path1);		/* delete message */
+    sprintf (tmp,"Message append failed: %s",strerror (errno));
+    mm_log (tmp,ERROR);
+    ret = NIL;
+  }
+				/* build final filename to use */
+  sprintf (path2,"%s/../new/%s",maildir_file (tmp,mailbox),file);
+  if (link (path1,path2) < 0) {
+    sprintf (tmp,"Message append failed: %s",strerror (errno));
+    mm_log (tmp,ERROR);
+    ret = NIL;
+  }
+  unlink (path1);
+  
+  close (fd);			/* close the file */
+  mm_nocritical (stream);	/* release critical */
+  fs_give ((void **) &s);	/* flush the buffer */
+  return ret;
+}
+
+short bezerk_getflags (MAILSTREAM *stream,char *flag)
+{
+  char *t,tmp[MAILTMPLEN],err[MAILTMPLEN];
+  short f = 0;
+  short i,j;
+  if (flag && *flag) {		/* no-op if no flag string */
+				/* check if a list and make sure valid */
+    if ((i = (*flag == '(')) ^ (flag[strlen (flag)-1] == ')')) {
+      mm_log ("Bad flag list",ERROR);
+      return NIL;
+    }
+				/* copy the flag string w/o list construct */
+    strncpy (tmp,flag+i,(j = strlen (flag) - (2*i)));
+    tmp[j] = '\0';
+    t = ucase (tmp);		/* uppercase only from now on */
+
+    while (t && *t) {		/* parse the flags */
+      if (*t == '\\') {		/* system flag? */
+	switch (*++t) {		/* dispatch based on first character */
+	case 'S':		/* possible \Seen flag */
+	  if (t[1] == 'E' && t[2] == 'E' && t[3] == 'N') i = fSEEN;
+	  t += 4;		/* skip past flag name */
+	  break;
+	case 'D':		/* possible \Deleted flag */
+	  if (t[1] == 'E' && t[2] == 'L' && t[3] == 'E' && t[4] == 'T' &&
+	      t[5] == 'E' && t[6] == 'D') i = fDELETED;
+	  t += 7;		/* skip past flag name */
+	  break;
+	case 'F':		/* possible \Flagged flag */
+	  if (t[1] == 'L' && t[2] == 'A' && t[3] == 'G' && t[4] == 'G' &&
+	      t[5] == 'E' && t[6] == 'D') i = fFLAGGED;
+	  t += 7;		/* skip past flag name */
+	  break;
+	case 'A':		/* possible \Answered flag */
+	  if (t[1] == 'N' && t[2] == 'S' && t[3] == 'W' && t[4] == 'E' &&
+	      t[5] == 'R' && t[6] == 'E' && t[7] == 'D') i = fANSWERED;
+	  t += 8;		/* skip past flag name */
+	  break;
+	default:		/* unknown */
+	  i = 0;
+	  break;
+	}
+				/* add flag to flags list */
+	if (i && ((*t == '\0') || (*t++ == ' '))) f |= i;
+      }
+      else {			/* no user flags yet */
+	t = strtok (t," ");	/* isolate flag name */
+	sprintf (err,"Unknown flag: %.80s",t);
+	t = strtok (NIL," ");	/* get next flag */
+	mm_log (err,ERROR);
+      }
+    }
+  }
+  return f;
+}
+
+short maildir_getflags (MAILSTREAM *stream,char *flag)
+{
+  return bezerk_getflags (stream,flag); /* nothing exciting, reuse old code */
+}
+
+long maildir_delete (MAILSTREAM *stream,char *mailbox)
+{
+  DIR *dirp;
+  struct direct *d;
+  int i,j;
+  char tmp[MAILTMPLEN],err[MAILTMPLEN];
+  char *subdir_names[] = {"cur/","new/","tmp/",NULL};
+
+				/* check if mailbox even exists */
+  if (!maildir_isvalid (mailbox,tmp,NIL)) {
+/*    sprintf (tmp,"Can't delete mailbox %s: no such mailbox",mailbox);
+    mm_log (tmp,ERROR);
+    return NIL; */
+    /*syslog(LOG_INFO, "Invalid maildir in delete()"); */
+    return T; /* well.. a stupid hack to get by a problem in netscape ..
+    		it remembers folders locally, and if a folder is deleted on
+    		another machine, you have no way removing it on any other
+    		netscapes... */
+  }
+
+				/* get name of directory */
+  i = strlen (maildir_file (tmp,mailbox)) + 1;
+  for (j = 0; subdir_names[j]; j++) {
+    strcpy (tmp + i - 4,subdir_names[j]);
+    if (dirp = opendir (tmp)) {	/* open directory */
+      while (d = readdir (dirp))	/* empty the directory */
+	if (strcmp (d->d_name,".") && strcmp (d->d_name,"..")) {
+	  strcpy (tmp + i,d->d_name);
+	  /*syslog(LOG_INFO, "unlink1: '%s'");*/
+	  unlink (tmp);
+	}
+      closedir (dirp);		/* flush directory */
+    }
+				/* remove the subdir */
+    tmp[i + 3] = '\0';
+    /*syslog(LOG_INFO, "tmp: '%s'", tmp);*/
+    if (rmdir (tmp)) {
+    /*  sprintf (err,"Can't delete directory %s: %s",tmp,strerror (errno));
+      mm_log (err,ERROR);*/
+    }
+  }
+
+  /* remove the .uidvalidity file */
+  strcpy(tmp + i - 4, ".uidvalidity");
+  unlink(tmp);
+
+				/* try to remove the directory */
+  *(tmp + i - 5) = '\0';
+  /*syslog(LOG_INFO, "tmp2: '%s'", tmp);*/
+  if (rmdir (tmp)) {
+/*    sprintf (err,"Can't delete mailbox %s: %s",mailbox,strerror (errno));
+    mm_log (err,ERROR);
+    return NIL; */
+  }
+  return T;			/* return success */
+}
+
+long maildir_rename (MAILSTREAM *stream,char *old,char *new)
+{
+  char tmp[MAILTMPLEN],tmpnew[MAILTMPLEN];
+  int i;
+
+				/* old mailbox name must be valid */
+  if (!maildir_isvalid (old,tmp,NIL)) {
+    sprintf (tmp,"Can't rename mailbox %s: no such mailbox",old);
+    mm_log (tmp,ERROR);
+    return NIL;
+  }
+
+				/* new mailbox name must not exist */
+  if (access (maildir_file (tmp,new),F_OK) == 0) {
+    sprintf (tmp,"Can't rename to mailbox %s: destination already exists",new);
+    mm_log (tmp,ERROR);
+    return NIL;
+  }
+
+                /* get the filesnames to rename */
+  maildir_file (tmp,old);
+  i = strlen(tmp);
+  if ( i > 4 && tmp[i-4] == '/' && tmp[i-3] == 'c' && tmp[i-2] == 'u' && tmp[i-1] == 'r' )
+  	tmp[i-4] = 0;
+
+  maildir_file (tmpnew,new);
+  i = strlen(tmpnew);
+  if ( i > 4 && tmpnew[i-4] == '/' && tmpnew[i-3] == 'c' && tmpnew[i-2] == 'u' && tmpnew[i-1] == 'r' )
+  	tmpnew[i-4] = 0;
+
+				/* new filename must not exist */
+  if (access (tmpnew,F_OK) == 0) {
+    sprintf (tmp,"Can't rename to mailbox %s: destination already exists as a non-mailbox",new);
+    mm_log (tmp,ERROR);
+    return NIL;
+  }
+
+				/* try to rename the directory */
+  if (rename (tmp,tmpnew)) {
+    sprintf (tmp,"Can't rename mailbox %s to %s: %s",old,new,strerror (errno));
+    mm_log (tmp,ERROR);
+    return NIL;
+  }
+  return T;			/* return success */
+}
+
+long maildir_sub (MAILSTREAM *stream,char *mailbox)
+{
+  char tmp[MAILTMPLEN];
+  return sm_subscribe (mailbox);
+}
+
+long maildir_unsub (MAILSTREAM *stream,char *mailbox)
+{
+  char tmp[MAILTMPLEN];
+  return sm_unsubscribe (mailbox);
+}
+
+void maildir_lsub (MAILSTREAM *stream,char *ref,char *pat)
+{
+ void *sdb = NIL;
+  char *s;
+                                /* get canonical form of name */
+  if ((s = sm_read (&sdb))) {
+    do if (pmatch_full (s,pat,'/')) mm_lsub (stream,'/',s,NIL);
+    while (s = sm_read (&sdb)); /* until no more subscriptions */
+  }
+
+}
--- pine-4.64.orig/imap/src/osdep/unix/maildir.h
+++ pine-4.64/imap/src/osdep/unix/maildir.h
@@ -0,0 +1,55 @@
+/*
+ * Please read maildir.c for license and information
+ *
+ */
+
+#define MAILDIRPATH "Maildir"
+	
+typedef struct maildir_local {
+  unsigned int inbox : 1;	/* if it is an INBOX or not */
+  unsigned int dirty : 1;	/* diskcopy needs updating */
+  char *dir;			/* mail directory name */
+  char *buf;			/* temporary buffer */
+  char *hdr;			/* current header */
+  unsigned long buflen;		/* current size of temporary buffer */
+  time_t scantime;		/* last time directory scanned */
+} MAILDIRLOCAL;
+
+/* Convenient access to local data */
+
+#define LOCAL ((MAILDIRLOCAL *) stream->local)
+
+/* Function prototypes */
+
+DRIVER *maildir_valid (char *name);
+int maildir_isvalid (char *name,char *tmp,long justname);
+MAILSTREAM *maildir_open (MAILSTREAM *stream);
+void maildir_gc (MAILSTREAM *stream,long gcflags);
+void maildir_close (MAILSTREAM *stream, long options);
+long maildir_ping (MAILSTREAM *stream);
+long maildir_ping_core (MAILSTREAM *stream);
+void maildir_check (MAILSTREAM *stream);
+long maildir_fetchtext (MAILSTREAM *stream,unsigned long msgno,STRING *bs,long flags);
+char *maildir_fetchheader (MAILSTREAM *stream,unsigned long msgno,
+		unsigned long *length, long flags);
+void maildir_fast (MAILSTREAM *stream,char *sequence,long flags);
+void maildir_list (MAILSTREAM *stream,char *ref,char *pat);
+void *maildir_parameters (long function,void *value);
+long maildir_create (MAILSTREAM *stream,char *mailbox);
+void maildir_flagmsg (MAILSTREAM *stream,MESSAGECACHE *elt);
+void maildir_expunge (MAILSTREAM *stream);
+long maildir_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options);
+long maildir_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data);
+short maildir_getflags (MAILSTREAM *stream,char *flag);
+long maildir_delete (MAILSTREAM *stream,char *mailbox);
+long maildir_rename (MAILSTREAM *stream,char *old,char *new);
+long maildir_sub (MAILSTREAM *stream,char *mailbox);
+long maildir_unsub (MAILSTREAM *stream,char *mailbox);
+void maildir_lsub (MAILSTREAM *stream,char *ref,char *pat);
+
+/* utility functions */
+char *maildir_file (char *dst,char *name);
+void maildir_copynew (const char *mailbox);
+int maildir_select (struct direct *name);
+int maildir_namesort (struct direct **d1,struct direct **d2);
+void maildir_listwork(char *name, MAILSTREAM *stream, char *s2, char *subdir, int flag);
--- pine-4.64.orig/imap/src/osdep/unix/privs.c
+++ pine-4.64/imap/src/osdep/unix/privs.c
@@ -0,0 +1,28 @@
+#include <unistd.h>
+#include "privs.h"
+
+static int mailgid = -1;
+static int usergid = -1;
+
+void
+privs_drop()
+{
+	if (usergid != -1)
+	  setgid(usergid);
+	else {
+		mailgid = getegid();
+		usergid = getgid();
+		setgid(usergid);
+	}
+}
+
+void
+privs_set()
+{
+	if (mailgid != -1)
+	  setgid(mailgid);
+	else {
+		mailgid = getegid();
+		usergid = getgid();
+	}
+}
--- pine-4.64.orig/imap/src/osdep/unix/privs.h
+++ pine-4.64/imap/src/osdep/unix/privs.h
@@ -0,0 +1,7 @@
+#ifndef PRIVS_H
+#define PRIVS_H 1
+
+void privs_drop();
+void privs_set();
+
+#endif
--- pine-4.64.orig/README.maildir
+++ pine-4.64/README.maildir
@@ -0,0 +1,93 @@
+Pine 4.0x Maildir c-client module
+---------------------------------
+
+Written by Mattias Larsson <ml@techno.org> <mta@freeit.com>
+
+This is the second release of my Maildir driver for Pine 4. It is based
+on Eric Greens IMAP2bis Maildir driver.
+
+PLEASE NOTE that this driver has only been tested in the IMAP4rev1 daemon
+before. It was just put into Pine 4.00, and it looks like it works, but it
+has not been extensively tested. It has been running for 8 months in
+production in our IMAP4 daemon though.
+
+PLEASE NOTE:
+
+This driver needs to store the UID's of the message in the file somehow. In
+the earlier versions of this driver this was done by adding a new maildir
+flag (the ,3 flag), however, this solution was not very good since most
+other clients could not handle it. Thus I had to find another solution. In
+this driver I use a pretty radical method. Any file in the maildir with the
+execute bit set has its UID set in the mtime of the file. So you should not
+edit the files in here, or in any otherway update the mtime, because then
+the UID gets changed. Most clients should not do this, so I think this
+solution is compatible with most other clients (if you find one that isn't,
+let me know). If you for some reason have to edit a file in the Maildir,
+delete the ".uidvalidity" file in the root of the Maildir (ie, the dir where
+you find cur/ new/ and tmp/). Alternatively, edit maildir.c and define the
+NO_UID_VALIDITY option, which will cause the Maildir to get set new UID's on
+every start up. Note that if you are running IMAP and Netscape as a client,
+you can't change the UID's, because Netscape do not support the UID validity
+flag in the IMAP protocol. So use this with care. 
+
+Please edit the maildir.c file in any case. There are 3 options you can
+set yourself. The default configuration is not suitable for ISPs. If you are
+an ISP, or system with many users, you might want to consider setting some
+of the options different.
+
+Ohh, if there are problems compiling it, let me know, and please let me know
+what you did to fix it. This thing was developed on Solaris (using both GCC
+and SunCC, should work with both), but I haven't tried it on any other
+platform. It is also known to compile cleanly on Linux RH5.1
+
+CONFIGURATION
+-------------
+
+There are a few configurable options. You find these at the top of the
+maildir.c file (and it can be found in imap/src/osdep/unix if I'm not all
+mistaken). Right now, two options are configurable. By default it is
+configured for ISP use, something that you might want to change if you use
+it at home.
+
+HOW TO USE
+----------
+
+Use it as any other c-client driver. There is some option you want to change
+if you want all folders to be created as Maildirs (and I can't remember what
+the option is from the top of my head). Read the pine documentation.
+
+CHANGES
+-------
+
+Rel 4.  Coredump problem fixed. In release 3 I decided to user the sparep
+	in the message cache so no patching of mail.h would be necessary,
+	however, PINE uses this pointer internally for other things, causing
+	coredumps when used with the Rel 3. patch.
+
+Rel 3.	New way of storing UID's (compatible with ,2 clients).
+	Multiple inbox patches applied
+
+Rel 2.  Pine 4 changes.
+
+Rel 1.  Imap4rev 1 driver
+
+FINAL NOTES
+-----------
+
+I'll try to maintain and release new versions as soon as I have time over,
+which unfortunately does not happen very often in this business ;)
+
+You can (might) find newer versions of this driver at:
+
+http://www.freeit.com/mta/
+
+
+Regards,
+Daniel Mattias Larsson
+
+e-mail: ml@techno.org
+ph: +46-707-268785
+snail-mail:
+Industrivagen 4
+SE-194 77 Upplands Vasby
+SWEDEN
--- pine-4.64.orig/debian/rules
+++ pine-4.64/debian/rules
@@ -0,0 +1,142 @@
+#!/usr/bin/make -f
+
+export LDAPLIBS=-lldap -llber
+export LDAPCFLAGS=-DENABLE_LDAP
+
+export SSL="'SSLTYPE=unix'"
+
+VERSION = \
+  $(shell head -n 1 debian/changelog | sed -e 's/.*(//' | sed -e 's/).*//')
+
+CC = gcc
+BASECFLAGS = -g
+OPTIMIZE = -g
+# DEBUG = -DDEBUG
+INSTALL_PROGRAM = install
+
+ifeq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+  BASECFLAGS += -O2
+  OPTIMIZE += -O2
+endif
+ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
+  INSTALL_PROGRAM += -s
+endif
+
+build: build-all
+
+include /usr/share/quilt/quilt.make
+build-all: patch
+	#@cat debian/DO-NOT-DISTRIBUTE-BINARIES
+	#@read dummy
+	./build $(SSL) CC="$(CC)" BASECFLAGS="$(BASECFLAGS)" \
+		OPTIMIZE="$(OPTIMIZE)" DEBUG="$(DEBUG)" \
+		EXTRAAUTHENTICATORS="gss krb" \
+		EXTRACFLAGS="-DHESIOD -DKERBEROS -I/usr/include/kerberosIV" \
+		SSLINCLUDE=/usr/include SSLLIB=/usr/lib \
+		SSLCERTS=/etc/ssl/certs \
+		EXTRALDFLAGS="-lcrypt -lhesiod" \
+		LDAPLIBS="$(LDAPLIBS)" slx
+	touch build-all
+
+clean: clean1 unpatch
+clean1:
+	rm -f build-all
+	./build clean
+	rm -rf bin .bld.hlp pine/date.c
+	rm -f `find . -name "*~"`
+	cd debian && rm -rf pine pilot pine-tracker pine-tech-notes
+	rm -rf debian/files* core debian/substvars
+
+binary-arch: checkroot build-all
+	debian/rules pine
+	debian/rules pilot
+
+binary-indep: checkroot build-all
+	debian/rules pine-tracker
+	debian/rules pine-tech-notes
+
+pine: checkroot build-all
+	rm -rf debian/$@
+	install -d debian/$@/DEBIAN debian/$@/usr/share/doc/$@
+	cd debian/$@ && install -d usr/bin usr/share/man/man1 usr/share/menu
+	cd debian && install -m 755 config postinst postrm $@/DEBIAN
+	cd debian && install -m 644 templates $@/DEBIAN
+	cd debian && install -m 644 menu.pine $@/usr/share/menu/pine
+	$(INSTALL_PROGRAM) bin/pine debian/$@/usr/bin
+	ln -s pine debian/$@/usr/bin/pinef
+	cp -p doc/pine.1 debian/$@/usr/share/man/man1
+	cp -p doc/brochure.txt README.maildir \
+		debian/BUGS.Debian debian/README debian/$@/usr/share/doc/$@
+	cp -p debian/changelog debian/$@/usr/share/doc/$@/changelog.Debian
+	gzip -9 debian/$@/usr/share/doc/$@/changelog.Debian
+	cat -s debian/copyright.in CPYRIGHT > debian/$@/usr/share/doc/$@/copyright
+	gzip -r9 debian/$@/usr/share/man
+	ln -s pine.1.gz debian/$@/usr/share/man/man1/pinef.1.gz
+	dpkg-shlibdeps bin/pine
+	dpkg-gencontrol -isp -p$@ -Pdebian/$@
+	cd debian/$@ && \
+		md5sum `find * -type f ! -regex "DEBIAN/.*"` > DEBIAN/md5sums
+	chown -R root:root debian/$@
+	chmod -R go=rX debian/$@
+	chown root:mail debian/$@/usr/bin/pine
+	chmod 2755 debian/$@/usr/bin/pine
+	dpkg --build debian/$@ ..
+
+pilot: checkroot build-all
+	rm -rf debian/$@
+	install -d debian/$@/DEBIAN debian/$@/usr/share/doc/$@
+	cd debian/$@ && install -d usr/bin usr/share/man/man1
+	$(INSTALL_PROGRAM) bin/pilot debian/$@/usr/bin
+	cp -p doc/pilot.1 debian/$@/usr/share/man/man1
+	cp -p debian/changelog debian/$@/usr/share/doc/$@/changelog.Debian
+	gzip -9 debian/$@/usr/share/doc/$@/changelog.Debian
+	cat -s debian/copyright.in CPYRIGHT > debian/$@/usr/share/doc/$@/copyright
+	gzip -r9 debian/$@/usr/share/man
+	dpkg-shlibdeps bin/pilot
+	dpkg-gencontrol -isp -p$@ -Pdebian/$@
+	cd debian/$@ && \
+		md5sum `find * -type f ! -regex "DEBIAN/.*"` > DEBIAN/md5sums
+	chown -R root:root debian/$@
+	chmod -R go=rX debian/$@
+	dpkg --build debian/$@ ..
+
+pine-tracker: checkroot build-all
+	rm -rf debian/$@
+	install -d debian/$@/DEBIAN debian/$@/usr/share/doc/$@
+	cp -p debian/changelog debian/$@/usr/share/doc/$@/changelog.Debian
+	gzip -9 debian/$@/usr/share/doc/$@/changelog.Debian
+	cat -s debian/copyright.in debian/copyright.pt CPYRIGHT \
+		> debian/$@/usr/share/doc/$@/copyright
+	cp -p debian/README.pine-tracker debian/$@/usr/share/doc/$@/README
+	sed -e 's/THISVERSION/$(VERSION)/' debian/$@.postinst.in \
+		> debian/$@/DEBIAN/postinst
+	chmod 755 debian/$@/DEBIAN/postinst
+	install -m 644 debian/$@.templates debian/$@/DEBIAN/templates
+	install -m 755 debian/$@.postrm debian/$@/DEBIAN/postrm
+	dpkg-gencontrol -isp -p$@ -Pdebian/$@
+	cd debian/$@ && \
+		md5sum `find * -type f ! -regex "DEBIAN/.*"` > DEBIAN/md5sums
+	chown -R root:root debian/$@
+	chmod -R go=rX debian/$@
+	dpkg --build debian/$@ ..
+
+pine-tech-notes: checkroot build-all
+	rm -rf debian/$@
+	install -d debian/$@/DEBIAN
+	cd debian/$@ && install -d usr/share/doc/pine/tech-notes
+	cp -p doc/tech-notes/*.html debian/$@/usr/share/doc/pine/tech-notes
+	ln -s pine debian/$@/usr/share/doc/$@
+	dpkg-gencontrol -isp -p$@ -Pdebian/$@
+	cd debian/$@ && \
+		md5sum `find * -type f ! -regex "DEBIAN/.*"` > DEBIAN/md5sums
+	chown -R root:root debian/$@
+	chmod -R go=rX debian/$@
+	dpkg --build debian/$@ ..
+
+binary: binary-indep binary-arch
+
+checkroot:
+	test root = "`whoami`"
+
+.PHONY: binary binary-arch binary-indep clean checkroot
+.PHONY: pine pilot pine-tracker pine-tech-notes
--- pine-4.64.orig/debian/patches/pine-athena-inbox-hack.patch
+++ pine-4.64/debian/patches/pine-athena-inbox-hack.patch
@@ -0,0 +1,36 @@
+diff -urN pine4.64/pine/folder.c pine4.64L/pine/folder.c
+--- pine4.64/pine/folder.c	2005-09-12 18:04:25.000000000 -0400
++++ pine4.64L/pine/folder.c	2006-10-17 14:24:14.000000000 -0400
+@@ -7823,8 +7823,13 @@
+     /*
+      * "Inbox" is filtered out here, since pine only supports one true
+      * inbox...
++     * Athena hack: don't do this filtering.  Also see mailcmd.c,
++     * where we modify pine to only special-case folders named "inbox"
++     * in the first context.  (The first context is where the primary
++     * inbox gets shoved in by init_folders(); that's pretty bogus,
++     * but it doesn't bother our default configuration.)
+      */
+-    if(!(attribs & LATT_NOSELECT) && strucmp(mailbox, "inbox")){
++    if(1){
+ 	ld->response.count++;
+ 	ld->response.isfile = 1;
+ 	new_f = new_folder(mailbox, 0);
+diff -urN pine4.64/pine/mailcmd.c pine4.64L/pine/mailcmd.c
+--- pine4.64/pine/mailcmd.c	2005-09-12 18:04:25.000000000 -0400
++++ pine4.64L/pine/mailcmd.c	2006-10-17 14:24:15.000000000 -0400
+@@ -7501,8 +7501,13 @@
+      * So, IF we're asked to open inbox AND it's already open AND
+      * the only stream AND it's healthy, just return ELSE fall thru
+      * and close mail_stream returning with inbox_stream as new stream...
++     *
++     * Athena hack: only special-case "inbox" in the first context (where
++     * it is shoved by init_folders()), so that the MH or pine folder
++     * collection can display an "inbox" folder.
+      */
+-    if(open_inbox = (strucmp(newfolder, ps_global->inbox_name) == 0
++    if(open_inbox = ((strucmp(newfolder, ps_global->inbox_name) == 0
++		      && new_context == ps_global->context_list)
+ 		     || strcmp(newfolder, ps_global->VAR_INBOX_PATH) == 0
+ 		     || same_remote_mailboxes(newfolder,
+ 					      ps_global->VAR_INBOX_PATH)
--- pine-4.64.orig/debian/patches/pine-athena-paths.patch
+++ pine-4.64/debian/patches/pine-athena-paths.patch
@@ -0,0 +1,119 @@
+diff -urN pine4.64/pine/mailcap.c pine4.64L/pine/mailcap.c
+--- pine4.64/pine/mailcap.c	2004-11-03 15:11:00.000000000 -0500
++++ pine4.64L/pine/mailcap.c	2006-10-17 14:24:15.000000000 -0400
+@@ -96,11 +96,11 @@
+ #define MC_PATH_SEPARATOR ':'
+ #define	MC_USER_FILE	  NULL
+ #define MC_STDPATH         \
+-		".mailcap:/etc/mailcap:/usr/etc/mailcap:/usr/local/etc/mailcap"
++		".mailcap:/usr/athena/etc/mailcap"
+ #define MT_PATH_SEPARATOR ':'
+ #define	MT_USER_FILE	  NULL
+ #define MT_STDPATH         \
+-		".mime.types:/etc/mime.types:/usr/local/lib/mime.types"
++		".mime.types:/usr/athena/etc/mime.types"
+ #endif /* !DOS */
+ 
+ #ifdef	_WINDOWS
+diff -urN pine4.64/pine/osdep/os-lnx.h pine4.64L/pine/osdep/os-lnx.h
+--- pine4.64/pine/osdep/os-lnx.h	2003-05-23 12:05:21.000000000 -0400
++++ pine4.64L/pine/osdep/os-lnx.h	2006-10-17 14:24:19.000000000 -0400
+@@ -163,10 +163,10 @@
+ 
+ /*----- System-wide config file ----------------------------------------*/
+ #ifndef SYSTEM_PINERC
+-#define SYSTEM_PINERC             "/usr/local/lib/pine.conf"
++#define SYSTEM_PINERC             "/usr/athena/etc/pine.conf"
+ #endif
+ #ifndef SYSTEM_PINERC_FIXED
+-#define SYSTEM_PINERC_FIXED       "/usr/local/lib/pine.conf.fixed"
++#define SYSTEM_PINERC_FIXED       "/usr/athena/etc/pine.conf.fixed"
+ #endif
+ 
+ 
+@@ -234,7 +234,7 @@
+ 
+ /*--------- Program employed by users to change their password ---------*/
+ #ifndef	PASSWD_PROG
+-#define	PASSWD_PROG	"/bin/passwd"
++#define	PASSWD_PROG	"/usr/athena/bin/passwd"
+ #endif
+ 
+ 
+@@ -280,7 +280,7 @@
+        8
+        9 logs gross details of command execution
+  ----*/
+-#define DEFAULT_DEBUG 2
++#define DEFAULT_DEBUG 0
+ 
+ 
+ 
+diff -urN pine4.64/pine/osdep/os-sgi.h pine4.64L/pine/osdep/os-sgi.h
+--- pine4.64/pine/osdep/os-sgi.h	2003-05-23 12:05:21.000000000 -0400
++++ pine4.64L/pine/osdep/os-sgi.h	2006-10-17 14:24:19.000000000 -0400
+@@ -163,10 +163,10 @@
+ 
+ /*----- System-wide config file ----------------------------------------*/
+ #ifndef SYSTEM_PINERC
+-#define SYSTEM_PINERC             "/usr/local/lib/pine.conf"
++#define SYSTEM_PINERC             "/usr/athena/etc/pine.conf"
+ #endif
+ #ifndef SYSTEM_PINERC_FIXED
+-#define SYSTEM_PINERC_FIXED       "/usr/local/lib/pine.conf.fixed"
++#define SYSTEM_PINERC_FIXED       "/usr/athena/etc/pine.conf.fixed"
+ #endif
+ 
+ 
+@@ -234,7 +234,7 @@
+ 
+ /*--------- Program employed by users to change their password ---------*/
+ #ifndef	PASSWD_PROG
+-#define	PASSWD_PROG	"/bin/passwd"
++#define	PASSWD_PROG	"/usr/athena/bin/passwd"
+ #endif
+ 
+ 
+@@ -280,7 +280,7 @@
+        8
+        9 logs gross details of command execution
+  ----*/
+-#define DEFAULT_DEBUG 2
++#define DEFAULT_DEBUG 0
+ 
+ 
+ 
+diff -urN pine4.64/pine/osdep/os-sol.h pine4.64L/pine/osdep/os-sol.h
+--- pine4.64/pine/osdep/os-sol.h	2003-05-23 12:05:21.000000000 -0400
++++ pine4.64L/pine/osdep/os-sol.h	2006-10-17 14:24:19.000000000 -0400
+@@ -163,10 +163,10 @@
+ 
+ /*----- System-wide config file ----------------------------------------*/
+ #ifndef SYSTEM_PINERC
+-#define SYSTEM_PINERC             "/usr/local/lib/pine.conf"
++#define SYSTEM_PINERC             "/usr/athena/etc/pine.conf"
+ #endif
+ #ifndef SYSTEM_PINERC_FIXED
+-#define SYSTEM_PINERC_FIXED       "/usr/local/lib/pine.conf.fixed"
++#define SYSTEM_PINERC_FIXED       "/usr/athena/etc/pine.conf.fixed"
+ #endif
+ 
+ 
+@@ -234,7 +234,7 @@
+ 
+ /*--------- Program employed by users to change their password ---------*/
+ #ifndef	PASSWD_PROG
+-#define	PASSWD_PROG	"/bin/passwd"
++#define	PASSWD_PROG	"/usr/athena/bin/passwd"
+ #endif
+ 
+ 
+@@ -280,7 +280,7 @@
+        8
+        9 logs gross details of command execution
+  ----*/
+-#define DEFAULT_DEBUG 2
++#define DEFAULT_DEBUG 0
+ 
+ 
+ 
--- pine-4.64.orig/debian/patches/pine-build-gssapi.patch
+++ pine-4.64/debian/patches/pine-build-gssapi.patch
@@ -0,0 +1,20 @@
+diff -ur pine4.64-hesiod/imap/src/osdep/unix/Makefile.gss pine4.64-hesiod-krb4/imap/src/osdep/unix/Makefile.gss
+--- pine4.64/imap/src/osdep/unix/Makefile.gss	2003-03-04 22:29:59.000000000 -0500
++++ pine4.64L/imap/src/osdep/unix/Makefile.gss	2003-04-30 21:32:13.000000000 -0400
+@@ -20,12 +20,11 @@
+ 
+ # Extended flags needed for additional authenticators.  You may need to modify.
+ 
+-GSSDIR=/usr/local
+-GSSCFLAGS= -I$(GSSDIR)/include -DGSS_C_NT_HOSTBASED_SERVICE=gss_nt_service_name
+-GSSOLDLDFLAGS= -L$(GSSDIR)/lib -lgssapi_krb5 -lkrb5 -lcrypto -lcom_err
+-GSSNEWLDFLAGS= -L$(GSSDIR)/lib -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err
++GSSCFLAGS= -DGSS_C_NT_HOSTBASED_SERVICE=gss_nt_service_name
++GSSLDFLAGS= -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err
+ 
+ gss:	# GSSAPI Kerberos V flags
+ 	echo $(GSSCFLAGS) >> OSCFLAGS
+-	sh -c '(test -f $(GSSDIR)/lib/libk5crypto.a) && echo $(GSSNEWLDFLAGS) || echo $(GSSOLDLDFLAGS)' >> LDFLAGS
++	echo $(GSSLDFLAGS) >> LDFLAGS
+ 	echo "#include \"kerb_mit.c\"" >> auths.c
++
--- pine-4.64.orig/debian/patches/pine-creatdir-afs.patch
+++ pine-4.64/debian/patches/pine-creatdir-afs.patch
@@ -0,0 +1,21 @@
+diff -urN pine4.64/pine/osdep/creatdir pine4.64L/pine/osdep/creatdir
+--- pine4.64/pine/osdep/creatdir	1993-07-15 19:03:58.000000000 -0400
++++ pine4.64L/pine/osdep/creatdir	2001-02-20 19:21:35.000000000 -0500
+@@ -9,12 +9,17 @@
+ create_mail_dir(dir)
+     char *dir;
+ {
++    char tmp[MAXPATH+128];
++
+     if(mkdir(dir, 0700) < 0)
+       return(-1);
+ 
+     (void)chmod(dir, 0700);
+     /* Some systems need this, on others we don't care if it fails */
+     (void)chown(dir, getuid(), getgid());
++    sprintf(tmp, "fs sa %.*s system:anyuser none system:authuser none",
++	    (int) MAXPATH, dir);
++    system(tmp);
+     return(0);
+ }
+ 
--- pine-4.64.orig/debian/patches/pine-hesiod.patch
+++ pine-4.64/debian/patches/pine-hesiod.patch
@@ -0,0 +1,126 @@
+diff -urN pine4.64/imap/src/c-client/mail.c pine4.64L/imap/src/c-client/mail.c
+--- pine4.64/imap/src/c-client/mail.c	2005-09-15 12:57:31.000000000 -0400
++++ pine4.64L/imap/src/c-client/mail.c	2006-10-17 14:24:12.000000000 -0400
+@@ -28,6 +28,9 @@
+ #include "rfc822.h"
+ #include "utf8.h"
+ #include "smtp.h"
++#ifdef HESIOD
++#include <hesiod.h>
++#endif
+ 
+ char *UW_copyright = "The IMAP toolkit provided in this Distribution is\nCopyright 1988-2005 University of Washington.\nThe full text of our legal notices is contained in the file called\nCPYRIGHT, included with this Distribution.\n";
+ 
+@@ -633,6 +636,76 @@
+ }
+ 
+ 
++#ifdef HESIOD
++/* Mail lookup and validate hesiod information
++ * Accepts: NETMBX structure to process
++ * Returns: T on success, NIL on failure
++ */
++
++static long mail_valid_hesiod (NETMBX *mb)
++{
++  char *user;
++  struct hesiod_postoffice *office;
++  struct servent *serv;
++  char tmp[MAILTMPLEN], service[NETMAXSRV];
++  void *hcontext;
++
++  if (mb->user && *mb->user)	/* Allows for the /user=foo switch */
++    user = mb->user;
++  else
++    user = myusername ();
++  sprintf (tmp,"Hesiod lookup for \"%s\"",user);
++  mm_log (tmp,NIL);
++
++  if (hesiod_init (&hcontext) == 0) {
++    office = hesiod_getmailhost (hcontext,user);
++    if (office && *office->hesiod_po_type
++	&& *office->hesiod_po_host && *office->hesiod_po_name) {
++      sprintf(tmp,"Hesiod answer: %s %s %s",
++	      office->hesiod_po_type,office->hesiod_po_host,
++	      office->hesiod_po_name);
++      mm_log(tmp,NIL);
++    }
++    else {
++      sprintf (tmp,"Hesiod error while determining PO server for \"%s\"",user);
++      mm_log (tmp,ERROR);
++      if (office)
++	hesiod_free_postoffice (hcontext,office);
++      hesiod_end (hcontext);
++      return NIL;
++    }
++  }
++  else {
++      sprintf(tmp,
++	      "Hesiod initialization error determining PO server for \"%s\"",
++	      user);
++      mm_log(tmp,ERROR);
++      return NIL;
++  }
++
++  strcpy(mb->host,office->hesiod_po_host);
++  strcpy(mb->user,office->hesiod_po_name);
++  /* Set service if it isn't specified, but don't force compliance. */
++  if (!*mb->service) {
++    if (!strcmp (office->hesiod_po_type,"POP"))
++      strcpy (mb->service,"pop3");
++    else if (!strcmp (office->hesiod_po_type,"IMAP"))
++      strcpy (mb->service,"imap");
++    else {
++      sprintf (tmp,"Hesiod error while determining PO server for \"%s\"",user);
++      mm_log (tmp,ERROR);
++      return NIL;
++    }
++  }
++
++  hesiod_free_postoffice (hcontext,office);
++  hesiod_end (hcontext);
++
++  return T;
++}
++#endif /* HESIOD */
++
++
+ /* Mail validate network mailbox name
+  * Accepts: mailbox name
+  *	    NETMBX structure to return values
+@@ -720,6 +799,9 @@
+       else {			/* non-argument switch */
+ 	if (!compare_cstring (s,"anonymous")) mb->anoflag = T;
+ 	else if (!compare_cstring (s,"debug")) mb->dbgflag = T;
++#ifdef HESIOD
++	else if (!compare_cstring (s,"hesiod")) mb->hesflag = T;
++#endif
+ 	else if (!compare_cstring (s,"readonly")) mb->readonlyflag = T;
+ 	else if (!compare_cstring (s,"secure")) mb->secflag = T;
+ 	else if (!compare_cstring (s,"norsh")) mb->norsh = T;
+@@ -756,6 +841,12 @@
+       return NIL;
+     } while (c);		/* see if anything more to parse */
+   }
++#ifdef HESIOD
++  if (mb->hesflag) {
++    if (!mail_valid_hesiod (mb))
++      return NIL;
++  }
++#endif
+ 				/* default mailbox name */
+   if (!*mb->mailbox) strcpy (mb->mailbox,"INBOX");
+ 				/* default service name */
+diff -urN pine4.64/imap/src/c-client/mail.h pine4.64L/imap/src/c-client/mail.h
+--- pine4.64/imap/src/c-client/mail.h	2005-02-08 18:44:54.000000000 -0500
++++ pine4.64L/imap/src/c-client/mail.h	2006-10-17 14:24:13.000000000 -0400
+@@ -599,6 +599,9 @@
+   unsigned int readonlyflag : 1;/* want readonly */
+   unsigned int norsh : 1;	/* don't use rsh/ssh */
+   unsigned int loser : 1;	/* server is a loser */
++#ifdef HESIOD
++  unsigned int hesflag : 1;    /* Hesiod flag */
++#endif
+ } NETMBX;
+ 
+ /* Item in an address list */
--- pine-4.64.orig/debian/patches/pine-krb4.patch
+++ pine-4.64/debian/patches/pine-krb4.patch
@@ -0,0 +1,1398 @@
+diff -urN pine4.64-hesiod/imap/Makefile pine4.64-hesiod-krb4/imap/Makefile
+--- pine4.64/imap/Makefile	2005-04-30 16:50:20.000000000 -0400
++++ pine4.64L/imap/Makefile	2006-10-17 14:24:12.000000000 -0400
+@@ -502,6 +502,7 @@
+ 	$(TOOLS)/$@ "$(LN)" src/c-client c-client
+ 	$(TOOLS)/$@ "$(LN)" src/ansilib c-client
+ 	$(TOOLS)/$@ "$(LN)" src/charset c-client
++	sh -c '(test -d src/kerberos) && ($(LN) `pwd`/src/kerberos/* c-client) || true'
+ 	$(TOOLS)/$@ "$(LN)" src/osdep/$(SYSTEM) c-client
+ 	$(TOOLS)/$@ "$(LN)" src/mtest mtest
+ 	$(TOOLS)/$@ "$(LN)" src/ipopd ipopd
+diff -urN pine4.64-hesiod/imap/src/c-client/mail.c pine4.64-hesiod-krb4/imap/src/c-client/mail.c
+--- pine4.64/imap/src/c-client/mail.c	2006-10-17 14:24:13.000000000 -0400
++++ pine4.64L/imap/src/c-client/mail.c	2006-10-17 14:24:13.000000000 -0400
+@@ -698,6 +698,12 @@
+     }
+   }
+ 
++#ifdef KERBEROS
++  /* kpop runs on a different port from pop3, so we have to set an override. */
++  if (!mb->port && mb->krbflag && !strcmp (mb->service,"pop3"))
++    mb->port = 1109;
++#endif
++
+   hesiod_free_postoffice (hcontext,office);
+   hesiod_end (hcontext);
+ 
+@@ -796,6 +802,9 @@
+ #ifdef HESIOD
+ 	else if (!compare_cstring (s,"hesiod")) mb->hesflag = T;
+ #endif
++#ifdef KERBEROS
++	else if (!compare_cstring (s,"kerberos")) mb->krbflag = T;
++#endif
+ 	else if (!compare_cstring (s,"readonly")) mb->readonlyflag = T;
+ 	else if (!compare_cstring (s,"secure")) mb->secflag = T;
+ 	else if (!compare_cstring (s,"norsh")) mb->norsh = T;
+diff -urN pine4.64-hesiod/imap/src/c-client/mail.h pine4.64-hesiod-krb4/imap/src/c-client/mail.h
+--- pine4.64/imap/src/c-client/mail.h	2006-10-17 14:24:13.000000000 -0400
++++ pine4.64L/imap/src/c-client/mail.h	2006-10-17 14:24:13.000000000 -0400
+@@ -602,6 +602,9 @@
+ #ifdef HESIOD
+   unsigned int hesflag : 1;    /* Hesiod flag */
+ #endif
++#ifdef KERBEROS
++  unsigned int krbflag : 1;    /* Kerberos flag */
++#endif
+ } NETMBX;
+ 
+ /* Item in an address list */
+diff -urN pine4.64-hesiod/imap/src/c-client/pop3.c pine4.64-hesiod-krb4/imap/src/c-client/pop3.c
+--- pine4.64/imap/src/c-client/pop3.c	2005-03-08 21:39:07.000000000 -0500
++++ pine4.64L/imap/src/c-client/pop3.c	2006-10-17 14:24:13.000000000 -0400
+@@ -557,6 +557,23 @@
+   NETDRIVER *ssld = (NETDRIVER *) mail_parameters (NIL,GET_SSLDRIVER,NIL);
+   sslstart_t stls = (sslstart_t) mail_parameters (NIL,GET_SSLSTART,NIL);
+ 				/* server has TLS? */
++
++#ifdef KERBEROS
++  if (mb->krbflag) {
++    /* We already took care of sending the ticket in tcp_unix.c, since
++     * that has to happen before the read of the server greeting.  So
++     * we just need to send the username here. */
++    if (mb->user && *mb->user)
++      strcpy (usr,mb->user);
++    else
++      strcpy (usr,myusername());
++    /* Send same PASS as USER. */
++    if (pop3_send (stream,"USER",usr) && pop3_send (stream,"PASS",usr))
++      return LONGT;		/* success */
++    else
++      return NIL;
++  }
++#endif
+   if (stls && LOCAL->cap.stls && !mb->sslflag && !mb->notlsflag &&
+       pop3_send (stream,"STLS",NIL)) {
+     mb->tlsflag = T;		/* TLS OK, get into TLS at this end */
+diff -urN pine4.64-hesiod/imap/src/kerberos/acte.c pine4.64-hesiod-krb4/imap/src/kerberos/acte.c
+--- pine4.64/imap/src/kerberos/acte.c	1969-12-31 19:00:00.000000000 -0500
++++ pine4.64L/imap/src/kerberos/acte.c	2001-02-19 03:03:07.000000000 -0500
+@@ -0,0 +1,48 @@
++/* acte.c -- Common functions for SASL mechanisms 
++ *
++ *	(C) Copyright 1994 by Carnegie Mellon University
++ *
++ *                      All Rights Reserved
++ *
++ * Permission to use, copy, modify, distribute, and sell this software
++ * and its documentation for any purpose is hereby granted without
++ * fee, provided that the above copyright notice appear in all copies
++ * and that both that copyright notice and this permission notice
++ * appear in supporting documentation, and that the name of Carnegie
++ * Mellon University not be used in advertising or publicity
++ * pertaining to distribution of the software without specific,
++ * written prior permission.  Carnegie Mellon University makes no
++ * representations about the suitability of this software for any
++ * purpose.  It is provided "as is" without express or implied
++ * warranty.
++ *
++ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
++ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
++ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
++ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
++ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
++ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
++ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
++ * SOFTWARE.
++ *
++ */
++
++#include "acte.h"
++
++char *acte_prottostring(protlevel)
++int protlevel;
++{
++    switch (protlevel) {
++    case ACTE_PROT_NONE:
++	return "no protection";
++
++    case ACTE_PROT_INTEGRITY:
++	return "integrity protection";
++
++    case ACTE_PROT_PRIVACY:
++	return "privacy protection";
++
++    default:
++	return "unknown";
++    }
++}
+diff -urN pine4.64-hesiod/imap/src/kerberos/acte.h pine4.64-hesiod-krb4/imap/src/kerberos/acte.h
+--- pine4.64/imap/src/kerberos/acte.h	1969-12-31 19:00:00.000000000 -0500
++++ pine4.64L/imap/src/kerberos/acte.h	2003-02-14 17:12:36.000000000 -0500
+@@ -0,0 +1,124 @@
++/* acte.h -- Interface for IMAP AUTHENTICATE mechanisms 
++ *
++ *	(C) Copyright 1994,1996 by Carnegie Mellon University
++ *
++ *                      All Rights Reserved
++ *
++ * Permission to use, copy, modify, distribute, and sell this software
++ * and its documentation for any purpose is hereby granted without
++ * fee, provided that the above copyright notice appear in all copies
++ * and that both that copyright notice and this permission notice
++ * appear in supporting documentation, and that the name of Carnegie
++ * Mellon University not be used in advertising or publicity
++ * pertaining to distribution of the software without specific,
++ * written prior permission.  Carnegie Mellon University makes no
++ * representations about the suitability of this software for any
++ * purpose.  It is provided "as is" without express or implied
++ * warranty.
++ *
++ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
++ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
++ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
++ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
++ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
++ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
++ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
++ * SOFTWARE.
++ *
++ */
++
++#ifndef INCLUDED_ACTE_H
++#define INCLUDED_ACTE_H
++
++#ifndef P
++#ifdef __STDC__
++#define P(x) x
++#else
++#define P(x) ()
++#endif
++#endif
++
++#include <time.h>
++
++struct sockaddr;
++
++typedef const char *acte_encodefunc_t P((void *state,
++					  char *input, int inputlen,
++					  char *output, int *outputlen));
++typedef const char *acte_decodefunc_t P((void *state,
++					  char *input, int inputlen,
++					  char **output, int *outputlen));
++typedef int acte_authproc_t P((const char *user, const char *auth_identity,
++			       const char **reply));
++
++/* Client-side authentication mechanism */
++struct acte_client {
++    /* Name of authentication mechanism */
++    char *auth_type;
++
++    /* Start a client->server authentication */
++    int (*start) P((const char *service, const char *host, const char *user,
++		    int protallowed, int maxbufsize,
++		    struct sockaddr *localaddr, struct sockaddr *remoteaddr,
++		    void **state, char *u_out));
++
++    /* Do an authentication protocol exchange */
++    int (*auth) P((void *state, int inputlen, char *input,
++		   int *outputlen, char **output));
++    
++    /* Query an authentication state */
++    void (*query_state) P((void *state, char **user, int *protlevel,
++			   acte_encodefunc_t **encodefunc,
++			   acte_decodefunc_t **decodefunc, int *maxplain));
++
++    /* Free an authentication state */
++    void (*free_state) P((void *state));
++    
++    /* Acquire daemon's credentials */
++    const char *(*new_cred) P((const char *service, time_t *lifetime));	
++
++    /* Free daemon's credentials */
++    void (*free_cred) P((void));
++};
++
++/* Server-side authentication mechanism */
++struct acte_server {
++    /* Name of authentication mechanism */
++    char *auth_type;		
++
++    /* Start an incoming authentication */
++    int (*start) P((const char *service, acte_authproc_t *authproc,
++		    int protallowed, int maxbufsize,
++		    struct sockaddr *localaddr, struct sockaddr *remoteaddr,
++		    int *outputlen, char **output,
++		    void **state, const char ** reply));
++    
++    /* Do an authentication protocol exchange */
++    int (*auth) P((void *state, int inputlen, char *input,
++		   int *outputlen, char **output, const char **reply));
++
++    /* Query an authentication state */
++    void (*query_state) P((void *state, char **user, int *protlevel,
++			   acte_encodefunc_t **encodefunc,
++			   acte_decodefunc_t **decodefunc, int *maxplain));
++
++    /* Free an authentication state */
++    void (*free_state) P((void *state));
++    
++    /* Get a cacheid, if available */
++    char *(*get_cacheid) P((void *state));
++};
++
++/* Protection mechanisms */
++#define ACTE_PROT_NONE 1
++#define ACTE_PROT_INTEGRITY 2
++#define ACTE_PROT_PRIVACY 4
++#define ACTE_PROT_ANY (ACTE_PROT_NONE|ACTE_PROT_INTEGRITY|ACTE_PROT_PRIVACY)
++
++#define ACTE_FAIL 1		/* Authentication failed */
++
++#define ACTE_DONE 3		/* Server has authenticated user */
++
++extern char *acte_prottostring P((int protlevel));
++
++#endif /* INCLUDED_ACTE_H */
+diff -urN pine4.64-hesiod/imap/src/kerberos/acte_krb.c pine4.64-hesiod-krb4/imap/src/kerberos/acte_krb.c
+--- pine4.64/imap/src/kerberos/acte_krb.c	1969-12-31 19:00:00.000000000 -0500
++++ pine4.64L/imap/src/kerberos/acte_krb.c	2005-01-26 16:13:35.000000000 -0500
+@@ -0,0 +1,874 @@
++/* acte_krb.c -- KERBEROS_V4 authentication routines for IMAP.
++ *
++ *	(C) Copyright 1994 by Carnegie Mellon University
++ *
++ *                      All Rights Reserved
++ *
++ * Permission to use, copy, modify, distribute, and sell this software
++ * and its documentation for any purpose is hereby granted without
++ * fee, provided that the above copyright notice appear in all copies
++ * and that both that copyright notice and this permission notice
++ * appear in supporting documentation, and that the name of Carnegie
++ * Mellon University not be used in advertising or publicity
++ * pertaining to distribution of the software without specific,
++ * written prior permission.  Carnegie Mellon University makes no
++ * representations about the suitability of this software for any
++ * purpose.  It is provided "as is" without express or implied
++ * warranty.
++ *
++ * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
++ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
++ * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
++ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
++ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
++ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
++ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
++ * SOFTWARE.
++ *
++ */
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <netdb.h>
++#include <sys/types.h>
++#include <sys/param.h>
++#include <netinet/in.h>
++#include <krb.h>
++
++#include "acte.h"
++
++#ifndef HAVE_KRB_GET_PHOST
++extern char *krb_get_phost P((char *));
++#endif
++
++#ifndef HAVE_KRB_REALMOFHOST
++extern char *krb_realmofhost P((char *));
++#endif
++
++static char *srvtab = "";	/* Srvtab filename */
++
++/* Maximum number of bytes of overhead the protection mechanisms use */
++#define PROTECTION_OVERHEAD 31
++
++/* Private state used by this mechanism */
++struct krb_state {
++    /* common */
++    char service[MAX_K_NAME_SZ+1];
++    int authstepno;
++    des_cblock session;	/* Our session key */
++    des_key_schedule schedule; /* Schedule for our session key */
++    long challenge;
++    char user[MAX_K_NAME_SZ+1];
++    int protallowed;
++    int maxbufsize;
++    struct sockaddr_in localaddr, remoteaddr;
++    long prot_time_sec;
++    char prot_time_5ms;
++    /* client */
++    char instance[INST_SZ];
++    char realm[REALM_SZ];
++    /* server */
++    int (*authproc)();
++    AUTH_DAT kdata;
++};
++
++/*
++ * Free the space used by an opaque state pointer
++ */
++static void
++krb_free_state(state)
++void *state;
++{
++    memset((char *)state, 0, sizeof(struct krb_state));
++    free((char *) state);
++}
++
++static acte_encodefunc_t krb_en_integrity;
++static acte_decodefunc_t krb_de_integrity;
++#ifndef NOPRIVACY
++static acte_encodefunc_t krb_en_privacy;
++static acte_decodefunc_t krb_de_privacy;
++#endif
++
++/*
++ * Query public values of the state pointer after authentiation
++ * complete.  Fills in buffers pointed to by the following arguments:
++ *
++ * user       -- IMAP userid authenticated as
++ * protlevel  -- bitmask for selected protection mechanism
++ * encodefunc -- if nonzero, protection mechanism function to encode
++ *               outgoing data with.
++ * decodefunc -- if nonzero, protection mechanism function to decode
++ *               incoming data with.
++ * maxplain   -- The maximum number of bytes that may be encoded by
++ *                the encodefunc at one time
++ */
++static void 
++krb_query_state(state, user, protlevel, encodefunc, decodefunc, maxplain)
++void *state;
++char **user;
++int *protlevel;
++acte_encodefunc_t **encodefunc;
++acte_decodefunc_t **decodefunc;
++int *maxplain;
++{
++    struct krb_state *kstate = (struct krb_state *)state;
++
++    *user = kstate->user;
++    *protlevel = kstate->protallowed;
++
++    switch (kstate->protallowed) {
++    case ACTE_PROT_NONE:
++	*encodefunc = 0;
++	*decodefunc = 0;
++	*maxplain = 0;
++	return;
++
++    case ACTE_PROT_INTEGRITY:
++	*encodefunc = krb_en_integrity;
++	*decodefunc = krb_de_integrity;
++	*maxplain = kstate->maxbufsize - PROTECTION_OVERHEAD;
++	return;
++
++#ifndef NOPRIVACY
++    case ACTE_PROT_PRIVACY:
++	*encodefunc = krb_en_privacy;
++	*decodefunc = krb_de_privacy;
++	*maxplain = kstate->maxbufsize - PROTECTION_OVERHEAD;
++	return;
++#endif
++
++    default:
++	abort();
++    }
++}
++
++/*
++ * Get the cacheid for 'state'
++ */
++static char *
++krb_get_cacheid(state)
++void *state;
++{
++    char *cacheid;
++
++    struct krb_state *kstate = (struct krb_state *)state;
++
++    cacheid = malloc(16);
++    if (!cacheid) return 0;
++
++    memset(cacheid, 0, sizeof(cacheid));
++    memcpy(cacheid, kstate->session, sizeof(kstate->session));
++    return cacheid;
++}
++
++/*
++ * Start the client side of an authentication exchange.
++ */
++static int krb_client_start(service, host, user, protallowed, maxbufsize,
++			    localaddr, remoteaddr, state, u_out)
++const char *service;		/* Name of service */
++const char *host;		/* Name of server host */
++const char *user;		/* (optional) user to log in as */
++int protallowed;		/* Protection mechanisms allowed */
++int maxbufsize;			/* Maximum ciphertext input buffer size */
++struct sockaddr *localaddr;	/* Network address of local side */
++struct sockaddr *remoteaddr;	/* Network address of remote side */
++void **state;			/* On success, filled in with state ptr */
++char *u_out;                    /* Output buffer for username 
++				 * if non-null must be atleast MAX_K_NAME_SZ+1                                  * large */
++{
++    struct hostent *host_name;
++    char userbuf[MAX_K_NAME_SZ+1];
++    char instance[INST_SZ];
++    char realm[REALM_SZ];
++    char uinst[INST_SZ];
++    char urealm[INST_SZ];
++    KTEXT_ST authent;
++    CREDENTIALS cr;
++    struct krb_state *kstate;
++    char *p;
++
++    protallowed &= ACTE_PROT_NONE|ACTE_PROT_INTEGRITY
++#ifndef NOPRIVACY
++	|ACTE_PROT_PRIVACY
++#endif
++	;
++    if (!localaddr || !remoteaddr) {
++	protallowed &= ACTE_PROT_NONE;
++    }
++    if (!protallowed) {
++	return ACTE_FAIL;
++    }
++    if (maxbufsize > 0xffffff) maxbufsize = 0xffffff;
++
++    /* Canonicalize hostname */
++    host_name = gethostbyname(host);
++    if (!host_name) {
++	return ACTE_FAIL;
++    }
++
++    strncpy(instance, host_name->h_name, sizeof(instance)-1);
++    instance[sizeof(instance)-1] = '\0';
++    /* downcase the instance */
++    p = instance;
++    do {
++      if (isupper(*p)) *p=tolower(*p);
++    } while (*p++);
++    strcpy(realm, krb_realmofhost(instance));
++    if (p = strchr(instance, '.')) *p = '\0';
++
++    /* Fetch imap.hostname service key */
++    (void) krb_mk_req(&authent, service, instance, realm, 0);
++    memset(&authent, 0, sizeof(authent));
++
++    if (krb_get_cred(service, instance, realm, &cr)) {
++	return ACTE_FAIL;
++    }
++    
++    if (!user || !user[0]) {
++	if (krb_get_tf_fullname(TKT_FILE, userbuf, uinst, urealm)) {
++	    memset(&cr, 0, sizeof(cr));
++	    return ACTE_FAIL;
++	}
++	if (uinst[0]) {
++	    strcat(userbuf, ".");
++	    strcat(userbuf, uinst);
++	}
++	if (strcmp(urealm, realm) != 0) {
++	    strcat(userbuf, "@");
++	    strcat(userbuf, urealm);
++	}
++	user = userbuf;
++    }
++    else if (strlen(user) > MAX_K_NAME_SZ) {
++	return ACTE_FAIL;
++    }
++
++    if(u_out) memcpy(u_out, user, strlen(userbuf) + 1);
++
++    kstate = (struct krb_state *)malloc(sizeof(struct krb_state));
++    if (!kstate) return ACTE_FAIL;
++    memset((char *)kstate, 0, sizeof(*kstate));
++    strcpy(kstate->service, service);
++    kstate->authstepno = 0;
++    memcpy(kstate->session, cr.session, sizeof(des_cblock));
++    des_key_sched(kstate->session, kstate->schedule);
++    strcpy(kstate->user, user);
++    kstate->protallowed = protallowed;
++    kstate->maxbufsize = maxbufsize;
++    if (localaddr && remoteaddr) {
++	kstate->localaddr = *(struct sockaddr_in *)localaddr;
++	kstate->remoteaddr = *(struct sockaddr_in *)remoteaddr;
++    }
++    strcpy(kstate->instance, instance);
++    strcpy(kstate->realm, realm);
++
++    memset(&cr, 0, sizeof(cr));
++    *state = (void *)kstate;
++    return 0;
++}
++
++/*
++ * Perform client-side authentication protocol exchange
++ * Returns ACTE_DONE if authentication can be complete after
++ * sending our client reply.
++ */
++static int krb_client_auth(state, inputlen, input, outputlen, output)
++void *state;			/* State of exchange */
++int inputlen;			/* Length of server response */
++char *input;			/* Server response data */
++int *outputlen;			/* Set to length of client reply */
++char **output;			/* Set to point to client reply data */
++{
++    static KTEXT_ST authent;
++    struct krb_state *kstate = (struct krb_state *)state;
++    char tmp[4];
++    int code;
++    int maxbufsize;
++
++    switch (kstate->authstepno++) {
++    case 0:
++	/* Server gave us challenge, respond with ticket+authenticator */
++	if (inputlen < 4) {
++	    kstate->authstepno = -1;
++	    return ACTE_FAIL;
++	}
++	memcpy(tmp, input, 4);
++	kstate->challenge = ntohl(*(int *)tmp);
++
++	code = krb_mk_req(&authent, kstate->service, kstate->instance,
++			  kstate->realm, kstate->challenge);
++	if (code) {
++	    kstate->authstepno = -1;
++	    return ACTE_FAIL;
++	}
++	*outputlen = authent.length;
++	*output = authent.dat;
++	return 0;
++
++    case 1:
++	/*
++	 * Server gave us mutual auth reply+available protection mechanisms.
++	 * Respond with challenge, desired protection mechanism, userid
++	 */
++	if (inputlen < 8) {
++	    kstate->authstepno = -1;
++	    return ACTE_FAIL;
++	}
++	des_ecb_encrypt(input, input, kstate->schedule, 0);
++	memcpy(tmp, input, 4);
++	if (ntohl(*(int *)tmp) != kstate->challenge + 1) {
++	    /* Server failed to mutually authenticte */
++	    kstate->authstepno = -1;
++	    return ACTE_FAIL;
++	}	    
++	memcpy(tmp, input+4, 4);
++	maxbufsize = ntohl(*(int *)tmp) & 0xfffff;
++	kstate->protallowed &= input[4];
++	if (maxbufsize <= PROTECTION_OVERHEAD) {
++	    /* Protection buffer too small */
++	    kstate->protallowed &= ACTE_PROT_NONE;
++	}
++#ifndef NOPRIVACY
++	if (kstate->protallowed & ACTE_PROT_PRIVACY) {
++	    kstate->protallowed = ACTE_PROT_PRIVACY;
++	}
++	else
++#endif
++	if (kstate->protallowed & ACTE_PROT_INTEGRITY) {
++	    kstate->protallowed = ACTE_PROT_INTEGRITY;
++	}
++	else if (kstate->protallowed & ACTE_PROT_NONE) {
++	    kstate->protallowed = ACTE_PROT_NONE;
++	}
++	else {
++	    /* No mutually agreeable protection mechanism */
++	    kstate->authstepno = -1;
++	    return ACTE_FAIL;
++	}
++
++	*(int *)authent.dat = htonl(kstate->challenge);
++	*(int *)(authent.dat+4) = htonl(kstate->maxbufsize);
++	authent.dat[4] = kstate->protallowed;
++	strcpy(&authent.dat[8], kstate->user);
++	authent.length = 8+strlen(kstate->user);
++	do {
++	    authent.dat[authent.length++] = '\0';
++	} while (authent.length & 7);
++	des_pcbc_encrypt(authent.dat, authent.dat, authent.length,
++			 kstate->schedule, kstate->session, 1);
++	*output = authent.dat;
++	*outputlen = authent.length;
++	if (maxbufsize < kstate->maxbufsize) kstate->maxbufsize = maxbufsize;
++	return ACTE_DONE;
++
++    default:
++	kstate->authstepno = -1;
++	return ACTE_FAIL;
++    }
++}
++
++/*
++ * Acquire daemon client credentials for 'service'.  Places lifetime
++ * of credentials in seconds in the buffer pointed to by 'lifetime'
++ * Returns error message on failure, NULL on success.
++ */
++static const char *
++krb_new_cred(service, lifetime)
++const char *service;
++time_t *lifetime;
++{
++    static int inited = 0;
++    char hostname[MAXHOSTNAMELEN+1];
++    char instance[MAXHOSTNAMELEN+1];
++    char realm[REALM_SZ];
++    char tktstring[256];
++    int r;
++    CREDENTIALS cr;
++
++    if (!inited++) {
++	sprintf(tktstring, "/tmp/tkt_pid_%d", getpid());
++	krb_set_tkt_string(tktstring);
++    }
++
++    if (krb_get_lrealm(realm,1) != KSUCCESS) {
++	return "cannot get local Kerberos realm";
++    }
++
++    gethostname(hostname, sizeof(hostname));
++    strcpy(instance, krb_get_phost(hostname));
++
++    r = krb_get_svc_in_tkt(service, instance, realm, "krbtgt", realm, 127,
++		       srvtab);
++
++    if (!r) {
++	r = krb_get_cred("krbtgt", realm, realm, &cr);
++	if (!r) *lifetime = cr.lifetime*5*60;
++	memset((char *)&cr, 0, sizeof(cr));
++    }
++
++    if (r) return krb_err_txt[r];
++    return 0;
++}
++    
++static void
++krb_free_cred()
++{
++    dest_tkt();
++}
++
++/* Exported definition of client-side authentication mechanism */
++struct acte_client krb_acte_client = {
++    "KERBEROS_V4",
++    krb_client_start,
++    krb_client_auth,
++    krb_query_state,
++    krb_free_state,
++    krb_new_cred,
++    krb_free_cred,
++};
++
++/*
++ * Start the server side of an authentication exchange
++ */
++static int
++krb_server_start(service, authproc, protallowed, maxbufsize,
++		 localaddr, remoteaddr, outputlen, output, state, reply)
++const char *service;
++acte_authproc_t *authproc;	/* (optional) function to decide
++				 * authoriztion to log in as given user
++				 */
++int protallowed;		/* Protection mechanisms allowed */
++int maxbufsize;			/* Maximum ciphertext input buffer size */
++struct sockaddr *localaddr;	/* Network address of local side */
++struct sockaddr *remoteaddr;	/* Network address of remote side */
++int *outputlen;			/* Set to length of initial reply */
++char **output;			/* Set to point to initial reply data */
++void **state;			/* On success, filled in with state ptr */
++const char **reply;		/* On failure, filled in with ptr to reason */
++{
++    static char outputbuf[4];
++    struct krb_state *kstate;
++
++    protallowed &= ACTE_PROT_NONE|ACTE_PROT_INTEGRITY
++#ifndef NOPRIVACY
++	|ACTE_PROT_PRIVACY
++#endif
++	;
++    if (!localaddr || !remoteaddr) {
++	protallowed &= ACTE_PROT_NONE;
++    }
++    if (!protallowed) {
++	*reply = "No suitable protection mechanism";
++	return ACTE_FAIL;
++    }
++    if (maxbufsize > 0xffffff) maxbufsize = 0xffffff;
++
++    kstate = (struct krb_state *)malloc(sizeof(struct krb_state));
++    if (!kstate) {
++	*reply = "Out of memory";
++	return ACTE_FAIL;
++    }
++    memset((char *)kstate, 0, sizeof(*kstate));
++    strcpy(kstate->service, service);
++    kstate->authstepno = 0;
++    kstate->challenge = time(0) ^ getpid();
++    kstate->protallowed = protallowed;
++    kstate->maxbufsize = maxbufsize;
++    if (localaddr && remoteaddr) {
++	kstate->localaddr = *(struct sockaddr_in *)localaddr;
++	kstate->remoteaddr = *(struct sockaddr_in *)remoteaddr;
++    }
++    kstate->authproc = authproc;
++
++    *(int *)outputbuf = htonl(kstate->challenge);
++    *output = outputbuf;
++    *outputlen = 4;
++    *state = (void *)kstate;
++    
++    return 0;
++}
++
++/*
++ * Perform server-side authentication protocol exchange.
++ * Returns 0 to continue exchange, ACTE_FAIL on failure, and ACTE_DONE
++ * if user is now successfully authenticated
++ */
++static int krb_server_auth(state, inputlen, input, outputlen, output, reply)
++void *state;			/* State of exchange */
++int inputlen;			/* Length of client response */
++char *input;			/* Client response data */
++int *outputlen;			/* Set to length of server reply */
++char **output;			/* Set to point to server reply data */
++const char ** reply;		/* On failure, filled in with ptr to reason */
++{
++    struct krb_state *kstate = (struct krb_state *)state;
++    static char outputbuf[8];
++    KTEXT_ST authent;
++    int code;
++    char tmp[4];
++    char instance[INST_SZ];
++    char realm[REALM_SZ];
++    int protallowed;
++    int maxbufsize;
++    char clientname[MAX_K_NAME_SZ+1];
++
++    switch (kstate->authstepno++) {
++    case 0:
++	/*
++	 * Client gave us ticket+authenticator
++	 * reply with mutual auth + supported protection mechanisms
++	 */
++	if (inputlen > MAX_KTXT_LEN) {
++	    kstate->authstepno = -1;
++	    *reply = "Kerberos authenticator too long";
++	    return ACTE_FAIL;
++	}
++	authent.length = inputlen;
++	memcpy(authent.dat, input, inputlen);
++	authent.mbz = 0;
++	strcpy(instance, "*");
++	code = krb_rd_req(&authent, kstate->service, instance, 0L,
++			  &kstate->kdata, srvtab);
++	if (code) {
++	    kstate->authstepno = -1;
++	    *reply = krb_err_txt[code];
++	    return ACTE_FAIL;
++	}
++	if (kstate->kdata.checksum != kstate->challenge) {
++	    kstate->authstepno = -1;
++	    *reply = "Incorrect checksum in Kerberos authenticator";
++	    return ACTE_FAIL;
++	}
++	memcpy(kstate->session, kstate->kdata.session, sizeof(des_cblock));
++	des_key_sched(kstate->session, kstate->schedule);
++	
++	*(int *)outputbuf = htonl(kstate->challenge+1);
++	*(int *)(outputbuf+4) = htonl(kstate->maxbufsize);
++	outputbuf[4] = kstate->protallowed;
++	des_ecb_encrypt(outputbuf, outputbuf, kstate->schedule, 1);
++	*output = outputbuf;
++	*outputlen = 8;
++
++	return 0;
++
++    case 1:
++	/* Client gave us selected protection mechanism + userid, we're done */
++	if (inputlen < 16 || inputlen & 7) {
++	    kstate->authstepno = -1;
++	    *reply = "Kerberos authenticator has incorrect length";
++	    return ACTE_FAIL;
++	}
++	des_pcbc_encrypt(input, input, inputlen,
++			 kstate->schedule, kstate->session, 0);
++	memcpy(tmp, input, 4);
++	if (ntohl(*(int *)tmp) != kstate->challenge) {
++	    kstate->authstepno = -1;
++	    *reply = "Incorrect checksum in Kerberos authenticator";
++	    return ACTE_FAIL;
++	}
++	memcpy(tmp, input+4, 4);
++	maxbufsize = ntohl(*(int *)tmp) & 0xfffff;
++	if (maxbufsize < kstate->maxbufsize) kstate->maxbufsize = maxbufsize;
++	protallowed = input[4];
++	if (!(protallowed & kstate->protallowed)) {
++	    kstate->authstepno = -1;
++	    *reply = "No suitable protection mechanism selected";
++	    return ACTE_FAIL;
++	}
++	if (
++#ifndef NOPRIVACY
++	    protallowed != ACTE_PROT_PRIVACY &&
++#endif
++	    protallowed != ACTE_PROT_INTEGRITY &&
++	    protallowed != ACTE_PROT_NONE) {
++	    kstate->authstepno = -1;
++	    *reply = "Multiple protection mechanisms selected";
++	    return ACTE_FAIL;
++	}
++	if (protallowed != ACTE_PROT_NONE &&
++	    kstate->maxbufsize <= PROTECTION_OVERHEAD) {
++	    /* Protection buffer too small */
++	    kstate->authstepno = -1;
++	    *reply = "Protection buffer size too small";
++	    return ACTE_FAIL;
++	}
++	kstate->protallowed = protallowed;
++
++	if (input[inputlen-1] != '\0') {
++	    *reply = "User name not nul-terminated";
++	    return ACTE_FAIL;
++	}
++	strcpy(kstate->user, input+8);
++
++	/* Check kerberos identity can log in as user */
++	if (krb_get_lrealm(realm,1)) {
++	    *reply = "Can't find local Kerberos realm";
++	    return ACTE_FAIL;
++	}
++	if (kstate->authproc) {
++	    strcpy(clientname, kstate->kdata.pname);
++	    if (kstate->kdata.pinst[0]) {
++		strcat(clientname, ".");
++		strcat(clientname, kstate->kdata.pinst);
++	    }
++	    if (kstate->kdata.prealm[0]) {
++		strcat(clientname, "@");
++		strcat(clientname, kstate->kdata.prealm);
++	    }
++	    if (kstate->authproc(kstate->user, clientname, reply) != 0) {
++		return ACTE_FAIL;
++	    }
++	}
++	else {
++	    if (strcmp(kstate->kdata.pname, kstate->user) != 0 ||
++		kstate->kdata.pinst[0] ||
++		strcmp(kstate->kdata.prealm, realm) != 0) {
++		*reply = "Kerberos ID does not match user name";
++		return ACTE_FAIL;
++	    }
++	}
++
++	return ACTE_DONE;
++
++    default:
++	*reply = "Internal error: invalid state in krb_server_auth";
++	return ACTE_FAIL;
++    }
++}
++
++/* Exported definition of server-side authentication mechanism */
++struct acte_server krb_acte_server = {
++    "KERBEROS_V4",
++    krb_server_start,
++    krb_server_auth,
++    krb_query_state,
++    krb_free_state,
++    krb_get_cacheid,
++};
++
++/*
++ * Apply integrity protection to the 'inputlen' bytes of data at 'input',
++ * using the state in 'state', placing the output data and length in the
++ * buffers pointed to by 'output' and 'outputlen' respectively.
++ */
++static const char *
++krb_en_integrity(state, input, inputlen, output, outputlen)
++void *state;
++char *input;
++int inputlen;
++char *output;
++int *outputlen;
++{
++    struct krb_state *kstate = (struct krb_state *)state;
++
++    *outputlen = krb_mk_safe(input, output, inputlen, kstate->session,
++			     &kstate->localaddr, &kstate->remoteaddr);
++    return 0;
++}
++
++/*
++ * Decode integrity protection on the 'inputlen' bytes of data at
++ * 'input', using the state in 'state', placing a pointer to the
++ * output data and length in the buffers pointed to by 'output' and
++ * 'outputlen' respectively.
++ */
++static const char *
++krb_de_integrity(state, input, inputlen, output, outputlen)
++void *state;
++char *input;
++int inputlen;
++char **output;
++int *outputlen;
++{
++    struct krb_state *kstate = (struct krb_state *)state;
++    int code;
++    MSG_DAT m_data;
++
++    code = krb_rd_safe(input, inputlen, kstate->session,
++		       &kstate->remoteaddr, &kstate->localaddr, &m_data);
++    if (code) return krb_err_txt[code];
++    if (m_data.time_sec < kstate->prot_time_sec ||
++	(m_data.time_sec == kstate->prot_time_sec &&
++	 m_data.time_5ms < kstate->prot_time_5ms)) {
++	return krb_err_txt[RD_AP_TIME];
++    }
++    kstate->prot_time_sec = m_data.time_sec;
++    kstate->prot_time_5ms = m_data.time_5ms;
++
++    *output = m_data.app_data;
++    *outputlen = m_data.app_length;
++    return 0;
++}
++
++#ifndef NOPRIVACY
++/*
++ * Apply privacy protection to the 'inputlen' bytes of data at 'input',
++ * using the state in 'state', placing the output data and length in the
++ * buffers pointed to by 'output' and 'outputlen' respectively.
++ */
++static const char *
++krb_en_privacy(state, input, inputlen, output, outputlen)
++void *state;
++char *input;
++int inputlen;
++char *output;
++int *outputlen;
++{
++    struct krb_state *kstate = (struct krb_state *)state;
++
++    *outputlen = krb_mk_priv(input, output, inputlen, kstate->schedule,
++			     kstate->session, &kstate->localaddr,
++			     &kstate->remoteaddr);
++    return 0;
++}
++
++/*
++ * Decode privacy protection on the 'inputlen' bytes of data at
++ * 'input', using the state in 'state', placing a pointer to the
++ * output data and length in the buffers pointed to by 'output' and
++ * 'outputlen' respectively.
++ */
++static const char *
++krb_de_privacy(state, input, inputlen, output, outputlen)
++void *state;
++char *input;
++int inputlen;
++char **output;
++int *outputlen;
++{
++    struct krb_state *kstate = (struct krb_state *)state;
++    int code;
++    MSG_DAT m_data;
++
++    code = krb_rd_priv(input, inputlen, kstate->schedule, kstate->session,
++		       &kstate->remoteaddr, &kstate->localaddr, &m_data);
++    if (code) return krb_err_txt[code];
++    if (m_data.time_sec < kstate->prot_time_sec ||
++	(m_data.time_sec == kstate->prot_time_sec &&
++	 m_data.time_5ms < kstate->prot_time_5ms)) {
++	return krb_err_txt[RD_AP_TIME];
++    }
++    kstate->prot_time_sec = m_data.time_sec;
++    kstate->prot_time_5ms = m_data.time_5ms;
++
++    *output = m_data.app_data;
++    *outputlen = m_data.app_length;
++    return 0;
++}
++#endif /* !NOPRIVACY */
++
++/*
++ * Kerberos set srvtab filename
++ * Accepts: name of srvtab file to use in reading authenticators
++ */
++int kerberos_set_srvtab(fname)
++char *fname;
++{
++    srvtab = fname;
++    return 0;
++}
++
++/*
++ * Kerberos get srvtab filename
++ * Returns: name of srvtab file to use in reading authenticators
++ */
++char *kerberos_get_srvtab()
++{
++    return srvtab;
++}
++
++static use_key(user, instance, realm, key, returned_key)
++char *user;
++char *instance;
++char *realm;
++des_cblock key;
++des_cblock returned_key;
++{
++    memcpy (returned_key, key, sizeof(des_cblock));
++    return 0;
++}
++
++/*
++ * Securely verify the plaintext password 'passwd' for user 'user'
++ * against the Kerberos database.  "service" is the name of a service
++ * we can verify the returned ticket against.  Returns 1 for success,
++ * 0 for failure.  On failure, 'reply' is filled in with a pointer to
++ * the reason.
++ */
++int kerberos_verify_password(user, passwd, service, reply)
++char *user;
++char *passwd;
++char *service;
++const char **reply;
++{
++    int result;
++    des_cblock key;
++    char tfname[40];
++    char realm[REALM_SZ];
++    char cell[REALM_SZ];
++    char hostname[MAXHOSTNAMELEN+1];
++    char phost[MAXHOSTNAMELEN+1];
++    KTEXT_ST authent;
++    char instance[INST_SZ];
++    AUTH_DAT kdata;
++
++    if (krb_get_lrealm(realm,1)) return 0;
++
++    sprintf(tfname, "/tmp/tkt_imapd_%d", getpid());
++    krb_set_tkt_string(tfname);
++
++    /* First try Kerberos string-to-key */
++    des_string_to_key(passwd, key);
++    
++    result = krb_get_in_tkt(user, "", realm,
++			    "krbtgt", realm, 1, use_key, NULL, key);
++
++    if (result == INTK_BADPW) {
++	/* Now try andrew string-to-key */
++	strcpy(cell, realm);
++	lcase(cell);
++	afs_string_to_key(passwd, cell, &key);
++    
++	result = krb_get_in_tkt(user, "", realm,
++				"krbtgt", realm, 1, use_key, NULL, key);
++    }
++
++    memset(key, 0, sizeof(key));
++
++    if (result != 0) {
++	dest_tkt();
++	*reply = krb_err_txt[result];
++	return 0;
++    }
++
++    /* Check validity of returned ticket */
++    gethostname(hostname, sizeof(hostname));
++    strcpy(phost, krb_get_phost(hostname));
++    result = krb_mk_req(&authent, service, phost, realm, 0);
++    if (result != 0) {
++	memset(&authent, 0, sizeof(authent));
++	dest_tkt();
++	*reply = krb_err_txt[result];
++	return 0;
++    }
++    strcpy(instance, "*");
++    result = krb_rd_req(&authent, service, instance, 0L, &kdata, srvtab);
++    memset(&authent, 0, sizeof(authent));
++    memset(kdata.session, 0, sizeof(kdata.session));
++    if (result != 0 || strcmp(kdata.pname, user) != 0 || kdata.pinst[0] ||
++	strcmp(kdata.prealm, realm) != 0) {
++	if (result != 0) {
++	    *reply = krb_err_txt[result];
++	}
++	else {
++	    *reply = "Kerberos ID does not match user name";
++	}
++	result = 0;
++    }
++    else result = 1;
++
++    dest_tkt();
++    return result;
++}
+diff -urN pine4.64-hesiod/imap/src/kerberos/auth_krb.c pine4.64-hesiod-krb4/imap/src/kerberos/auth_krb.c
+--- pine4.64/imap/src/kerberos/auth_krb.c	1969-12-31 19:00:00.000000000 -0500
++++ pine4.64L/imap/src/kerberos/auth_krb.c	2003-02-14 17:12:37.000000000 -0500
+@@ -0,0 +1,103 @@
++/*
++ * Program:	Kerberos authenticator
++ *
++ * Author:	Mark Crispin
++ *		Networks and Distributed Computing
++ *		Computing & Communications
++ *		University of Washington
++ *		Administration Building, AG-44
++ *		Seattle, WA  98195
++ *		Internet: MRC@CAC.Washington.EDU
++ *
++ * Date:	1 May 1996
++ * Last Edited:	1 December 1998
++ *
++ * Copyright 1998 by the University of Washington.
++ *
++ *  Permission to use, copy, modify, and distribute this software and its
++ * documentation for any purpose and without fee is hereby granted, provided
++ * that the above copyright notice appears in all copies and that both the
++ * above copyright notice and this permission notice appear in supporting
++ * documentation, and that the name of the University of Washington not be
++ * used in advertising or publicity pertaining to distribution of the software
++ * without specific, written prior permission.  This software is made available
++ * "as is", and
++ * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
++ * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
++ * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
++ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
++ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
++ * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
++ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
++ *
++ */
++
++/* Thanks to Daniel A. Root at CMU who contributed the original version */
++
++#include "acte_krb.c"
++
++long auth_krb_client P((authchallenge_t challenger,authrespond_t responder,
++			char *service,NETMBX *mb,void *stream,unsigned long *trial,
++			char *user));
++char *auth_krb_server P((authresponse_t responder,int argc,char *argv[]));
++
++AUTHENTICATOR auth_krb = {
++  AU_SECURE | AU_AUTHUSER,	/* secure authenticator */
++  "KERBEROS_V4",		/* authenticator name */
++  NIL,				/* always valid */
++  auth_krb_client,		/* client method */
++  NIL,				/* server method */
++  NIL				/* next authenticator */
++};
++
++/* Client authenticator
++ * Accepts: challenger function
++ *	    responder function
++ *	    parsed network mailbox structure
++ *	    stream argument for functions
++ *	    pointer to trial number
++ *	    returned user name
++ * Returns: T if success, NIL otherwise
++ */
++
++long auth_krb_client (challenger,responder,service,mb,stream,trial,user)
++     authchallenge_t challenger;
++     authrespond_t responder;
++     char *service;
++     NETMBX *mb;
++     void *stream;
++     unsigned long *trial;
++     char *user;
++{
++  struct acte_client *mech;
++  void *challenge;
++  char *response;
++  unsigned long clen, rlen;
++  struct krb_state *state;
++  int rc;
++  mech = &krb_acte_client;
++  *trial = 0;			/* don't retry if failure */
++				/* fetch proper service tickets */
++  if (mech->start (service,mb->host,0,ACTE_PROT_NONE,0,0,0,&state,user)) {
++      /* Grab Initial Challenge (note, if this fails, we don't care) */
++      (*challenger)(stream,&clen);
++      /* Cancel authentication */
++      (*responder) (stream,NIL,0);
++      return NIL;
++  }
++				/* get challenge/response */
++  do {				/* until ACTE_DONE or something fails */
++    if (!(challenge = (*challenger) (stream,&clen))) return NIL;
++    rc = mech->auth (state,clen,challenge,&rlen,&response);
++    if (rc == ACTE_FAIL) {
++      /* Cancel authentication */
++      (*responder) (stream,NIL,0);
++      return NIL;
++    }
++    fs_give ((void **) &challenge);
++    if (!((*responder) (stream,response,rlen))) return NIL;
++  } while (rc != ACTE_DONE);
++  mech->free_state (state);	/* clean up */
++  return T;
++}
+diff -urN pine4.64-hesiod/imap/src/kerberos/ckp_krb.c pine4.64-hesiod-krb4/imap/src/kerberos/ckp_krb.c
+--- pine4.64/imap/src/kerberos/ckp_krb.c	1969-12-31 19:00:00.000000000 -0500
++++ pine4.64L/imap/src/kerberos/ckp_krb.c	2001-02-19 03:03:12.000000000 -0500
+@@ -0,0 +1,53 @@
++/*
++ * Program:	Kerberos check password
++ *
++ * Author:	Mark Crispin
++ *		Networks and Distributed Computing
++ *		Computing & Communications
++ *		University of Washington
++ *		Administration Building, AG-44
++ *		Seattle, WA  98195
++ *		Internet: MRC@CAC.Washington.EDU
++ *
++ * Date:	1 August 1988
++ * Last Edited:	1 December 1998
++ *
++ * Copyright 1998 by the University of Washington
++ *
++ *  Permission to use, copy, modify, and distribute this software and its
++ * documentation for any purpose and without fee is hereby granted, provided
++ * that the above copyright notice appears in all copies and that both the
++ * above copyright notice and this permission notice appear in supporting
++ * documentation, and that the name of the University of Washington not be
++ * used in advertising or publicity pertaining to distribution of the software
++ * without specific, written prior permission.  This software is made available
++ * "as is", and
++ * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
++ * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
++ * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
++ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
++ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
++ * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
++ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
++ *
++ */
++
++/* Check password
++ * Accepts: login passwd struct
++ *	    password string
++ *	    argument count
++ *	    argument vector
++ * Returns: passwd struct if password validated, NIL otherwise
++ */
++
++struct passwd *checkpw (pw,pass,argc,argv[])
++     struct passwd *pw;
++     char *pass;
++     int argc;
++     char *argv[];
++{
++  char *reply;
++  return kerberos_verify_password (pw->pw_name,pass,"imap",&reply) ? pw : NIL;
++}
++
+diff -urN pine4.64-hesiod/imap/src/kerberos/Makefile.krb pine4.64-hesiod-krb4/imap/src/kerberos/Makefile.krb
+--- pine4.64/imap/src/kerberos/Makefile.krb	1969-12-31 19:00:00.000000000 -0500
++++ pine4.64L/imap/src/kerberos/Makefile.krb	2003-02-15 15:45:13.000000000 -0500
+@@ -0,0 +1,41 @@
++# Program:	Kerberos IV makefile
++#
++# Author:	Mark Crispin
++#		Networks and Distributed Computing
++#		Computing & Communications
++#		University of Washington
++#		Administration Building, AG-44
++#		Seattle, WA  98195
++#		Internet: MRC@CAC.Washington.EDU
++#
++# Date:		11 May 1989
++# Last Edited:	13 October 1998
++#
++# Copyright 1998 by the University of Washington
++#
++#  Permission to use, copy, modify, and distribute this software and its
++# documentation for any purpose and without fee is hereby granted, provided
++# that the above copyright notice appears in all copies and that both the
++# above copyright notice and this permission notice appear in supporting
++# documentation, and that the name of the University of Washington not be
++# used in advertising or publicity pertaining to distribution of the software
++# without specific, written prior permission.  This software is made
++# available "as is", and
++# THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
++# WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
++# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
++# NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
++# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
++# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
++# (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
++# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
++
++
++# Extended flags needed for additional authenticators.  You may need to modify.
++
++KRBCFLAGS= -DHAVE_KRB_GET_PHOST -DHAVE_KRB_REALMOFHOST
++KRBLDFLAGS= -lkrb4 -ldes425 -lkrb5 -lk5crypto -lcom_err
++
++krb:	# Kerberos IV flags
++	echo $(KRBCFLAGS) >> OSCFLAGS
++	echo $(KRBLDFLAGS) >> LDFLAGS
+diff -urN pine4.64-hesiod/imap/src/kerberos/README pine4.64-hesiod-krb4/imap/src/kerberos/README
+--- pine4.64/imap/src/kerberos/README	1969-12-31 19:00:00.000000000 -0500
++++ pine4.64L/imap/src/kerberos/README	2001-02-19 03:03:13.000000000 -0500
+@@ -0,0 +1,26 @@
++		       Kerberos 4 IMAP Patchkit
++			   1 December 1998
++			     Mark Crispin
++
++     The Kerberos 4 IMAP patchkit consists of a set of modules and
++patches to the IMAP toolkit to enable Kerberos 4 client-only support
++in c-client.  There is server support.
++
++     This patchkit is completely unsupported.  Use it at your own
++risk.
++
++     To build the IMAP tookit with the Kerberos 4 IMAP patchkit, move
++the entire contents of the kerberos/ directory into
++imap-4.???/src/kerberos, then do a make command with krb listed as one
++of the EXTRAAUTHENTICATORS.
++
++     For example, assuming that you just obtained imap-4.5.tar.Z and
++this kerberos4-patches.tar.Z distribution and desire to build on a
++Digital UNIX 4.0 system.  You would follow a procedure somewhat like
++this:
++	% zcat imap-4.5.tar.Z | tar xf -
++	% zcat kerberos4-patches.tar.Z | tar xf -
++	% mv kerberos imap-4.5/src
++	% cd imap-4.5
++	% make os4 EXTRAAUTHENTICATORS=krb
++
+diff -urN pine4.64-hesiod/imap/src/osdep/unix/tcp_unix.c pine4.64-hesiod-krb4/imap/src/osdep/unix/tcp_unix.c
+--- pine4.64/imap/src/osdep/unix/tcp_unix.c	2005-08-16 16:56:14.000000000 -0400
++++ pine4.64L/imap/src/osdep/unix/tcp_unix.c	2006-10-17 14:24:14.000000000 -0400
+@@ -272,6 +272,20 @@
+ 	now = time (0);		/* fake timeout if interrupt & time expired */
+ 	if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
+       } while ((i < 0) && (errno == EINTR));
++#ifdef KERBEROS
++      if (port == 1109 && i > 0) {
++	/* For kpop, we have to send kerberos authentication before we
++	 * can read anything.  So we have to do it here instead of in
++	 * the pop3 code. */
++	KTEXT_ST ticket;
++
++	if (krb_sendauth (0,sock,&ticket,"pop",hst,krb_realmofhost (hst),
++			  0,NULL,NULL,NULL,NULL,NULL,"KPOPV0.1") != KSUCCESS) {
++	  close (sock);
++	  return -1;		/* failure */
++	}
++      }
++#endif  
+       if (i > 0) {		/* success, make sure really connected */
+ 				/* restore blocking status */
+ 	fcntl (sock,F_SETFL,flgs);
--- pine-4.64.orig/debian/patches/pine-slx-include.patch
+++ pine-4.64/debian/patches/pine-slx-include.patch
@@ -0,0 +1,11 @@
+diff -ur pine4.64-hesiod/imap/src/osdep/unix/os_slx.h pine4.64-hesiod-krb4/imap/src/osdep/unix/os_slx.h
+--- pine4.64/imap/src/osdep/unix/os_slx.h	2005-04-20 20:49:42.000000000 -0400
++++ pine4.64L/imap/src/osdep/unix/os_slx.h	2006-10-17 14:24:14.000000000 -0400
+@@ -41,6 +41,7 @@
+ #include <fcntl.h>
+ #include <syslog.h>
+ #include <sys/file.h>
++#include <time.h>
+ 
+ 
+ /* Linux gets this wrong */
--- pine-4.64.orig/debian/patches/pine-version-4.64L.patch
+++ pine-4.64/debian/patches/pine-version-4.64L.patch
@@ -0,0 +1,21 @@
+diff -urN pine4.64/doc/pine.1 pine4.64L/doc/pine.1
+--- pine4.64/doc/pine.1	2005-09-15 17:01:32.000000000 -0400
++++ pine4.64L/doc/pine.1	2006-10-17 14:24:12.000000000 -0400
+@@ -1,4 +1,4 @@
+-.TH pine 1 "Version 4.64"
++.TH pine 1 "Version 4.64L"
+ .SH NAME
+ pine \- a Program for Internet News and Email
+ .SH SYNTAX 
+diff -urN pine4.64/pine/pine.h pine4.64L/pine/pine.h
+--- pine4.64/pine/pine.h	2005-09-15 20:39:42.000000000 -0400
++++ pine4.64L/pine/pine.h	2006-10-17 14:24:16.000000000 -0400
+@@ -63,7 +63,7 @@
+ #ifndef _PINE_INCLUDED
+ #define _PINE_INCLUDED
+ 
+-#define PINE_VERSION		"4.64"
++#define PINE_VERSION		"4.64L"
+ #define	PHONE_HOME_VERSION	"-count"
+ #define	PHONE_HOME_HOST		"docserver.cac.washington.edu"
+ 
--- pine-4.64.orig/debian/patches/series
+++ pine-4.64/debian/patches/series
@@ -0,0 +1,5 @@
+pine-version-4.64L.patch
+pine-hesiod.patch
+pine-krb4.patch
+pine-creatdir-afs.patch
+pine-athena-inbox-hack.patch
--- pine-4.64.orig/debian/BUGS.Debian
+++ pine-4.64/debian/BUGS.Debian
@@ -0,0 +1,17 @@
+Many people say that using base64 encoding for text attachments is a bug.
+
+We have asked Pine developers about this and they said that the
+highest priority for any attachment is that a MIME tool can recover
+_exactly_ what was attached. They found that it was not possible to have
+any reasonable assurance of getting a text attachment through intact
+without BASE64 encoding. Therefore, they consider BASE64 encoding a
+feature, not a bug, and do not plan to change Pine in this regard.
+
+In addition to this, any file may be included using Control-R, and
+lack of MIME-aware software is hopefully a short-lived problem.
+
+This is even more true in year 2000 so I've decided that this
+does not worth a wishlist bug anymore.
+
+
+Santiago Vila <sanvila@debian.org>
--- pine-4.64.orig/debian/changelog
+++ pine-4.64/debian/changelog
@@ -0,0 +1,517 @@
+pine (4.64-3debathena1) unstable; urgency=low
+
+  * Add Athena patches for Hesiod and Kerberos IV support.
+  * Configure pine to send outgoing mail using debathena-msmtp.
+
+ -- Anders Kaseorg <andersk@mit.edu>  Tue, 26 Jun 2007 16:46:29 -0400
+
+pine (4.64-3) unstable; urgency=medium
+
+  * Use debconf to announce new versions. Closes: #213260.
+  * Use debconf to configure /etc/mailname and /etc/news/server.
+    Thanks a lot to Tim Cutts. Closes: #292528.
+
+ -- Santiago Vila <sanvila@debian.org>  Mon, 18 Dec 2006 18:06:32 +0100
+
+pine (4.64-2) unstable; urgency=low
+
+  * Added Suggests: ca-certificates, as this package has SSL support.
+  * Changed pine/mailindx.c to show mail sizes in traditional form.
+
+ -- Santiago Vila <sanvila@debian.org>  Fri,  8 Dec 2006 18:01:54 +0100
+
+pine (4.64-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Santiago Vila <sanvila@debian.org>  Wed,  5 Oct 2005 18:46:34 +0200
+
+pine (4.63-1) unstable; urgency=low
+
+  * New upstream release (Closes: #316042).
+  * Moved menu file to /usr/share/menu.
+
+ -- Santiago Vila <sanvila@debian.org>  Thu, 14 Jul 2005 14:50:56 +0200
+
+pine (4.62-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Santiago Vila <sanvila@debian.org>  Sat, 22 Jan 2005 18:28:04 +0100
+
+pine (4.61-1) unstable; urgency=low
+
+  * New upstream release (Closes: #253155).
+  * Should fix problem with enable-aggregate-command-set (Closes: #240048).
+
+ -- Santiago Vila <sanvila@debian.org>  Thu, 12 Aug 2004 19:35:16 +0200
+
+pine (4.58-1) unstable; urgency=medium
+
+  * New upstream release. Fixes potential security problems caused
+    by maliciously-formed RFC 2231 attachment parameters.
+
+ -- Santiago Vila <sanvila@debian.org>  Thu, 18 Sep 2003 19:30:06 +0200
+
+pine (4.56-2) unstable; urgency=medium
+
+  * Removed "disclaimer", obsolete since version 3.96L-6.
+  * Removed debian/README.old, obsoleted by copyright and changelog.
+  * Use debian/<package> instead of debian/tmp to allow parallel builds.
+  * Fixed DEB_BUILD_OPTIONS handling, it didn't work for c-client.
+  * Modified imap/src/c-client/mail.c to fix a segfault problem.
+    Patch by Mark Crispin.
+
+ -- Santiago Vila <sanvila@debian.org>  Wed, 10 Sep 2003 15:58:28 +0200
+
+pine (4.56-1) unstable; urgency=low
+
+  * New upstream release.
+  * Removed potato-patch.
+  * Removed pico support.
+
+ -- Santiago Vila <sanvila@debian.org>  Thu,  4 Sep 2003 19:36:04 +0200
+
+pine (4.44-9) unstable; urgency=low
+
+  * Downgrade pico to extra so that nano, which is optional, may include
+    a pico -> nano symlink and conflict with pico (Closes: #202636).
+  * I hereby declare pico as "unsupported". Use nano instead.
+  * By default, pico.deb will not be generated from source anymore.
+    If you feel nostalgic you can still "debian/rules binary-pico" for now.
+
+ -- Santiago Vila <sanvila@debian.org>  Fri,  1 Aug 2003 16:25:24 +0200
+
+pine (4.44-8) unstable; urgency=medium
+
+  * Added README.maildir to /usr/share/doc/pine (Closes: #193649).
+  * Updated adrbkcmd.c so that it works with OpenLDAP 2.1 (Closes: #194217).
+
+ -- Santiago Vila <sanvila@debian.org>  Sun, 25 May 2003 14:11:06 +0200
+
+pine (4.44-7) unstable; urgency=medium
+
+  * Use EXTRALDFLAGS="-lcrypt" so that it builds using the most recent
+    libssl-dev package (Closes: #182856).
+
+ -- Santiago Vila <sanvila@debian.org>  Sun,  2 Mar 2003 21:52:00 +0100
+
+pine (4.44-6) unstable; urgency=high
+
+  * Patched bldaddr.c to fix a buffer overflow problem. A fully legal
+    email message with a crafted From: header can make pine to segfault
+    on startup (Closes: #172887).
+
+ -- Santiago Vila <sanvila@debian.org>  Fri, 13 Dec 2002 16:45:56 +0100
+
+pine (4.44-5) unstable; urgency=low
+
+  * README.pine-tracker now points to sources.list(5). Closes: #148261.
+  * pine-tracker now Enhances: pine. Closes: #158758.
+  * Standards-Version: 3.5.7.
+
+ -- Santiago Vila <sanvila@debian.org>  Wed, 25 Sep 2002 00:04:20 +0200
+
+pine (4.44-4) unstable; urgency=low
+
+  * Updated maildir.c so that uses mail_status_default instead of NIL
+    for the "status of mailbox". Should fix a segfault problem.
+    Closes: #142972. Patch by Dean Gaudet.
+  * Put X- in front of Delivered-To and Mailing-List headers when a message
+    is bounced, as it's already done for Received headers. Some programs
+    complained about them. Closes: #142973. Patch by Dean Gaudet.
+
+ -- Santiago Vila <sanvila@debian.org>  Wed, 17 Apr 2002 17:10:02 +0200
+
+pine (4.44-3) unstable; urgency=low
+
+  * Updated smtp.c from upstream. TLS should now work (Closes: #137312).
+
+ -- Santiago Vila <sanvila@debian.org>  Sun, 10 Mar 2002 15:07:36 +0100
+
+pine (4.44-2) unstable; urgency=medium
+
+  * This release should compile under potato (Closes: #131520).
+
+ -- Santiago Vila <sanvila@debian.org>  Fri,  1 Feb 2002 17:38:26 +0100
+
+pine (4.44-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Santiago Vila <sanvila@debian.org>  Thu, 10 Jan 2002 16:31:26 +0100
+
+pine (4.43-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Santiago Vila <sanvila@debian.org>  Thu, 29 Nov 2001 16:00:02 +0100
+
+pine (4.42-1) unstable; urgency=low
+
+  * New upstream release. Should fix the following bugs:
+  - pine and pico segfault on large resolutions, closes: #76473, #81375.
+  - pine doesn't scan for new email when INBOX is empty, closes: #117111.
+  - debian/rules clean does not remove ipopd, closes: #117314.
+  * Added support for DEB_BUILD_OPTIONS.
+
+ -- Santiago Vila <sanvila@debian.org>  Thu, 22 Nov 2001 17:47:24 +0100
+
+pine (4.40-2) unstable; urgency=low
+
+  * Improved pine-tracker README (Closes: #117031).
+  * Use the old Maildir code again, the new code had undesired side effects.
+    Closes: #115499, #116021.
+
+ -- Santiago Vila <sanvila@debian.org>  Fri, 26 Oct 2001 19:13:44 +0200
+
+pine (4.40-1) unstable; urgency=low
+
+  * New upstream release.
+  * Applied new Maildir patch from Miquel van Smoorenburg, Maildir folders
+    should now sort properly 10^9 seconds after 1970 (Closes: #111818).
+  * pine-tracker now tells the user to make sure there are source URIs
+    in /etc/apt/sources.list before using apt-get source (Closes: #113180).
+
+ -- Santiago Vila <sanvila@debian.org>  Sun, 30 Sep 2001 12:40:01 +0200
+
+pine (4.33-5) unstable; urgency=high
+
+  * Fixed update-alternatives invocation in postinst.pico, should be
+    FHS-compliant now (Closes: #105289).
+
+ -- Santiago Vila <sanvila@debian.org>  Sat, 18 Aug 2001 17:46:58 +0200
+
+pine (4.33-4) unstable; urgency=low
+
+  * Build-Depends: libncurses5-dev, libldap2-dev, libssl-dev.
+  * Modified the pine-tracker recipe so that apt-get --only-source is used.
+    Thanks to Paul Johnson for the report (Closes: #103967).
+  * Make sure dotlock_lock() in env_unix.c always drops set-gid privileges
+    before returning. Reported by John Jorgensen.
+
+ -- Santiago Vila <sanvila@debian.org>  Mon,  9 Jul 2001 16:45:32 +0200
+
+pine (4.33-3) unstable; urgency=low
+
+  * The mail spool directory is now /var/mail.
+  * Slightly rewritten no-distribution notice.
+  * Changed some docs to reflect FHS locations.
+  * Added manpage symlink for the `pinef' binary.
+  * Modified term.inf for Home and End keys to work again.
+  * README.pine4, now README, refers to the invisible message feature.
+  * Removed suidmanager support and Conflicts: suidmanager (<< 0.50).
+  * Allow messages to be saved to existing Maildir folders.
+    Patch by Piotr Roszatycki (Closes: #90951).
+  * Created a pine-tracker binary package (Closes: #100655).
+    Suggested by Joey Hess.
+
+ -- Santiago Vila <sanvila@debian.org>  Tue,  3 Jul 2001 19:53:14 +0200
+
+pine (4.33-2) unstable; urgency=high
+
+  * Added #include <time.h> to os_slx.h to make glibc-2.2 happy.
+    Closes: #87421.
+
+ -- Santiago Vila <sanvila@debian.org>  Tue, 27 Feb 2001 19:14:35 +0100
+
+pine (4.33-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Santiago Vila <sanvila@debian.org>  Fri,  2 Feb 2001 16:45:24 +0100
+
+pine (4.32-2) unstable; urgency=low
+
+  * Added SSL support (Closes: #78833). Updated Build-Depends.
+    Thanks to Tomas Pospisek and Cristian Ionescu-Idbohrn for the help.
+
+ -- Santiago Vila <sanvila@debian.org>  Mon, 29 Jan 2001 19:08:09 +0100
+
+pine (4.32-1) unstable; urgency=medium
+
+  * New upstream release.
+  * Added LDAP support (Closes: #74915). Updated Build-Depends.
+  * Fixed temporary file hijacking vulnerability (Closes: #79363).
+
+ -- Santiago Vila <sanvila@debian.org>  Thu, 18 Jan 2001 17:30:02 +0100
+
+pine (4.31-1) unstable; urgency=low
+
+  * New upstream release.
+
+ -- Santiago Vila <sanvila@debian.org>  Thu,  7 Dec 2000 20:06:00 +0100
+
+pine (4.30-1) unstable; urgency=low
+
+  * New upstream release.
+  * Renamed source back to "pine".
+  * postrm now uses suidmanager to unregister pine (Bug #76172).
+
+ -- Santiago Vila <sanvila@debian.org>  Thu, 16 Nov 2000 18:24:36 +0100
+
+pine4 (4.21-3) unstable; urgency=low
+
+  * Replaced include(fgetpos.non) by include(fgetpos) in pine/osdep/os-lnx.ic
+    since the former is no longer allowed by glibc-2.2.
+
+ -- Santiago Vila <sanvila@debian.org>  Wed, 11 Oct 2000 17:27:38 +0200
+
+pine4 (4.21-2) unstable; urgency=low
+
+  * Standards-Version: 3.1.1.
+  * Build-Depends: libncurses-dev.
+  * Modified the `build' script so that a compilation error actually stops
+    the build process (Bug #69096).
+
+ -- Santiago Vila <sanvila@debian.org>  Tue, 29 Aug 2000 20:17:40 +0200
+
+pine4 (4.21-1) unstable; urgency=low
+
+  * New upstream release, uploaded as `pine4' for the source name.
+  * Added a README.pine4 in the doc directory.
+
+ -- Santiago Vila <sanvila@ctv.es>  Fri, 14 Jan 2000 12:39:33 +0100
+
+pine (3.96M-5) unstable; urgency=low
+
+  * Use iso-8859-1 as a better default for the character set,
+    following a suggestion by Thomas Quinot.
+  * Updated BUGS.Debian.
+
+ -- Santiago Vila <sanvila@ctv.es>  Thu, 13 Jan 2000 20:08:24 +0100
+
+pine (3.96M-4) unstable; urgency=low
+
+  * Added real section in Section: field (Bug #40206).
+  * Removed mailcap.unx from doc directory.
+
+ -- Santiago Vila <sanvila@ctv.es>  Mon,  5 Jul 1999 20:03:04 +0200
+
+pine (3.96M-3) unstable; urgency=low
+
+  * pine and pico now Suggests: spell (Bug #34634).
+
+ -- Santiago Vila <sanvila@ctv.es>  Sat,  3 Apr 1999 13:03:52 +0200
+
+pine (3.96M-2) frozen unstable; urgency=medium
+
+  * c-client: mtx.c and tenex2.c: changed %hx to %lx and cast to long,
+    as is already done in env_unix.c. Reported by David Luyer.
+  * Removed -Wall from CFLAGS, since it generates some confusion among
+    people who have to compile this for the first time.
+
+ -- Santiago Vila <sanvila@ctv.es>  Thu, 28 Jan 1999 13:54:54 +0100
+
+pine (3.96M-1) frozen unstable; urgency=low
+
+  * Pristine source.
+  * Looks for rimapd in /usr/sbin instead of /etc.
+  * Added a "M" instead of an "L" to the version number.
+    (L was for "Local", M is for "Modified").
+
+ -- Santiago Vila <sanvila@ctv.es>  Thu, 30 Apr 1998 17:51:27 +0200
+
+pine (3.96L-7) unstable; urgency=high
+
+  * Applied patch from Erik Troan to fix the external editor problem.
+  * Added copyright file for pine-tech-notes.
+
+ -- Santiago Vila <sanvila@ctv.es>  Sat,  7 Mar 1998 18:43:27 +0100
+
+pine (3.96L-6) unstable; urgency=high
+
+  * Fixed Bug #17378. Pine now drops setgid mail privileges and restore
+    them only for locking. Patch by Ilya Ovchinnikov.
+  * Fixed Bug #15188 (same lock file for different mailboxes).
+    Patch by Ilya Ovchinnikov.
+  * Fixed Bug #17435. Files in /tmp are now created 600, not 666.
+  * menu entries for pine and pico.
+
+ -- Santiago Vila <sanvila@ctv.es>  Sat, 31 Jan 1998 12:43:33 +0100
+
+pine (3.96L-5) unstable; urgency=low
+
+  * Patched to recognize SIGWINCH signal (thanks to Mark Baker).
+  * Implemented new editor policy for pico.
+  * debian/rules: postinst and postrm installed by install -m 755.
+  * Removed bashisms everywhere.
+  * gzipped changelog.Debian.
+
+ -- Santiago Vila <sanvila@ctv.es>  Tue, 18 Nov 1997 18:49:38 +0100
+
+pine (3.96L-4) unstable; urgency=low
+
+  * Added Maildir support by Eric Green.
+  * Added -lcrypt to compile under libc6.
+  * Added md5sums.
+
+ -- Santiago Vila <sanvila@ctv.es>  Wed, 22 Oct 1997 12:09:27 +0200
+
+pine (3.96L-3) unstable; urgency=low
+
+  * Source-only release, license says modified binaries like this
+    are not allowed to be distributed.
+  * Added /usr/doc/pine/BUGS.Debian explaining the base64 bug|feature.
+  * pine is now setgid mail and has suidmanager support.
+  * Simplified debian/rules a little bit.
+  * Added pinef -> pine symlink.
+  * New `pilot' package.
+
+ -- Santiago Vila <sanvila@ctv.es>  Sat, 26 Jul 1997 18:30:21 +0200
+
+pine (3.96L-2) unstable; urgency=low
+
+  * Use "Path: not-for-mail" according to `son-of-1036' for NNTP postings.
+  * Patched a lot of files (including pine man page) to reflect that
+    config files are in /etc and mail spool is /var/spool/mail.
+  * Now local info is in /etc/pine.info.
+  * Some patches to be libc6-ready.
+  * _Really_ use TERMINFO and not TERMCAP. Now "Home" and "End" keys work.
+  * Removed /etc/pine.conf and /etc/pine.conf.fixed and simplified
+    pine postinst. If /etc/pine.conf does not exist, it is created
+    using "pine -conf". Don't touch it if it already exists.
+  * postrm removes /etc/pine.{conf,conf.fixed,info} when purging.
+
+ -- Santiago Vila <sanvila@ctv.es>  Sat, 29 Mar 1997 14:01:06 +0100
+
+pine (3.96L-1) unstable; urgency=low
+
+  * Rewritten copyright, now is generated from the "CPYRIGHT" source file.
+  * Moved all Debian-specific files from ./doc to ./debian (source).
+  * Moved debian.README to debian/README.old (source).
+  * Removed Getting_Started and SecretsOfPine-3.9.
+    Instead, there will be a pine-docs package with sources taken
+    from ftp://ftp.cac.washington.edu/pine/docs.
+  * Moved "technical notes" into a separate `pine-tech-notes' package,
+    using HTML files in directory ./pine-3.96L/doc/tech-notes.
+  * Uncompressed remaining docs, since they are not too big.
+  * Distribution unstable, Section non-free.
+  * Improved debian/rules clean target.
+  * c-client.a also compiled using -O2.
+  * Compressed manpages.
+  * New maintainer.
+
+ -- Santiago Vila <sanvila@ctv.es>  Tue, 25 Mar 1997 18:59:08 +0100
+
+pine (3.96L-0) non-free; urgency=low
+
+  * Latest Upstream Release
+
+ -- Daniel Stringfield <servo@southeast.net>  Mon, 10 Mar 1997 00:39:48 -0500
+
+pine (3.95L-7) non-free; urgency=low
+
+  * Removed .orig files caused by patching done in -5, closing bug#6869
+
+ -- Daniel Stringfield <servo@southeast.net>  Wed, 29 Jan 1997 22:46:08 -0500
+
+pine (3.95L-6) non-free; urgency=low
+
+  * Fixed postinst to not crash on zero byte /etc/news/server file
+  * Changed wording from "popclient" to "fetchmail" in description
+  * Changed compile options to "-O2 -g -Wall" and removed -DDEBUG
+
+ -- Daniel Stringfield <servo@southeast.net>  Fri, 24 Jan 1997 12:32:44 -0500
+
+pine (3.95L-5) non-free; urgency=low
+
+  * Patched source with "pine-patch-1" from ftp.cac.washington.edu
+
+ -- Daniel Stringfield <servo@southeast.net>  Wed, 22 Jan 1997 18:42:13 -0500
+
+pine (3.95L-4) non-free; urgency=low
+
+  * Included a fixed postinst script to deal with comments in /etc/news/server
+  * Added disclaimer for setgid mail
+
+ -- Daniel Stringfield <servo@southeast.net>  Sun, 29 Dec 1996 14:39:46 -0500
+
+pine (3.95L-3) non-free; urgency=low
+
+  * removed imapd from the pine package (now supplied as imap-4)
+
+ -- Dale Scheetz <dwarf@polaris.net>  Wed, 4 Dec 1996 11:35:59 -0500
+
+pine (3.95L-2) non-free; urgency=low
+
+  * compressed files in /usr/doc/pine
+
+ -- Dale Scheetz <dwarf@polaris.net>  Tue, 15 Oct 1996 11:24:01 -0400
+
+pine (3.95L-1) non-free; urgency=low
+
+  * corrected passwd path
+  * edited pine.conf path
+  * enabled From: configuration
+  * Standards-Version: 2.1.0.0
+
+ -- Dale Scheetz <dwarf@polaris.net>  Tue, 17 Sep 1996 19:55:31 -0400
+
+Tue June 2, 1996 Dale Scheetz <dwarf@polaris.net>
+
+	* Removed imapd from recommends
+	* Moved mail-delivery-agent to suggests
+
+Mon June 17,1996 Dale Scheetz <dwarf@polaris.net>
+
+	* Upgraded to 3.94 source
+	* Added necessary changes (pine.conf path)
+
+Mon May 20 1996 Dale Scheetz <dwarf@polaris.net>
+
+	* Fixed path to pine.conf
+	* Placed new CPYRIGHT file into copyright
+
+ April 22 1996 Dale Scheetz <dwarf@polaris.net>
+
+	* Upgraded source to 3.93
+	* Added architecture stuff
+
+Thu Feb 29 1996 Dale Scheetz <dwarf@polaris.net>
+	
+	* Made corrections to installation postinst script
+	* Added 'Source: pine-3.91' to pico control file
+
+Sat Feb 10 1995 Dale Scheetz <dwarf@polaris.net>
+
+	* Fixed debian.rules (see debian.README)
+	* Added pine.conf and pine.conf.fixed files back into package
+	* Docs now include SecretsOfPine-3.9 as one of the doc files.
+	* Changed dependancies to libc5 and ncurses3.0
+	* Reduced mail-delivery-agent to a suggestion
+
+Sat May 13 12:09:29 1995  Ted Hajek  <tedhajek@all-blues.micro.umn.edu>
+
+	* debian.control.pine: Added verbose description.  Changed package
+	revision number to three.
+
+	* Added "/etc/pine.conf" and "/etc/pine.conf.fixed" to the list of
+	configuration files.
+
+	* debian.postinst: added post-installation script to obtain
+	mail-name from /etc/mailname or to create /etc/mailname if
+	necessary.  The mailname is assigned to the "user-domain" variable
+	in /etc/pine.conf if the mailname differs from the local hostname.
+	This repairs bug #686
+
+	* pine/osdep/os-lnx.h (PASSWD_PROG): Changed from /bin/passwd to
+	/usr/bin/passwd.  This solves bug #776
+
+	* debian.control.pine (DEPENDS): removed `netbase' from list of
+	dependencies.  We don't need netbase to deal with local mail.
+	This solves bug #694.
+
+Sun Dec 18 23:17:46 1994  Ted Hajek  <tedhajek@all-blues.micro.umn.edu>
+
+	* debian.rules (binary): changed call to 'dpkg-util.deb' to
+	'dpkg'.
+
+	(source): created variables to hold version and package revision
+	numbers so I only have to type them once when things change.
+
+	* debian.control.pine (PACKAGE_REVISION): changed to package
+	revision number 2.
+
+	(DEPENDS): Removed parentheses in order to correct bug number 251.
+	Dpkg didn't like extraneous parentheses.
--- pine-4.64.orig/debian/config
+++ pine-4.64/debian/config
@@ -0,0 +1,48 @@
+#!/bin/sh -e
+
+. /usr/share/debconf/confmodule
+db_version 2.0
+
+# The following debconf magic comes from the slrn package
+
+db_beginblock
+
+if [ ! -s /etc/news/server ]; then
+  # No news server file currently exists (or it's empty).
+  db_get shared/news/server
+  SERVER="$RET"
+  # If there is no server set, try to guess a good value.
+  if [ -z "$SERVER" ]; then
+    NETNAME="`hostname -d`" || true
+    if [ ! -z "$NETNAME" ]; then
+      db_set shared/news/server "news.$NETNAME"
+    fi
+  fi
+else
+  # Reconfiguring the package, or a news server file already exists.
+  # Still ask the question, though it may or may not be seen. Just
+  # use the first line of the file now as the default answer.
+  db_set shared/news/server "`head -n 1 /etc/news/server`"
+  # Effectively, the question is seen -- since the file is set up..
+  db_fset shared/news/server seen true
+fi
+db_input medium shared/news/server || true
+
+if [ ! -s /etc/mailname ]; then
+  # No /etc/mailname file, or it's empty, so prompt for the mailname.
+  db_get shared/mailname
+  MAILNAME="$RET"
+  if [ -z "$MAILNAME" ]; then
+    db_set shared/mailname "`hostname --fqdn`" || db_set shared/mailname "`hostname`"
+  fi
+else
+  # Reconfiguring the package, or a mailname file already exists.
+  # Still ask the question, though it may not be seen. Just use the
+  # first line of the file now as the default answer.
+  db_set shared/mailname "`head -n 1 /etc/mailname`"
+  # Effectively, the question is seen -- since the file is set up..
+  db_fset shared/mailname seen true
+fi
+db_input medium shared/mailname || true
+db_endblock
+db_go || true
--- pine-4.64.orig/debian/control
+++ pine-4.64/debian/control
@@ -0,0 +1,58 @@
+Source: pine
+Section: non-free/mail
+Priority: optional
+Maintainer: Santiago Vila <sanvila@debian.org>
+Standards-Version: 3.7.2
+Build-Depends: libncurses5-dev, libldap2-dev, libssl-dev, quilt, libhesiod-dev, libkrb5-dev
+
+Package: pine
+Architecture: any
+Depends: ${shlibs:Depends}, mime-support, debconf | debconf-2.0, debathena-msmtp-config
+Suggests: mail-transport-agent, spell, ca-certificates
+Provides: mail-reader, debathena-pine
+Conflicts: suidmanager (<< 0.50)
+Description: An e-mail reader with MIME and IMAP support
+ Pine is a mail-user-agent that provides features for viewing e-mail.
+ .
+ Some form of mail-transport-agent is desirable for obtaining mail. However
+ fetchmail is sufficient in some cases to deal with the delivery. There are
+ several mail-transport-agents available, including smail, sendmail and others.
+ .
+ Pine needs no mail-transport-agent for sending mail, as it provides SMTP for
+ this purpose.
+ .
+ In addition to mail viewing, Pine provides features for viewing and creating
+ news group postings.
+
+Package: pilot
+Section: non-free/utils
+Priority: optional
+Architecture: any
+Depends: ${shlibs:Depends}
+Description: simple file system browser in the style of the Pine Composer
+ Pilot is a simple, display-oriented file system browser based on
+ the Pine message system composer.  As with Pine, commands are
+ displayed at the bottom of the screen, and context-sensitive
+ help is provided.
+
+Package: pine-tracker
+Section: non-free/admin
+Depends: debconf | debconf-2.0
+Enhances: pine
+Priority: optional
+Architecture: all
+Description: Tracks pine uploads
+ This package warns you about outdated pine packages in your system.
+ It compares its own version against the installed version of pine, etc.
+ and suggests the user to update those packages if old packages are found.
+
+Package: pine-tech-notes
+Section: non-free/doc
+Priority: optional
+Architecture: all
+Depends: pine
+Description: Pine technical notes
+ These are the HTML docs which may be found in ./doc/tech-notes
+ in the pine source code, describing design goals, pine
+ components, background details, building and installation,
+ command line arguments, configuration and preferences, etc.
--- pine-4.64.orig/debian/copyright.in
+++ pine-4.64/debian/copyright.in
@@ -0,0 +1,16 @@
+This is the Debian prepackaged version of the "pine" e-mail reader.
+
+This package is currently maintained by Santiago Vila <sanvila@debian.org>
+and built from sources obtained from:
+
+ftp://ftp.cac.washington.edu/pine/pine4.64.tar.gz
+
+Maildir support was taken from:
+
+http://www.freeit.com/mta/maildir980721.patch.gz
+
+This package was first put together by
+Ted Hajek <tedhajek@boombox.micro.umn.edu>
+
+Copyright:
+
--- pine-4.64.orig/debian/copyright.pt
+++ pine-4.64/debian/copyright.pt
@@ -0,0 +1,2 @@
+The pine-tracker package is in the public domain.
+
--- pine-4.64.orig/debian/DO-NOT-DISTRIBUTE-BINARIES
+++ pine-4.64/debian/DO-NOT-DISTRIBUTE-BINARIES
@@ -0,0 +1,13 @@
+
+
+
+Important notice: Pine license does not allow "modified binaries" (like
+the ones produced by this source package) to be distributed.
+
+In particular, if you are a Debian developer, feel free to compile it
+for a specific architecture to see if there are any bugs, but please
+do not upload any .deb packages.
+
+Press Enter to continue
+
+
--- pine-4.64.orig/debian/menu.pine
+++ pine-4.64/debian/menu.pine
@@ -0,0 +1 @@
+?package(pine):needs="text" section="Apps/Net" title="Pine" command="/usr/bin/pine"
--- pine-4.64.orig/debian/pine-tracker.postinst.in
+++ pine-4.64/debian/pine-tracker.postinst.in
@@ -0,0 +1,21 @@
+#!/bin/sh
+set -e
+. /usr/share/debconf/confmodule
+
+thisversion=THISVERSION
+
+uptodate=1
+for p in pine pine-tech-notes pilot; do
+  version=`awk -v p=$p '
+  $0 ~ "^Package:" { package = $2 }
+  $0 ~ "^Version:" { if (package == p) print $2 }
+  ' /var/lib/dpkg/status`
+  if dpkg --compare-versions "$version" lt-nl "$thisversion"; then
+    uptodate=0
+  fi
+done
+if [ "$uptodate" = 0 ]; then
+  db_fset pine-tracker/note seen false
+  db_input high pine-tracker/note || true
+  db_go || true
+fi
--- pine-4.64.orig/debian/pine-tracker.postrm
+++ pine-4.64/debian/pine-tracker.postrm
@@ -0,0 +1,6 @@
+#!/bin/sh
+set -e
+. /usr/share/debconf/confmodule
+if [ "$1" = "purge" ]; then
+    db_purge
+fi
--- pine-4.64.orig/debian/pine-tracker.templates
+++ pine-4.64/debian/pine-tracker.templates
@@ -0,0 +1,11 @@
+Template: pine-tracker/note
+Type: note
+Description: New pine source available
+  Some packages built from the pine source are out of date. To update
+  these packages, make sure you have source URIs in /etc/apt/sources.list
+  and run the following commands, as root, in a scratch directory:
+ .
+   # apt-get --only-source build-dep pine
+   # apt-get --only-source -b source pine
+ .
+  And then use dpkg -i to install the generated debian packages.
--- pine-4.64.orig/debian/postinst
+++ pine-4.64/debian/postinst
@@ -0,0 +1,61 @@
+#!/bin/sh
+set -e
+
+. /usr/share/debconf/confmodule
+
+syshostname=`hostname --fqdn`
+
+if [ "$1" = "configure" ]; then
+
+  #mkdir -p /etc/news
+
+  #db_get shared/news/server
+  #servername="$RET"
+  #echo "$RET" > /etc/news/server
+
+  #db_get shared/mailname
+  #mailname="$RET"
+  #echo "$RET" > /etc/mailname
+
+## Create /etc/pine.conf if it does not exist:
+## user-domain=$mailname if the mailname doesn't equal the hostname.
+## nntp-server=$servername if the news servername doesn't equal the hostname.
+
+  if [ ! -f /etc/pine.conf ]; then
+    #if [ "$mailname" != "$syshostname" ]; then
+    #  expr1="s/^\(user-domain=\).*$/\1$mailname/"
+    #fi
+    #if [ "$servername" != "$syshostname" ]; then
+    #  expr2="s/^\(nntp-server=\).*$/\1$servername/"
+    #fi
+    #expr3="s/^\(character-set=\).*$/\1iso-8859-1/"
+    pine -conf | sed -e '
+s|^\(user-domain=\).*$|\1mit.edu|
+s|^\(nntp-server=\).*$|\1news.mit.edu|
+s|^\(inbox-path=\).*$|\1{mit.edu/hesiod/imap}INBOX|
+s|^\(feature-list=\).*$|\1enable-mail-check-cue,\
+	save-will-quote-leading-froms,\
+	enable-full-header-cmd|
+s|^\(bugs-fullname=\).*$|\1Debian-Athena Project|
+s|^\(bugs-address=\).*$|\1debathena@mit.edu|
+s|^\(suggest-fullname=\).*$|\1Debian-Athena Project|
+s|^\(suggest-address=\).*$|\1debathena@mit.edu|
+s|^\(local-fullname=\).*$|\1Debian-Athena Project|
+s|^\(local-address=\).*$|\1debathena@mit.edu|
+s|^\(url-viewers=\).*$|\1/usr/bin/sensible-browser|
+s|^\(folder-collections=\).*$|\1"MIT Mail" {mit.edu/hesiod/imap}INBOX.[],\
+	"Old MH Mail" #mh/[],\
+	"Old Pine Mail" ~/mail/[]|
+s|^\(sendmail-path=\).*$|\1/usr/lib/debathena-msmtp|
+s|^\(rsh-open-timeout=\).*$|\10|
+s|^\(ssh-open-timeout=\).*$|\10|
+s|^\(new-version-threshold=\).*$|# (Athena hack: '\''z'\'' should be lexically greater than any pine version.)\
+\1z|
+' > /etc/pine.conf
+  fi
+
+  if [ -x /usr/bin/update-menus ]; then
+    update-menus
+  fi
+
+fi
--- pine-4.64.orig/debian/postrm
+++ pine-4.64/debian/postrm
@@ -0,0 +1,12 @@
+#!/bin/sh
+set -e
+
+. /usr/share/debconf/confmodule
+
+if [ "$1" = "purge" ]; then
+  db_purge
+  cd /etc && rm -f pine.conf pine.conf.fixed pine.info
+fi
+if [ -x /usr/bin/update-menus ]; then
+  update-menus
+fi
--- pine-4.64.orig/debian/README
+++ pine-4.64/debian/README
@@ -0,0 +1,31 @@
+There are a lot of new things in pine-4.xx. A few ones might be
+annoying when compared to pine-3.96, but there is one that is
+particularly annoying: By default, every mail folder has now an
+invisible message from MAILER-DAEMON with the following text:
+
+  This text is part of the internal format of your mail folder, and is not
+  a real message.  It is created automatically by the mail system software.
+  If deleted, important folder data will be lost, and it will be re-created
+  with the data reset to initial values.
+
+pine usually hides these messages, but they may end up being very
+annoying when using other mail clients, or even when refiltering mbox
+folders with procmail.
+
+To get rid of this feature, enable the "quell-folder-internal-msg" feature
+in the feature list.
+
+For already existing mbox folders containing invisible messages, the
+following procmail recipes may be useful, I have them at the very
+beginning in my ~/.procmailrc file:
+
+:0 fhw
+| formail -I X-IMAPbase: -I X-Keywords: -I X-UID:
+
+:0:
+* ^From: Mail System Internal Data
+* ^Subject:.*FOLDER INTERNAL DATA
+folder-internal-data
+
+
+Santiago Vila <sanvila@debian.org>
--- pine-4.64.orig/debian/README.pine-tracker
+++ pine-4.64/debian/README.pine-tracker
@@ -0,0 +1,19 @@
+pine-tracker
+------------
+
+This package warns you about outdated pine packages in your system.
+It compares its own version against the installed version of pine, etc.
+and suggests the user to update those packages if old packages are found.
+
+Follows the recipe given by postinst, in case you want to read it here:
+
+To update the packages built from the pine source, make sure you have
+source URIs in /etc/apt/sources.list and run the following commands,
+as root, in a scratch directory:
+
+# apt-get --only-source build-dep pine
+# apt-get --only-source -b source pine
+
+Then use dpkg -i to install the generated debian packages.
+
+For info about source URIs please see sources.list(5).
--- pine-4.64.orig/debian/templates
+++ pine-4.64/debian/templates
@@ -0,0 +1,14 @@
+Template: shared/news/server
+Type: string
+Description: What news server should be used for reading and posting news?
+ What news server (NNTP server) should be used for reading and posting
+ news?
+ .
+ Enter the fully qualified domain name of the server.
+
+Template: shared/mailname
+Type: string
+Description: Please enter the mail name of your system:
+ The "mail name" is the hostname portion of the address to be shown on
+ outgoing news and mail messages.
+
