zsh-workers
 help / color / mirror / code / Atom feed
* MAIL, MAILPATH and maildir support
@ 1999-06-03  4:00 Clint Adams
  1999-06-03  5:46 ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Clint Adams @ 1999-06-03  4:00 UTC (permalink / raw)
  To: zsh-workers

This patch is from Miquel van Smoorenburg <miquels@cistron.nl>.

It corrects the treatment of maildir-format mailbox directories
in MAILPATH.

-----
diff -ruN zsh-3.1.5.pws19.b4/Src/mailstat.c zsh-3.1.5.pws19/Src/mailstat.c
--- zsh-3.1.5.pws19.b4/Src/mailstat.c	Thu Jan  1 01:00:00 1970
+++ zsh-3.1.5.pws19/Src/mailstat.c	Wed Jun  2 12:29:32 1999
@@ -0,0 +1,98 @@
+/*
+ *	Stat a file. If it's a maildir, check all messages
+ *	in the maildir and present the grand total as a file.
+ *	The fields in the 'struct stat' are from the mail directory.
+ *	The following fields are emulated:
+ *
+ *	st_nlink	always 1
+ *	st_size		total number of bytes in all files
+ *	st_blocks	total number of messages
+ *	st_atime	access time of newest file in maildir
+ *	st_mtime	modify time of newest file in maildir
+ *	st_mode		S_IFDIR changed to S_IFREG
+ *
+ *	This is good enough for most mail-checking applications.
+ */
+int
+mailstat(char *path, struct stat *st)
+{
+	DIR			*dd;
+	struct			dirent *fn;
+	struct stat		st_ret, st_tmp;
+	static struct stat	st_new_last, st_ret_last;
+	char			dir[PATH_MAX * 2];
+	char			file[PATH_MAX * 2];
+	int			i, l;
+	time_t			atime = 0, mtime = 0;
+
+	/* First see if it's a directory. */
+	if ((i = stat(path, st)) != 0 || !S_ISDIR(st->st_mode))
+		return i;
+	if (strlen(path) > sizeof(dir) - 5) {
+		errno = ENAMETOOLONG;
+		return -1;
+	}
+
+	st_ret = *st;
+	st_ret.st_nlink = 1;
+	st_ret.st_size  = 0;
+	st_ret.st_blocks  = 0;
+	st_ret.st_mode  &= ~S_IFDIR;
+	st_ret.st_mode  |= S_IFREG;
+
+	/* See if cur/ is present */
+	sprintf(dir, "%s/cur", path);
+	if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) return 0;
+	st_ret.st_atime = st_tmp.st_atime;
+
+	/* See if tmp/ is present */
+	sprintf(dir, "%s/tmp", path);
+	if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) return 0;
+	st_ret.st_mtime = st_tmp.st_mtime;
+
+	/* And new/ */
+	sprintf(dir, "%s/new", path);
+	if (stat(dir, &st_tmp) || !S_ISDIR(st_tmp.st_mode)) return 0;
+	st_ret.st_mtime = st_tmp.st_mtime;
+
+	/* Optimization - if new/ didn't change, nothing else did. */
+	if (st_tmp.st_dev == st_new_last.st_dev &&
+	    st_tmp.st_ino == st_new_last.st_ino &&
+	    st_tmp.st_atime == st_new_last.st_atime &&
+	    st_tmp.st_mtime == st_new_last.st_mtime) {
+		*st = st_ret_last;
+		return 0;
+	}
+	st_new_last = st_tmp;
+
+	/* Loop over new/ and cur/ */
+	for (i = 0; i < 2; i++) {
+		sprintf(dir, "%s/%s", path, i ? "cur" : "new");
+		sprintf(file, "%s/", dir);
+		l = strlen(file);
+		if ((dd = opendir(dir)) == NULL)
+			return 0;
+		while ((fn = readdir(dd)) != NULL) {
+			if (fn->d_name[0] == '.' ||
+			    strlen(fn->d_name) + l >= sizeof(file))
+				continue;
+			strcpy(file + l, fn->d_name);
+			if (stat(file, &st_tmp) != 0)
+				continue;
+			st_ret.st_size += st_tmp.st_size;
+			st_ret.st_blocks++;
+			if (st_tmp.st_atime != st_tmp.st_mtime &&
+			    st_tmp.st_atime > atime)
+				atime = st_tmp.st_atime;
+			if (st_tmp.st_mtime > mtime)
+				mtime = st_tmp.st_mtime;
+		}
+		closedir(dd);
+	}
+
+	if (atime) st_ret.st_atime = atime;
+	if (mtime) st_ret.st_mtime = mtime;
+
+	*st = st_ret_last = st_ret;
+	return 0;
+}
diff -ruN zsh-3.1.5.pws19.b4/Src/utils.c zsh-3.1.5.pws19/Src/utils.c
--- zsh-3.1.5.pws19.b4/Src/utils.c	Sun May 16 17:32:15 1999
+++ zsh-3.1.5.pws19/Src/utils.c	Wed Jun  2 12:30:03 1999
@@ -29,6 +29,7 @@
 
 #include "zsh.mdh"
 #include "utils.pro"
