Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Apr 2000 20:41:25 -0400 (EDT)
From:      srm@epitaph.org
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/18100: update to src/usr.bin/from/from.c for multiple mboxes
Message-ID:  <200004200041.UAA00708@eternal.epitaph.org>

next in thread | raw e-mail | index | archive | help

>Number:         18100
>Category:       bin
>Synopsis:       update to src/usr.bin/from/from.c for multiple mboxes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 19 17:20:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Sean R. McNamara
>Release:        FreeBSD 2.2.5-RELEASE i386 (and forward)
>Organization:
n/a 
>Environment:

	Compiled and tested on FreeBSD 2.2.5-RELEASE 3.0-RELEASE
	3.1-RELEASE 3.4-RELEASE and 4.0-RELEASE (i386)  
	No other archs. were available for testing purposes.


>Description:

	/usr/bin/from modified to allow the polling of multiple mailboxes
	via the MAIL environment variable with the following syntax:
		<mailbox1>:<mailbox2>:<mailbox3>:<...>:<mailboxN>	

	Default behavior remains intact to poll <MAIL_PATH>/<USERNAME>	


>How-To-Repeat:

	N/A

>Fix:
	
--- /usr/src/usr.bin/from/from.c	Wed Apr 19 18:46:42 2000
+++ ./from.c	Wed Apr 19 18:45:39 2000
@@ -42,7 +42,7 @@
 static char sccsid[] = "@(#)from.c	8.1 (Berkeley) 6/6/93";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: src/usr.bin/from/from.c,v 1.8 1999/08/28 01:01:22 peter Exp $";
+  "$FreeBSD: src/usr.bin/from/from.c,v 1.5.2.2 1999/10/30 21:49:05 green Exp $";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -57,6 +57,7 @@
 
 int match __P((char *, char *));
 static void usage __P((void));
+char * getbox __P((char *));
 
 int
 main(argc, argv)
@@ -66,8 +67,8 @@
 	extern char *optarg;
 	extern int optind;
 	struct passwd *pwd;
-	int ch, count, newline;
-	char *file, *sender, *p;
+	int ch, count, newline, header, deflt;
+	char *file, *mailenv, *sender, *p;
 #if MAXPATHLEN > BUFSIZ
 	char buf[MAXPATHLEN];
 #else
@@ -76,6 +77,7 @@
 
 	file = sender = NULL;
 	count = -1;
+	deflt = -1;
 	while ((ch = getopt(argc, argv, "cf:s:")) != -1)
 		switch (ch) {
 		case 'c':
@@ -99,7 +101,7 @@
 	if (!file) {
 		if (*argv) {
 			(void)sprintf(buf, "%s/%s", _PATH_MAILDIR, *argv);
-			file  = buf;
+			file  = strdup(buf); deflt=1;
 		} else {
 			if (!(file = getenv("MAIL"))) {
 				if (!(pwd = getpwuid(getuid())))
@@ -107,36 +109,67 @@
 				file = pwd->pw_name;
 				(void)sprintf(buf,
 				    "%s/%s", _PATH_MAILDIR, file);
-				file = buf;
+				file = strdup(buf); deflt=1;
 			}
 		}
 	}
 
-	/* read from stdin */
-	if (strcmp(file, "-") == 0) {
-	} 
-	else if (!freopen(file, "r", stdin)) {
-		errx(1, "can't read %s", file);
-	}
-	for (newline = 1; fgets(buf, sizeof(buf), stdin);) {
-		if (*buf == '\n') {
-			newline = 1;
-			continue;
+	while(((deflt) && (mailenv = getbox(file)) != NULL)) {	
+
+		/* read from stdin */
+		if (strcmp(file, "-") == 0) {
 		}
-		if (newline && !strncmp(buf, "From ", 5) &&
-		    (!sender || match(buf + 5, sender))) {
-			if (count != -1)
-				count++;
-			else
-				printf("%s", buf);
+		else { 
+			if (!freopen(file, "r", stdin)) 
+				errx(1, "can't read %s", file);
+		} 
+	
+		header=0;
+		for (newline = 1; fgets(buf, sizeof(buf), stdin);) {
+			if (*buf == '\n') {
+				newline = 1;
+				continue;
+			}
+			if (newline && !strncmp(buf, "From ", 5) &&
+		    	(!sender || match(buf + 5, sender))) {
+				if (count != -1)
+					count++;
+				else
+					if(!header) {
+						printf("%s:\n\n",file);
+						header++;
+					}	
+					printf("%s", buf);
+					fflush(stdout);
+			}
+			newline = 0;
 		}
-		newline = 0;
+		if (count != -1)
+			printf("There %s %d message%s in your incoming mailbox.\n",
+		    	count == 1 ? "is" : "are", count, count == 1 ? "" : "s"); 
+		if(deflt == 1)
+			deflt--;
+		file = mailenv;
 	}
-	if (count != -1)
-		printf("There %s %d message%s in your incoming mailbox.\n",
-		    count == 1 ? "is" : "are", count, count == 1 ? "" : "s"); 
-	exit(0);
 }
+
+char *
+getbox(str)
+	char *str;
+{
+	char *p;
+	
+	if(*str == '\0')
+		return((char *)NULL);
+
+	for (p = str;((*str != ':')&&(*str != '\0'));str++) {}
+	*str++ = '\0';
+	return(str);
+}
+
+	
+
+
 
 static void
 usage()

>Release-Note:
>Audit-Trail:
>Unformatted:


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?200004200041.UAA00708>