This patch makes MH command "folders" 10 times faster. The idea is
given by Kazumasa Utashiro <utashiro@sra.co.jp> and the author is
Yoshinari NOMURA <nomsun@csce.kyushu-u.ac.jp>. If the number of a
directory's links is 2, it stops chasing subdirectores.

*** folder.c.orig	Mon Dec  6 17:45:19 1993
--- folder.c	Sun Oct 16 17:33:01 1994
***************
*** 7,12 ****
--- 7,14 ----
  #include "../h/local.h"
  #include <errno.h>
  #include <stdio.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
  #ifdef LOCALE
  #include	<locale.h>
  #endif
***************
*** 69,74 ****
--- 71,81 ----
  #define	HELPSW	21
      "help", 4,
  
+ #define LEAFSW	22
+     "leaf", 0,
+ #define NLEAFSW	23
+     "noleaf", 0,
+ 
      NULL, 0
  };
  
***************
*** 87,92 ****
--- 94,100 ----
  static int  foldtot = 0;
  static int  start = 0;
  static int  foldp = 0;
+ static int  fleaf = 1;
  
  static char *mhdir;
  static char *stack = "Folder-Stack";
***************
*** 231,236 ****
--- 239,250 ----
  		    listsw++;
  		    pushsw = 0;
  		    continue;
+ 	        case LEAFSW:
+ 		    fleaf++;
+ 		    continue;
+ 		case NLEAFSW:
+ 		    fleaf = 0;
+ 		    continue;
  	    }
  	if (*cp == '+' || *cp == '@')
  	    if (argfolder)
***************
*** 413,419 ****
  	printf ("%s\n", fold);
  
  	if (!msg && !fpack) {
! 	    if (frecurse)
  		dodir (fold);
  	    return retval;
  	}
--- 427,433 ----
  	printf ("%s\n", fold);
  
  	if (!msg && !fpack) {
! 	    if (frecurse && ImustDig(fold))
  		dodir (fold);
  	    return retval;
  	}
***************
*** 464,470 ****
      others = mp -> msgflags & OTHERS;
      m_fmsg (mp);
  
!     if (frecurse && others)
  	dodir (fold);
  
      return retval;
--- 478,484 ----
      others = mp -> msgflags & OTHERS;
      m_fmsg (mp);
  
!     if (frecurse && others && ImustDig(fold))
  	dodir (fold);
  
      return retval;
***************
*** 631,633 ****
--- 645,664 ----
  		&& !ssequal (mhdir, np -> n_name + atrlen))
  	    (void) pfold (np -> n_name + atrlen, NULLCP);
  }
+ 
+ /*  */
+ 
+ static int ImustDig(path)
+     char *path;
+ {
+     struct stat buf;
+ 
+     if (!fleaf) return 1; /* don't trust link counter */
+ 
+     if (stat(m_maildir(path), &buf) == NOTOK) {
+ 	perror("stat:");
+ 	return 0;
+     }
+ 
+     return (int)buf.st_nlink > 2 ? 1:0;
+ }

