#!/bin/sh - /usr/local/bin/gawk ' BEGIN { IGNORECASE=1 RS="" syntax_state=0 } NR==1 { if (!match($0, /\nContent-Type:/) || \ match($0, /\nContent-Type:(\n?[ \t])*(text\/plain|multipart)/)) { if (match($0, /\nContent-Type:(\n?[ \t])*multipart[^\n]*(\n[ \t][^\n]*)*/)) { boundary=substr($0, RSTART, RLENGTH) sub(/.*boundary=[ \t]*/, "", boundary) if (match(boundary, /^\"/)) { sub(/^\"/, "", boundary) sub(/\".*$/, "", boundary) } else sub(/[ \t].*$/, "", boundary) if (boundary!="") boundary="--" boundary } print print "" } else { while (match($0, /\nContent-[^:]+:/)) { content_spec=content_spec \ substr($0, match($0, /\nContent-[^:]+:[^\n]*(\n[ \t][^\n]*)*/), RLENGTH) sub(/\nContent-[^:]+:[^\n]*(\n[ \t][^\n]*)*/, "") } print print "Content-Type: text/plain" print "Content-Transfer-Encoding: 7bit" print "" print "** An attachment was eliminated. **" print "The content specification had been as follows:" print content_spec print "" exit } RS="\n" next } syntax_state==0 { if (boundary!="") { if (index($0, boundary)==1 && index($0, boundary "--")!=1) { uuencode=0 syntax_state=1 RS="" } } if (match($0, /^begin [0-7][0-7][0-7] [^ ]/)) { uuencode=1 uuencode_count=0 } else if (uuencode) { if (match($0, /^end$/)) uuencode=0 else if (match($0, /^[ -_`~]+$/)) { ++uuencode_count if (uuencode_count==4) { print "** UUENCODE data was suppressed. **" next } else if (uuencode_count>4) next } else uuencode=0 } print next } syntax_state==1 { if (!match($0, /(^|\n)Content-Type:/) || \ match($0, /(^|\n)Content-Type:(\n?[ \t])*text\/plain/)) { print print "" syntax_state=0 RS="\n" } else { print "Content-Type: text/plain" print "Content-Transfer-Encoding: 7bit" print "" print "** An attachment was eliminated. **" print "The content specification had been as follows:" print "" print print "" syntax_state=2 RS="\n" } next } syntax_state==2 { if (index($0, boundary "--")==1) { print syntax_state=0 } else if (index($0, boundary)==1) { print syntax_state=1 RS="" } next } '