From srm@eternal.epitaph.org  Wed Apr 19 17:15:02 2000
Return-Path: <srm@eternal.epitaph.org>
Received: from eternal.epitaph.org (cc1006043-a.vron1.nj.home.com [24.3.150.10])
	by hub.freebsd.org (Postfix) with ESMTP id 8C99837B857
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 19 Apr 2000 17:15:01 -0700 (PDT)
	(envelope-from srm@eternal.epitaph.org)
Received: (from srm@localhost)
	by eternal.epitaph.org (8.9.0/8.9.0) id UAA00708;
	Wed, 19 Apr 2000 20:41:25 -0400 (EDT)
Message-Id: <200004200041.UAA00708@eternal.epitaph.org>
Date: Wed, 19 Apr 2000 20:41:25 -0400 (EDT)
From: srm@epitaph.org
Sender: srm@eternal.epitaph.org
Reply-To: srm@epitaph.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: update to src/usr.bin/from/from.c for multiple mboxes
X-Send-Pr-Version: 3.2

>Number:         18100
>Category:       bin
>Synopsis:       [patch] from(1): update to src/usr.bin/from/from.c for multiple mboxes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          suspended
>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:  Mon May 05 03:16:54 UTC 2014
>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:

From: Alexander Best <alexbestms@math.uni-muenster.de>
To: <bug-followup@FreeBSD.org>,
 <srm@epitaph.org>
Cc:  
Subject: Re: bin/18100: [patch] update to src/usr.bin/from/from.c for
 multiple mboxes
Date: Sat, 07 Nov 2009 03:11:45 +0100 (CET)

 this patch still looks like a useful addition to the `from' command. what's
 missing in order to fully support multiple mailboxes however is
 
 1. support for `from -f file1 file2 ... fileN'
 2. support for `from [user1] [user2] ... [userN]'
 
 taking the long time this change request has been around into account and the
 fact that zero replies were made, this pr should be set into suspended state.
 
 cheers.
 alex
State-Changed-From-To: open->suspended 
State-Changed-By: linimon 
State-Changed-When: Sat Nov 7 02:51:16 UTC 2009 
State-Changed-Why:  
Recent review indicates that this is still a problem.  Mark it 'suspended' 
since it has languished for so long. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18100 
>Unformatted:
