#!/bin/sh

mmencode () { perl -0777pne '
    $_=unpack("B*",$_); s/$/0000/; s/.{6}/00$&/g;
    s/((.{8})*).*/pack("B*",$1)/e; tr[\0-\77][A-Za-z0-9+/];
    s/$/===/; s/((....)*).*/$1/; s/.{76}/$&\n/g;' $*
}

t=/tmp/mailjpeg$$

echo "To: $2
Bcc: $USER
Subject: $3
MIME-Version: 1.0
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=$1
Content-Description: file:$1
Content-Location: file:$1

`mmencode $1`" > $t

{ 
	xterm -e less $t 
	/usr/lib/sendmail -t < $t
	rm $t
} &

