Bug 10074 - mail -u doesn't work when the MAIL environ. var. is set
mail -u doesn't work when the MAIL environ. var. is set
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: mailx (Show other bugs)
6.1
All Linux
medium Severity medium
: ---
: ---
Assigned To: Florian La Roche
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-03-08 15:48 EST by Jeff Norden
Modified: 2008-05-01 11:37 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-07-14 19:41:16 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jeff Norden 2000-03-08 15:48:50 EST
If the MAIL environment variable is set, /bin/mail *ignores* the -u option.
This is evident from the following snippet:

     if (!(mbox = getenv("MAIL")))
	snprintf(buf, size, "%s/%s", _PATH_MAILDIR, user)
     else
	strncpy(buf, mbox, size)

This problem was alluded to in bug #4465.  The solution of using "su -"
given there works because it sets MAIL, not USER.

I've got multiple mailboxes on my system (mostly for mailing lists I've
subscribed to).  Its nice to be able to use "mail -u foo_list"
occasionally, even though /bin/mail isn't my main mail reader.

A workaround for the problem is to do 'unset MAIL' in .bash_profle.

A better fix is the patch below, which causes /bin/mail to ignore MAIL when
-u is specified.  (This diff was generated from mailx-8.1.1-10 sources
after the other 6 patches were applied, so I guess it could be patch7.)

-Jeff Norden
===================================================================
--- mailx-8.1.1/v7.local.c~	Tue Feb 29 17:11:43 2000
+++ mailx-8.1.1/v7.local.c	Tue Feb 29 17:24:35 2000
@@ -66,7 +66,8 @@
 {
 	char *mbox;

-	if (!(mbox = getenv("MAIL"))) {
+	mbox = getenv("MAIL");
+	if (uflag || (mbox == NOSTR)) {
 		(void)snprintf(buf, size, "%s/%s", _PATH_MAILDIR, user);
 	} else {
 		(void)strncpy(buf, mbox, size);
--- mailx-8.1.1/main.c~	Tue Feb 29 17:11:43 2000
+++ mailx-8.1.1/main.c	Tue Feb 29 17:18:56 2000
@@ -132,8 +132,11 @@
 		case 'u':
 			/*
 			 * Next argument is person to pretend to be.
+			 * Also set a flag to tell findmail() to ignore the
+			 * MAIL environment  variable.
 			 */
 			myname = optarg;
+			uflag++;
 			break;
 		case 'i':
 			/*
--- mailx-8.1.1/glob.h~	Tue Feb 29 17:11:43 2000
+++ mailx-8.1.1/glob.h	Tue Feb 29 17:31:48 2000
@@ -79,6 +79,7 @@
 struct	ignoretab	ignoreall[2];	/* special, ignore all headers */
 char	**altnames;			/* List of alternate names for user */
 int	debug;				/* Debug flag set */
+int	uflag;				/* -u option given? */
 int	screenwidth;			/* Screen width, or best guess */
 int	screenheight;			/* Screen height, or best guess,
Comment 1 Jeff Johnson 2000-08-11 15:19:25 EDT
Added in mailx-8.1.1-17. Thanks for the patch.

Note You need to log in before you can comment on or make changes to this bug.