+#include "mailstat.c"
 
 /* Print an error */
 
@@ -711,7 +712,7 @@
 	if (**s == 0) {
 	    *v = c;
 	    zerr("empty MAILPATH component: %s", *s, 0);
-	} else if (stat(unmeta(*s), &st) == -1) {
+	} else if (mailstat(unmeta(*s), &st) == -1) {
 	    if (errno != ENOENT)
 		zerr("%e: %s", *s, errno);
 	} else if (S_ISDIR(st.st_mode)) {


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: MAIL, MAILPATH and maildir support
@ 1999-06-04  9:48 Sven Wischnowsky
  0 siblings, 0 replies; 10+ messages in thread
From: Sven Wischnowsky @ 1999-06-04  9:48 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> A module with more powerful mail commands is a reasonable idea, but I have
> some reservations.  First, if this is going to be a largish add-on, basic
> UNIX mail-file checking (as it currently exists) should probably stay in
> the basic shell, since pretty much everybody (? I presume) uses that

Err... ahem. I always feared that I'm not normal.

> --- maybe (ms???) should work too, but it doesn't at the moment);

Now that's a weird omission. Why didn't I... (computers were slower at 
that time, but...)


Bye
 Sven

--- os/glob.c	Tue Jun  1 11:28:26 1999
+++ Src/glob.c	Fri Jun  4 11:40:04 1999
@@ -97,6 +97,7 @@
 #define TT_MINS 2
 #define TT_WEEKS 3
 #define TT_MONTHS 4
+#define TT_SECONDS 5
 
 #define TT_BYTES 0
 #define TT_POSIX_BLOCKS 1
@@ -1615,6 +1616,8 @@
 				units = TT_WEEKS, ++s;
 			    else if (*s == 'M')
 				units = TT_MONTHS, ++s;
+			    else if (*s == 's')
+				units = TT_SECONDS, ++s;
 			}
 			/* See if it's greater than, equal to, or less than */
 			if ((range = *s == '+' ? 1 : *s == '-' ? -1 : 0))

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1999-06-07 15:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-03  4:00 MAIL, MAILPATH and maildir support Clint Adams
1999-06-03  5:46 ` Bart Schaefer
1999-06-03 12:02   ` Clint Adams
1999-06-03 13:20   ` Oliver Kiddle
1999-06-03 14:08     ` Peter Stephenson
1999-06-03 15:51       ` Bart Schaefer
1999-06-03 15:45         ` Peter Stephenson
1999-06-07 13:45       ` Oliver Kiddle
1999-06-03 19:18   ` Bruce Stephens
1999-06-04  9:48 Sven Wischnowsky

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).