#!/bin/sh - # # w-filter Ver1.03 # $Id: w-filter,v 1.5 2004/08/08 13:38:10 umesan Exp $ # # By T.Wakaume # /usr/bin/gawk ' BEGIN { IGNORECASE=1 status=0 } #{ # print status "" NF #} status==0 && NF==0 { print status=1 next } status==0 { if(match($1, /Content-Type:/) && match($0, /multipart/)) { if(match($0, /boundary.*/)) { boundary=substr($0, RSTART, RLENGTH) sub(/.*boundary=[ \t]*/, "", boundary) if(match(boundary, /^\"/)) { sub(/^\"/, "", boundary) sub(/\".*$/, "", boundary) } else { sub(/[ \t].*$/, "", boundary) } } else { getline if(match($0, /boundary.*/)) { 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 "Content-Type: text/plain; charset=ISO-2022-JP" next } else { if(match($1, /Disposition-Notification-To:/)) { next } } print } status==6 { if(index($0, boundary2 "--")==1) { status=3 next } if(index($0, boundary2)!=1) { print next } status=5 } status==5 { if(index($0, boundary2 "--")==1) { status=3 next } if(index($0, boundary2)==1) { getline if(match($1, /Content-Type:/) && match($0, /text\/plain/)) { while(NF!=0) { getline } status = 6 } else { print "" print "** An attachment was eliminated. **" print "The content specification had been as follows:" print "" print while(NF!=0) { getline print } print "" } } } status!=0 && status!=9 && status!=5 && status!=6{ if(boundary=="") { status=9 } # if(index($0, "This is a multi-part message in MIME format.")) { next } # if(index($0, boundary)==1 && index($0, boundary "--")!=1) { getline if(match($1, /Content-Type:/) && match($0, /text\/plain/)) { if(status==1 || status==3) { status=2 } else { status=4 } } else if(match($1, /Content-Type:/) && match($0, /multipart/)) { status = 5 } else { if(status==1) { status=3 } else { status=4 } } pre = "" if(status==2) { while(NF!=0) { if(match($0, /name.*/)) { status=3 break } if(pre == "") { pre = $0 } else { pre = (pre "\n" $0) } getline } print "" } if(status==3 || status==4) { print "" print "** An attachment was eliminated. **" print "The content specification had been as follows:" print "" if(pre != "") { print pre } print while(NF!=0) { getline print } print "" } else if(status==5) { while(NF!=0) { if(match($0, /boundary.*/)) { boundary2=substr($0, RSTART, RLENGTH) sub(/.*boundary=[ \t]*/, "", boundary2) if(match(boundary2, /^\"/)) { sub(/^\"/, "", boundary2) sub(/\".*$/, "", boundary2) } else { sub(/[ \t].*$/, "", boundary2) } break } getline } if (boundary2!="") { boundary2="--" boundary2 } } else if(status==2) { } else { while(NF!=0) { getline if(status==2 && match($0, /name=.*/)) { status=1 } } print "" } next } } status==2 { print } status==9 { print } '