Bug 268402 - mail(1) save command doesn't adhere to POSIX fallback to mbox
Summary: mail(1) save command doesn't adhere to POSIX fallback to mbox
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-standards (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-16 02:13 UTC by Tim Chase
Modified: 2022-12-16 13:54 UTC (History)
1 user (show)

See Also:


Attachments
Patch from Mark Jamsek on bugs@openbsd to fix issue (1.93 KB, patch)
2022-12-16 13:54 UTC, Tim Chase
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Chase 2022-12-16 02:13:19 UTC
According to the POSIX definitions for mail(1),
the (s)ave command should save to "mbox" if the
file is not specified

> Save the specified messages in the file named
> by the pathname file, or the mbox if the file
> argument is omitted

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).

https://pubs.opengroup.org/onlinepubs/7908799/xcu/mail.html#tag_001_014_1339

However, when exercising this functionality,
mail(1) on FreeBSD (also tested on OpenBSD where
the same issue manifests) doesn't support this:

  demo$ echo test | mail -s test $USER
  demo$ mail
  Mail version 8.1 6/6/93.  Type ? for help.
  "/var/mail/demo": 1 message 1 new
  >N  1 demo@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.
Comment 1 Tim Chase 2022-12-16 13:54:35 UTC
Created attachment 238836 [details]
Patch from Mark Jamsek on bugs@openbsd to fix issue

Reporting this over on the bugs@openbsd mailing list,
Mark Jamsek created a quick patch that should update
the documentation & behavior to be in line with POSIX
requirements:

https://marc.info/?l=openbsd-bugs&m=167119629423839&w=2