Sun May 3 00:36:22 CEST 2020

mail(1) on NetBSD-8.x

One of the open problems shifting my "marshlabs" mail to hackett was how to deal with HTML mails. (I mean you, Paypal, and all the non-tech friends naively using webmail accounts and/or smart-phones.)

NetBSD's mail(1) (aka Mail and mailx) originates from Kurt Shoen's BSD-mail 8.1 but has been brought into the current millenium with basic support for MIME. It will

  1. take care of transfer-encoded messages (such as base64 or quoted-printable),
  2. lets you access/save individual parts of a MIME message, and
  3. lets you define handlers for specific MIME content-types.

(If you need to know: nope, OpenBSD and FreeBSD are still sticking to the orginal.)

The basic pipeline to process a message (as stated in the man page):

mail -> MIME-decoder -> MIME-hook -> pager -> screen

The man page also provides an example how to deal with HTML parts:

set mime-body-text-html="+/usr/pkg/bin/lynx -force_html -dump -stdin"

The "+" is a flag to prefer the HTML version over others in a multipart/alternative mail. The -dump option makes lynx not to behave interactively but to push the rendered message to stdout where it gets passed on to the pager stage of the pipeline.

Of course an interactive lynx would be much nicer. It would allow you to use any embedded links. However, just leaving off the -dump option didn't cut it. It works as bad as

lynx https://gaertner.de/~neitzel/nb/ | less

does -- you end up with just an empty page.

Today I dived further into the mail(1) manpage and found a workaround:

set mime-body-text-html="lynx -stdin". Before displaying an HTML mail, either set pager-off (NetBSD-mail-specific) or unset crt (old-school) to suppress the pager stage.

Lynx can be used interactively then. Toggling the pager off and on again, is a nuisance, though. It would be nicer to have that as another flag in the handler.

Strongly related: The currently defined flags for a mime-hook are:

  • !: use a sub-shell instead of doing an exec(3).
  • +: mark as preferred alternate type
  • -: disable the transfer-decoding stage

I already know that the "-" feature, i.e. an easy activation/deactivation of the transfer-encoding decoder is important. Gunnar Ritter's fabulous Heirloom-mailx (aka nail) provides two variations of the classic | command to filter a message: pipe (= |) and Pipe (preserve headers and MIME sections), and you can use set raw/unset raw to toggle the transfer decoding. I need all of these, and quite often.

With NetBSD, the | won't do the transfer-decoding, ever. You need to provide it yourself, as in

& | base64 -d | grep foo

You get the decoding but also the (abridged) mail header with this command:

& set enable-pipes
& p . | grep foo

I wasn't able to make the write command work with a |foo command destination.

Summary:

  1. I should hack bit more on the NetBSD mail source and add a "no-pager" flag for the mime-hooks.

  2. I need to install the metamail package and tie that in, too. It's the oldest MIME support kit I am aware of, and I have existing setups with various other MUAs. Thi should make more things work rather quickly, without relying on MUA-specific MIME-hooks.


Posted by neitzel | Permanent link | File under: learned, bsd