On 22-12-18 09:29PM, Jason McIntyre wrote:
> On Fri, Dec 16, 2022 at 02:21:41AM +0000, Tim Chase wrote:
> > According to the POSIX definitions for mail(1) & mailx(1), the
> > (s)ave command should save to "mbox" if the filename is not specified
> > 
> > > Save the specified messages in the file named by the pathname
> > > file, or the mbox if the file argument is omitted
> > 
> > (newer spec)
> > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/mailx.html#tag_20_75_13_33
> > 
> > > s [file]
> > >  Save the message in the named file (mbox is default).
> > 
> > (older spec)
> > https://pubs.opengroup.org/onlinepubs/7908799/xcu/mail.html#tag_001_014_1339
> > 
> > 
> > 
> > However, when exercising this functionality, mail(1) on OpenBSD
> > (also tested on FreeBSD where the same issue manifests[1]) doesn't
> > support this:
> > 
> >   demo$ echo test | mail -s "test" demo # send self a message
> >   demo$ mail
> >   Mail version 8.1 6/6/93.  Type ? for help.
> >   "/var/mail/demo": 1 message 1 new
> >   >N  1 d...@localhost.my.do  Thu Dec 15 19:34  19/775   "test"
> >   & s
> >   No file specified.
> > 
> > While I'm not positive on the solution, I think it involves tweaking
> > the save1() function in src/usr.bin/mail/cmd2.c such that instead
> > of failing if it can't snarf(), it should set `file` to "mbox" or
> > "&" so that expand() points to the mbox as required by POSIX.
> > 
> > -tkc
> > 
> > [1]
> > https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=268402
> > 
> 
> hi.
> 
> currently mail(1) has these entries in FILES:
> 
>     FILES
>        /var/mail/*                 post office (unless overridden
>                                    by the MAIL environment
>                                    variable)
>        ~/mbox                      user's old mail
> 
> isn;t it the case that openbsd uses mailboxes in /var/mail by default,
> instead of ~/mbox, as displayed?
> 
> it seems that mail(1) is really out of date regarding default mail spool
> entries, but i may well have misunderstood the situation. once it's
> clear, i can see if we need a code fix (out of my hands) or doc fix.
> 
> jmc

I agree with Brian and think behaviour comports with mail(1). Unexamined
mail remains in the post office (i.e., /var/mail/*), and examined mail,
as noted by Brian, is deposited to the user's mbox file (i.e., ~/mbox):

  You can end a mail session with the quit (q) command.  Messages
  which have been examined go to your mbox file unless they have
  been deleted, in which case they are discarded.  Unexamined
  messages go back to the post office (see the -f option above).

If the session is aborted with e(x)it, however, changes are discarded
thus mail remains unexamined and left in the post office.

Regarding the OP's case, (s)ave is also consistent with mail(1) except
that line and char count are not currently echoed (the below diff adds
this to the output):

  save  (s) Takes a message list and a filename and appends each message
        in turn to the end of the file.  The filename in quotes,
        followed by the line count and character count is echoed on the
        user's terminal.

I guess it's a question of whether we want to change this and make it
comply with POSIX so that "s" with no args saves the current message to
the user's mbox file as the diff upthread does. I think it's handy, but
that behaviour might have been omitted on purpose. And, tbh, "s" isn't
really that much more convenient than "s &".

diff d956567b8a83e77dcbaa40d1038b81c18ca02b19 
0628dc730fed3c76f8e1cec17dd1c90c3a58aa75
commit - d956567b8a83e77dcbaa40d1038b81c18ca02b19
commit + 0628dc730fed3c76f8e1cec17dd1c90c3a58aa75
blob - 54b30bc153cd53765a7d15eb0430246c9b46fb17
blob + 7a0650ddcf690e3b2f61550007cf40819b308f94
--- usr.bin/mail/cmd2.c
+++ usr.bin/mail/cmd2.c
@@ -146,6 +146,8 @@ save1(char *str, int mark, char *cmd, struct ignoretab
 {
        struct message *mp;
        char *file, *disp;
+       off_t sz = 0;
+       int nlines = 0;
        int f, *msgvec, *ip;
        FILE *obuf;
 
@@ -182,6 +184,8 @@ save1(char *str, int mark, char *cmd, struct ignoretab
                        (void)Fclose(obuf);
                        return(1);
                }
+               nlines += mp->m_lines;
+               sz += mp->m_size;
                if (mark)
                        mp->m_flag |= MSAVED;
        }
@@ -189,7 +193,7 @@ save1(char *str, int mark, char *cmd, struct ignoretab
        if (ferror(obuf))
                warn("%s", file);
        (void)Fclose(obuf);
-       printf("%s\n", disp);
+       printf("%s %d/%lld\n", disp, nlines, (long long)sz);
        return(0);
 }
 

-- 
Mark Jamsek <fnc.bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68

Attachment: signature.asc
Description: PGP signature

Reply via email to