From: utzoo!decvax!microsof!uw-beave!jim
Newsgroups: net.unix-wizards
Title: Bugs in 4.1bsd mailers
Article-I.D.: uw-beave.273
Posted: Mon Jan  3 16:41:42 1983
Received: Tue Jan  4 06:22:48 1983

I have noticed several bugs in mail and rmail as delivered with 4.1bsd.

In rmail.c, where the command line for delivermail is built, we have:

	sprintf(cmd, "%s -r%s %s", MAILER, from, to);

I think this should be:

	sprintf(cmd, "%s -em -i -r%s %s", MAILER, from, to);

The "-em" says to mail back errors.  Without this, errors seem to get
mailed back anyway, I assume because delivermail is smart enough to
realize that the mail is coming from rmail.  Sometimes the returned
mail is missing the line that says why the mail was returned, and I
think this is because the "-em" is missing, but I haven't verified
this.  The "-i" flag tells delivermail to ignore lines containing just
a single ".".

In mail.c, after uucp mail is handed off to uux, we have the curious
combination:

	pclose(rmf);
	exit(0);

What this does is ignore any errors from uux.  Our uux returns 0 for no
errors, 1 for system type failures, and 101 (where did this number come
from?) if the host is not in the L.sys file.  It seems to me that a
better exit from mail would be something like:

#include 
...
	switch (pclose(rmf)) {
	case 0:			/* Normal exit */
		exit(0);
	case (101 << 8):	/* Unknown host */
		exit(EX_NOHOST);
	default:		/* Unknown error from uux */
		exit(EX_OSERR);

Better yet, fix uux so it returns EX_* codes, and have mail.c do:

	exit(pclose(rmf) >> 8);

Before you run out with editor in hand to do battle with the sources, I
should mention that I have not tried this change.  I discovered the
problem when I noticed that our local version of the uucp mailer (we
don't use /bin/mail directly for this) returns mail addressed to
unknown hosts, but that /bin/mail just drops it.

Does anyone know why the handling of exit codes in mail.c is so sloppy?
Eric Allman (who wrote delivermail) seems to be much too careful to
allow something like this to happen.