mail(1) patch: ignoring empty letters

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

mail(1) patch: ignoring empty letters

vetinari
Here is a small patch adding '-e' option which makes mail abort if
the body of the message is empty.

Quite a useful thing to do, for example, in crontab entry:

*/5 * * * * root /path/../script.sh | mail -e root

where script.sh most of the time outputs nothing.


Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/main.c,v
retrieving revision 1.19
diff -u -r1.19 main.c
--- main.c 19 Apr 2004 10:17:18 -0000 1.19
+++ main.c 3 May 2006 12:03:17 -0000
@@ -92,7 +92,7 @@
  bcc = NULL;
  smopts = NULL;
  subject = NULL;
- while ((i = getopt(argc, argv, "INT:b:c:dfins:u:v")) != -1) {
+ while ((i = getopt(argc, argv, "INT:b:c:defins:u:v")) != -1) {
  switch (i) {
  case 'T':
  /*
@@ -123,6 +123,9 @@
  break;
  case 'd':
  debug++;
+ break;
+ case 'e':
+ assign("ignoreempty", "");
  break;
  case 's':
  /*
Index: send.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/send.c,v
retrieving revision 1.17
diff -u -r1.17 send.c
--- send.c 3 Jun 2003 02:56:11 -0000 1.17
+++ send.c 3 May 2006 12:03:17 -0000
@@ -332,12 +332,16 @@
  char **namelist;
  struct name *to;
  FILE *mtf;
+ int ignoreempty;
 
  /*
  * Collect user's mail from standard input.
  * Get the result as mtf.
  */
  if ((mtf = collect(hp, printheaders)) == NULL)
+ return;
+ ignoreempty = value("ignoreempty") != NULL;
+ if (fsize(mtf) == 0 && ignoreempty)
  return;
  if (fsize(mtf) == 0) {
  if (hp->h_subject == NULL)

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

Eichert, Diana
I don't see the man page patch.


-----Original Message-----
From: [hidden email] on behalf of vetinari
Sent: Wed 5/3/2006 6:10 AM
To: [hidden email]
Subject: mail(1) patch: ignoring empty letters

Here is a small patch adding '-e' option which makes mail abort if
the body of the message is empty.

Quite a useful thing to do, for example, in crontab entry:

*/5 * * * * root /path/../script.sh | mail -e root

where script.sh most of the time outputs nothing.


Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/main.c,v
retrieving revision 1.19
diff -u -r1.19 main.c
--- main.c 19 Apr 2004 10:17:18 -0000 1.19
+++ main.c 3 May 2006 12:03:17 -0000
@@ -92,7 +92,7 @@
  bcc = NULL;
  smopts = NULL;
  subject = NULL;
- while ((i = getopt(argc, argv, "INT:b:c:dfins:u:v")) != -1) {
+ while ((i = getopt(argc, argv, "INT:b:c:defins:u:v")) != -1) {
  switch (i) {
  case 'T':
  /*
@@ -123,6 +123,9 @@
  break;
  case 'd':
  debug++;
+ break;
+ case 'e':
+ assign("ignoreempty", "");
  break;
  case 's':
  /*
Index: send.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/send.c,v
retrieving revision 1.17
diff -u -r1.17 send.c
--- send.c 3 Jun 2003 02:56:11 -0000 1.17
+++ send.c 3 May 2006 12:03:17 -0000
@@ -332,12 +332,16 @@
  char **namelist;
  struct name *to;
  FILE *mtf;
+ int ignoreempty;

  /*
  * Collect user's mail from standard input.
  * Get the result as mtf.
  */
  if ((mtf = collect(hp, printheaders)) == NULL)
+ return;
+ ignoreempty = value("ignoreempty") != NULL;
+ if (fsize(mtf) == 0 && ignoreempty)
  return;
  if (fsize(mtf) == 0) {
  if (hp->h_subject == NULL)

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

vetinari
On Wed, May 03, 2006 at 06:39:12AM -0600, Eichert, Diana wrote:
> I don't see the man page patch.

Here it is:


Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/main.c,v
retrieving revision 1.19
diff -u -r1.19 main.c
--- main.c 19 Apr 2004 10:17:18 -0000 1.19
+++ main.c 3 May 2006 13:22:20 -0000
@@ -92,7 +92,7 @@
  bcc = NULL;
  smopts = NULL;
  subject = NULL;
- while ((i = getopt(argc, argv, "INT:b:c:dfins:u:v")) != -1) {
+ while ((i = getopt(argc, argv, "INT:b:c:defins:u:v")) != -1) {
  switch (i) {
  case 'T':
  /*
@@ -123,6 +123,9 @@
  break;
  case 'd':
  debug++;
+ break;
+ case 'e':
+ assign("ignoreempty", "");
  break;
  case 's':
  /*
Index: send.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/send.c,v
retrieving revision 1.17
diff -u -r1.17 send.c
--- send.c 3 Jun 2003 02:56:11 -0000 1.17
+++ send.c 3 May 2006 13:22:21 -0000
@@ -332,12 +332,16 @@
  char **namelist;
  struct name *to;
  FILE *mtf;
+ int ignoreempty;
 
  /*
  * Collect user's mail from standard input.
  * Get the result as mtf.
  */
  if ((mtf = collect(hp, printheaders)) == NULL)
+ return;
+ ignoreempty = value("ignoreempty") != NULL;
+ if (fsize(mtf) == 0 && ignoreempty)
  return;
  if (fsize(mtf) == 0) {
  if (hp->h_subject == NULL)
Index: mail.1
===================================================================
RCS file: /cvs/src/usr.bin/mail/mail.1,v
retrieving revision 1.46
diff -u -r1.46 mail.1
--- mail.1 7 Dec 2004 22:30:55 -0000 1.46
+++ mail.1 3 May 2006 13:22:22 -0000
@@ -40,7 +40,7 @@
 .Sh SYNOPSIS
 .Nm mail
 .Bk -words
-.Op Fl Iinv
+.Op Fl Iienv
 .Op Fl b Ar list
 .Op Fl c Ar list
 .Op Fl s Ar subject
@@ -48,11 +48,11 @@
 .Op Fl Ar sendmail-options Op Ar ...
 .Ek
 .Nm mail
-.Op Fl IiNnv
+.Op Fl IieNnv
 .Fl f
 .Op Ar name
 .Nm mail
-.Op Fl IiNnv
+.Op Fl IieNnv
 .Op Fl u Ar user
 .Sh DESCRIPTION
 .Nm mail
@@ -92,6 +92,9 @@
 particularly useful when using
 .Nm mail
 on noisy phone lines.
+.It Fl e
+Don't send empty mails.
+Abort if the messege body is empty.
 .It Fl N
 Inhibits initial display of message headers
 when reading mail or editing a mail folder.

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

Marco Pfatschbacher
In reply to this post by vetinari
On Wed, May 03, 2006 at 02:10:35PM +0200, vetinari wrote:
> Here is a small patch adding '-e' option which makes mail abort if
> the body of the message is empty.
>
> Quite a useful thing to do, for example, in crontab entry:
>
> */5 * * * * root /path/../script.sh | mail -e root
>
> where script.sh most of the time outputs nothing.
 
how about this?

> */5 * * * * root /path/../script.sh | grep . && mail -e root

IMO, it's not worth adding a non standard extension.

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

vetinari
On Wed, May 03, 2006 at 04:20:17PM +0200, Marco Pfatschbacher wrote:

> On Wed, May 03, 2006 at 02:10:35PM +0200, vetinari wrote:
> > Here is a small patch adding '-e' option which makes mail abort if
> > the body of the message is empty.
> >
> > Quite a useful thing to do, for example, in crontab entry:
> >
> > */5 * * * * root /path/../script.sh | mail -e root
> >
> > where script.sh most of the time outputs nothing.
>  
> how about this?
>
> > */5 * * * * root /path/../script.sh | grep . && mail -e root

It's not exactly the same.

$ echo -en "line1\n\nline2\n\nline3\n" | grep . && cat
line1
line2
line3
$

vetinari

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

Matthias Kilian
On Wed, May 03, 2006 at 09:10:52PM +0200, vetinari wrote:
> $ echo -en "line1\n\nline2\n\nline3\n" | grep . && cat
> line1
> line2
> line3

s/\./^/

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

Marco Pfatschbacher
In reply to this post by vetinari
On Wed, May 03, 2006 at 09:10:52PM +0200, vetinari wrote:

> On Wed, May 03, 2006 at 04:20:17PM +0200, Marco Pfatschbacher wrote:
> > On Wed, May 03, 2006 at 02:10:35PM +0200, vetinari wrote:
> > > Here is a small patch adding '-e' option which makes mail abort if
> > > the body of the message is empty.
> > >
> > > Quite a useful thing to do, for example, in crontab entry:
> > >
> > > */5 * * * * root /path/../script.sh | mail -e root
> > >
> > > where script.sh most of the time outputs nothing.
> >  
> > how about this?
> >
> > > */5 * * * * root /path/../script.sh | grep . && mail -e root
>
> It's not exactly the same.
>
> $ echo -en "line1\n\nline2\n\nline3\n" | grep . && cat
> line1
> line2
> line3
> $

Actually, my workaround is complete bogus. cat will not get the output
from grep.
Anyway, I still don't like adding an incompatible extension to mail.


    Marco

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

vetinari
On Wed, May 03, 2006 at 11:19:38PM +0200, Marco Pfatschbacher wrote:

> On Wed, May 03, 2006 at 09:10:52PM +0200, vetinari wrote:
> > On Wed, May 03, 2006 at 04:20:17PM +0200, Marco Pfatschbacher wrote:
> > > On Wed, May 03, 2006 at 02:10:35PM +0200, vetinari wrote:
> > > > Here is a small patch adding '-e' option which makes mail abort if
> > > > the body of the message is empty.
> > > >
> > > > Quite a useful thing to do, for example, in crontab entry:
> > > >
> > > > */5 * * * * root /path/../script.sh | mail -e root
> > > >
> > > > where script.sh most of the time outputs nothing.
> > >  
> > > how about this?
> > >
> > > > */5 * * * * root /path/../script.sh | grep . && mail -e root
> >
> > It's not exactly the same.
> >
> > $ echo -en "line1\n\nline2\n\nline3\n" | grep . && cat
> > line1
> > line2
> > line3
> > $
>
> Actually, my workaround is complete bogus. cat will not get the output
> from grep.
> Anyway, I still don't like adding an incompatible extension to mail.

How should I do it then?


vetinari

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

Nick Guenther
On 5/4/06, vetinari <[hidden email]> wrote:

> On Wed, May 03, 2006 at 11:19:38PM +0200, Marco Pfatschbacher wrote:
> > On Wed, May 03, 2006 at 09:10:52PM +0200, vetinari wrote:
> > > On Wed, May 03, 2006 at 04:20:17PM +0200, Marco Pfatschbacher wrote:
> > > > On Wed, May 03, 2006 at 02:10:35PM +0200, vetinari wrote:
> > > > > Here is a small patch adding '-e' option which makes mail abort if
> > > > > the body of the message is empty.
> > > > >
> > > > > Quite a useful thing to do, for example, in crontab entry:
> > > > >
> > > > > */5 * * * * root /path/../script.sh | mail -e root
> > > > >
> > > > > where script.sh most of the time outputs nothing.
> > > >
> > > > how about this?
> > > >
> > > > > */5 * * * * root /path/../script.sh | grep . && mail -e root
> > >
> > > It's not exactly the same.
> > >
> > > $ echo -en "line1\n\nline2\n\nline3\n" | grep . && cat
> > > line1
> > > line2
> > > line3
> > > $
> >
> > Actually, my workaround is complete bogus. cat will not get the output
> > from grep.
> > Anyway, I still don't like adding an incompatible extension to mail.
>
> How should I do it then?
>

Write a script (say, quietmail.sh) that waits on stdin until there is
some data available, and when that happens it exec's mail, handing off
the stdin stream. You could even make it pass it's command line args
direct into mail so it can be used just like it.
Then:
$mycommand | quietmail.sh -options_for_mail

-Nick

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

Philip Guenther-2
On 5/4/06, Nick Guenther <[hidden email]> wrote:
> Write a script (say, quietmail.sh) that waits on stdin until there is
> some data available, and when that happens it exec's mail, handing off
> the stdin stream.

That can't be done as you described from a shell script, as the shell
doesn't provide access to recv(MSG_PEEK).  From a shell script you
would have to relay all the data between stdin and sendmail as there's
no way to 'push back' the data you read when verifying that there
really was data and not just EOF.


> You could even make it pass it's command line args
> direct into mail so it can be used just like it.
> Then:
> $mycommand | quietmail.sh -options_for_mail

Side-note: when doing that (passing on of command line arguments) in
shell scripts, be sure to use "$@" and _not_ $*, as the latter will
result in resplitting of the arguments instead of preservation of the
argument boundaries.

So, untested:

#!/bin/sh
read line && { echo "$line"; cat - ; } | /usr/sbin/sendmail "$@"


Philip Guenther

Reply | Threaded
Open this post in threaded view
|

Re: mail(1) patch: ignoring empty letters

Arne P. Boettger
In reply to this post by vetinari
On 05.05.2006, at 00:16, vetinari wrote:
>>>>> Quite a useful thing to do, for example, in crontab entry:
>>>>>
>>>>> */5 * * * * root /path/../script.sh | mail -e root
>>>>>
>>>>> where script.sh most of the time outputs nothing.
>
> How should I do it then?

How about this:

*/5 * * * * root /path/../script.sh

Cron automatically mails any output a job produces. If there is no  
output, there is no mail.

As far as I can tell the functionality is already there...

regards, Arne

Reply | Threaded
Open this post in threaded view
|

Strange HTTP error

Alexandre Epinat
In reply to this post by vetinari
I have this strange apache error on 3.9:

ACCESS.LOG
xxx.xxx.xxx.xxx - - [12/May/2006:008:36:47 +0200] "\x80g\x01\x03" 501 -

ERROR.LOG
[Fri May 12 08:36:47 2006] [error] [client XXX.XXX.XXX.XXX] Invalid method
in request \\x80g\\x01\\x03


I configured apache as a reverse proxy the same way it is on another
server (openBSD 3.7) and I get this strange error above when I ask for a
page.

I ask for a web page in https and the openBSD reverse proxy redirects in
HTTP.

really strange cause I've had this working for years now and with 3.9 I
get this error.

Apache using mod_security, mod_proxy and mod_rewrite.

/A