From e65f95daf358a37f16803c1e0525aac9c021d0b6 Mon Sep 17 00:00:00 2001 From: mikeh Date: Thu, 28 Jun 2001 02:40:07 +0000 Subject: Add the -E flag to not send messages that have an empty body. This is useful for piping cron script error output by mail. PR: bin/9494 Obtained from: NetBSD MFC after: 2 weeks --- usr.bin/mail/mail.1 | 9 ++++++--- usr.bin/mail/main.c | 16 +++++++++++----- usr.bin/mail/send.c | 2 ++ 3 files changed, 19 insertions(+), 8 deletions(-) (limited to 'usr.bin/mail') diff --git a/usr.bin/mail/mail.1 b/usr.bin/mail/mail.1 index ed67cc3..ddbf34a 100644 --- a/usr.bin/mail/mail.1 +++ b/usr.bin/mail/mail.1 @@ -40,7 +40,7 @@ .Nd send and receive mail .Sh SYNOPSIS .Nm -.Op Fl iInv +.Op Fl EiInv .Op Fl s Ar subject .Op Fl c Ar cc-addr .Op Fl b Ar bcc-addr @@ -50,11 +50,11 @@ .Ar sendmail-option ... .Oc .Nm -.Op Fl iInNv +.Op Fl EiInNv .Fl f .Op Ar name .Nm -.Op Fl iInNv +.Op Fl EiInNv .Op Fl u Ar user .Sh INTRODUCTION .Nm Mail @@ -68,6 +68,9 @@ with lines replaced by messages. Verbose mode. The details of delivery are displayed on the user's terminal. +.It Fl E +Don't send messages with an empty body. This is useful +for piping errors from cron scripts. .It Fl i Ignore tty interrupt signals. This is diff --git a/usr.bin/mail/main.c b/usr.bin/mail/main.c index 7c03e17..3707903 100644 --- a/usr.bin/mail/main.c +++ b/usr.bin/mail/main.c @@ -93,7 +93,7 @@ main(argc, argv) bcc = NULL; smopts = NULL; subject = NULL; - while ((i = getopt(argc, argv, "INT:b:c:dfins:u:v")) != -1) { + while ((i = getopt(argc, argv, "EINT:b:c:dfins:u:v")) != -1) { switch (i) { case 'T': /* @@ -181,13 +181,19 @@ main(argc, argv) */ bcc = cat(bcc, nalloc(optarg, GBCC)); break; + case 'E': + /* + * Don't send empty files. + */ + assign("dontsendempty", ""); + break; case '?': fprintf(stderr, "\ -Usage: %s [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ +Usage: %s [-EiInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ %*s [- sendmail-options ...]\n\ - %s [-iInNv] -f [name]\n\ - %s [-iInNv] [-u user]\n",__progname, strlen(__progname), "", __progname, - __progname); + %s [-EiInNv] -f [name]\n\ + %s [-EiInNv] [-u user]\n",__progname, strlen(__progname), "", + __progname, __progname); exit(1); } } diff --git a/usr.bin/mail/send.c b/usr.bin/mail/send.c index 0e6886c..42dd65e 100644 --- a/usr.bin/mail/send.c +++ b/usr.bin/mail/send.c @@ -323,6 +323,8 @@ mail1(hp, printheaders) } } if (fsize(mtf) == 0) { + if (value("dontsendempty") != NULL) + goto out; if (hp->h_subject == NULL) printf("No message, no subject; hope that's ok\n"); else -- cgit v1.1