Pages: Welcome | Projects

Pipe that rude HTML

2015/12/10
Tags: [ wtf ]

Good software is flexible, and this is a Good Thing. Flexibility however requires a bit of discipline.

Take the tar archives for instance. Tar was born in the magnetic tapes era, but it is flexible and general enough, so it is still alive, and used pretty much everywhere there's a package to install.

Tar will cowardly refuse to create empty archives (just try and see), but it will not forbid you from creating what I call rude archives. I'm talking about tarballs which will extract everything in the current directory, polluting it with a flat hierarchy of files. By contrast, a well behaved tarball named something.tar will prefix every file with a something/ directory.

If you are familiar with Git, try using git archive without the --prefix option (or forgetting the trailing / in its argument!).

If Tar forced inner files to have a prefix, it could not be used for installing stuff on the / of your Unix system. So it's not a bad thing itself. The evil part is in the user (or program) who will package a rude tarball. You open it in your $HOME and you are full of files everywhere, together with your regular files and your dotfiles. What a mess.

Emails are similar: an awesome example of textual protocol which never disappears, not even in the smartphone era. One day (in the obscure times of the Browser wars, probably?), some clever guys decided that we should be able to put anything in it. Like HTML. Maybe with some javascript. And MSWord attachments! With macro viruses! Or README.doc.exe. Funny times.

At least those clever guys went for MIME! But speaking of discipline, nobody prevents you — developer — from getting the MIME wrapping part wrong. Or from skipping it entirely! I especially love when the latest noob goes for:

That sure helps my poor mailcap! And how lovely when the text/html part is entirely missing while the text/plain contains HTML, full force!

Life is increasingly complicated for the command line lovers!

This inspired me a sad ballad named A horrible, horrible script. It goes like this:

#!/bin/sh

set -e
: ${BROWSER:?"No BROWSER in env"}

fname=`mktemp --suffix .html`
echo $fname
cat >$fname
[ -s $fname ] && $BROWSER $fname || echo "No data!" 1>&2
rm $fname

Fun fact, I can simply pipe the offending mail into the ballad, and have it shown in my w3m.

Credits: Thanks mutt for sucking less, and giving me the | key.