Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Feb 2002 22:00:03 -0800 (PST)
From:      Andrew Hesford <jester@core.usrlib.org>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/35129: Maildir support in login(1)
Message-ID:  <200202200600.g1K603G18266@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/35129; it has been noted by GNATS.

From: Andrew Hesford <jester@core.usrlib.org>
To: freebsd-gnats-submit@FreeBSD.org, ajh3@cec.wustl.edu
Cc:  
Subject: Re: bin/35129: Maildir support in login(1)
Date: Tue, 19 Feb 2002 23:53:39 -0600

 After some extra thought, I have changed the patch a bit. Whereas before
 login(1) would go through $MAILDIR/new and count every message, and then
 count every message in $MAILDIR/cur, I have reduced it to counting at
 most four directory entries.
 
 Now I simply call fts_read() twice on $MAILDIR/new to see if there are
 files in that directory. If there are, each call to fts_read() will
 produce an FTSENT structure with a different fts_name field: the first
 will be the directory, and the second will be some file. If there are no
 files in the directory, each FTSENT structure will contain the directory
 name in its fts_name field.
 
 If there are files in $MAILDIR/new, login(1) prints "You have new mail."
 and forgets about Maildir. Otherwise, it repeats the fts_read() process
 for $MAILDIR/cur.
 
 The reasoning behind the first patch was to count new and old messages,
 to display a count; however, I decided against that but did not change
 the process. After some secondary thought I realized that this new
 method is superior, because at worst-case there are four fts_read()
 calls.
 
 I don't think there are bugs in this... I'll leave that to everybody
 else to determine. :) I'm sure many people who rely on Maildir will find
 this useful (or a superior scheme if you can think of one).
 
 ::: BEGIN login.diff :::
 
 *** login.c.orig	Tue Feb 19 23:35:27 2002
 --- login.c	Tue Feb 19 23:39:03 2002
 ***************
 *** 53,59 ****
 --- 53,61 ----
   
   #include <sys/copyright.h>
   #include <sys/param.h>
 + #include <sys/types.h>
   #include <sys/stat.h>
 + #include <fts.h>
   #include <sys/socket.h>
   #include <sys/time.h>
   #include <sys/resource.h>
 ***************
 *** 167,172 ****
 --- 169,179 ----
   	char tname[sizeof(_PATH_TTY) + 10];
   	char *shell = NULL;
   	login_cap_t *lc = NULL;
 + 	int use_mdir = 0;
 + 	FTS *ftsp;
 + 	char *mdbuf[2];
 + 	FTSENT *ftse[2];
 + 	int mdopt = FTS_NOCHDIR | FTS_NOSTAT | FTS_LOGICAL;
   #ifdef USE_PAM
   	pid_t pid;
   	int e;
 ***************
 *** 690,701 ****
   		cw = getenv("MAIL");	/* $MAIL may have been set by class */
   		if (cw != NULL)
   			strlcpy(tbuf, cw, sizeof(tbuf));
 ! 		else
 ! 			snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILDIR,
 ! 			    pwd->pw_name);
 ! 		if (stat(tbuf, &st) == 0 && st.st_size != 0)
   			(void)printf("You have %smail.\n",
   			    (st.st_mtime > st.st_atime) ? "new " : "");
   	}
   
   	login_close(lc);
 --- 697,745 ----
   		cw = getenv("MAIL");	/* $MAIL may have been set by class */
   		if (cw != NULL)
   			strlcpy(tbuf, cw, sizeof(tbuf));
 ! 		else {
 ! 			cw = getenv("MAILDIR");
 ! 			if (cw != NULL) {
 ! 				strlcpy(tbuf, cw, sizeof(tbuf));
 ! 				use_mdir = 1;
 ! 			}
 ! 			else
 ! 				snprintf(tbuf, sizeof(tbuf), "%s/%s",
 ! 						_PATH_MAILDIR, pwd->pw_name);
 ! 		}
 ! 		if (!use_mdir && stat(tbuf, &st) == 0 && st.st_size != 0)
   			(void)printf("You have %smail.\n",
   			    (st.st_mtime > st.st_atime) ? "new " : "");
 + 		/*
 + 		 * The only way to check Maildir for messages is to read
 + 		 * the directories... use fts(3) for this.
 + 		 */
 + 		else if (use_mdir && stat(tbuf, &st) == 0 &&
 + 				(st.st_mode & S_IFDIR) != 0) {
 + 			mdbuf[0] = (char*)malloc(sizeof(tbuf));
 + 			bzero(mdbuf[0], sizeof(tbuf));
 + 			snprintf(mdbuf[0], sizeof(tbuf), "%s/new", tbuf);
 + 			if ((ftsp = fts_open(mdbuf, mdopt, NULL)) != NULL) {
 + 			    ftse[0] = fts_read(ftsp);
 + 			    ftse[1] = fts_read(ftsp);
 + 			    fts_close(ftsp);
 + 			    if (strcmp(ftse[0]->fts_name,
 + 					ftse[1]->fts_name) != 0)
 + 			        (void)printf("You have new mail.\n");
 + 			    else {
 + 			        snprintf(mdbuf[0], sizeof(tbuf),
 + 						"%s/cur", tbuf);
 + 				if ((ftsp=fts_open(mdbuf,mdopt, NULL))!=NULL) {
 + 				    ftse[0] = fts_read(ftsp);
 + 				    ftse[1] = fts_read(ftsp);
 + 				    fts_close(ftsp);
 + 				    if (strcmp(ftse[0]->fts_name,
 + 						ftse[1]->fts_name) != 0)
 + 				        (void)printf("You have mail.\n");
 + 				}
 + 			    }
 + 			}
 + 		}
   	}
   
   	login_close(lc);
 *** login.1.orig	Tue Feb 19 23:35:27 2002
 --- login.1	Tue Feb 19 23:38:28 2002
 ***************
 *** 173,179 ****
   login account records
   .It Pa /var/mail/user
   system mailboxes
 ! .It Pa \&.hushlogin
   makes login quieter
   .It Pa /etc/auth.conf
   configure authentication services
 --- 173,181 ----
   login account records
   .It Pa /var/mail/user
   system mailboxes
 ! .It Pa ~/Maildir
 ! Maildir mailbox (used if $MAIL is unset)
 ! .It Pa ~/\&.hushlogin
   makes login quieter
   .It Pa /etc/auth.conf
   configure authentication services
 
 ::: END login.diff :::
 -- 
 Andrew Hesford, Washington University
 ajh3@cec.wustl.edu, jester@usrlib.org
 :- Fortune of the Moment -:
 I've given up reading books; I find it takes my mind off myself.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200202200600.g1K603G18266>