Unix shell mailbox rocket science...

Unix shell mailbox rocket science...

am 24.01.2006 10:44:20 von kdd21

I need a non-interactive command-line utility to manipulate mailboxes--
one that can handle the requisite file locking, etc. This is on a
FreeBSD system that has mail, mailx, elm, pine, etc., and perhaps some
others.

I want to be able to do the following:

- Produce a numbered index of messages in the mailbox
- Output (stdout) a message by number
- Delete a message by number.


Sounds easy, eh? This is *not* rocket-science so I think...

So I tried using /usr/bin/mail like this, which almost worked:


/usr/bin/mail -Nn -f $path_to_mailbox/INBOX < f 1-$
q
EOF


GIves me all the headers, but when run w/o a tty it thinks the screen
width is 80 chars and truncates the heck out of the subject text. It's
got no TTY, so it can't be using ioctl on the tty to get the width,
what the heck is it using? Probably it just defaults to 80 if it can't
get info from the TTY, in which case I'm screwed-- it just ain't
designed to work with no tty in that fashion.

The equivalents for delete & output work OK, just the table-of-contents
doesn't work here....

Am I the first one to ever want to do this? Or have I just not
encountered the tool that makes short work of this? Why does every
)#$(%^*@)(#^& mail reader in the world think you want to use their
f***ing interface (as if it's somehow especially brilliant) and not
think that you might want to do some of these things without the damn
interface? Isn't the philosophy of Unix to be modular so this kind of
thing should be easy?

Sure, I could write my own. However, in investigating this particular
problem, I find caution after caution about rolling-your-own mailbox
file locking stuff as every system does it different, yada yada... Ok,
FINE. So is there an existing BASIC mailbox manipulation program
that's not impossibly hamstrung by its design to be run with a tty? Or
do I have to reinvent the wheel?


IMHO-- not only *should* there be a low-level noninteractive mailbox
manipulation command, but the interface mail programs like pine and
elm, et. al., SHOULD ALL BE USING IT. Then if you wanted to plug in
some completely new way of storing and manipulating messages (like,
say, in a database instead of a flat-file) you could still use your
favorite front end to give you whatever interface you happen to like
(or none at all, as in my case).

But maybe there is one and I am just unaware of it...




--

Sync