#!/bin/sh # # Copyright (c) 2010 Mitzyuki IMAIZUMI, All rights reserved. # $Id: mhmime,v 1.1 2010/08/31 11:12:18 mitz Exp $ # mhn=/usr/local/bin/mhn ( rm $1 awk 'BEGIN{ types["jpg"] = "image/jpeg" types["jpeg"] = "image/jpeg" types["gif"] = "image/gif" types["mp3"] = "audio/mp3" types["mpg"] = "video/mpeg" types["mpeg"] = "video/mpeg" types["txt"] = "text/plain" } { if($1 ~ /^#/) if($1 ~ /^#MIME/){ filename = substr($2, match($2, "/[^/]*$")+1, length($2)) if(NF > 2) for(i=3; i<=NF; i++) comment = comment $i else comment = filename i = split($2, array, ".") if((type = types[array[i]]) == "") type = "application/octet-stream" printf("#%s; name=%s [%s] %s\n", type, filename, comment, $2) } else printf("#%s\n", $0); else printf("%s\n", $0) }' > $1 ) < $1 ${mhn} $@