#!/bin/sh - /usr/local/bin/gawk ' BEGIN { getline seq < "/var/mlist/ML.seq" close("/var/mlist/ML.seq") ++seq print seq > "/var/mlist/ML.seq" close("/var/mlist/ML.seq") IGNORECASE=1 RS="" syntax_state=0 } NR==1 { gsub(/\nReturn-Receipt-To:[^\n]*(\n[ \t][^\n]*)*/, "") gsub(/\nErrors-To:[^\n]*(\n[ \t][^\n]*)*/, "") gsub(/\nDisposition-Notification-To:[^\n]*(\n[ \t][^\n]*)*/, "") if (match($0, /\nContent-Type:(\n?[ \t])*multipart[^\n]*(\n[ \t][^\n]*)*/)) { boundary=substr($0, RSTART, RLENGTH) sub(/.*boundary=[ \t]*\"?/, "", boundary) sub(/[\" \t\n].*$/, "", boundary) if (boundary!="") boundary="--" boundary } if (match($0, /\nSubject:(\n?[ \t])*(\[ML [0-9]+\] *)*Re:/)) gsub(/\nSubject:(\n?[ \t])*((\[ML [0-9]+\] *)*(Re: *)*)*/, \ "\nSubject: [ML " seq "] Re: ") else gsub(/\nSubject:(\n?[ \t])*(\[ML [0-9]+\] *)*/, \ "\nSubject: [ML " seq "] ") print if (!match($0, /\nSubject:/)) print "Subject: [ML " seq "] " print "" caption="[ML " seq "] (Reply-to-Me-Only)\n" if (boundary=="") { if (!match($0, /(^|\n)Content-Transfer-Encoding:/) || \ match($0, /(^|\n)Content-Transfer-Encoding:(\n?[ \t])*([78]bit|quoted-printable)/)) { print caption caption="" } } RS="\n" next } syntax_state==0 { if (boundary!="") { if (index($0, boundary)==1 && index($0, boundary "--")!=1) { syntax_state=1 RS="" } } print next } syntax_state==1 { if (caption!="") { if (!match($0, /(^|\n)Content-Type:/) || \ match($0, /(^|\n)Content-Type:(\n?[ \t])*text\/plain/)) { if (!match($0, /(^|\n)Content-Transfer-Encoding:/) || \ match($0, /(^|\n)Content-Transfer-Encoding:(\n?[ \t])*([78]bit|quoted-printable)/)) { print print "" print caption caption="" } } } else { print print "" } syntax_state=0 RS="\n" next } ' | /usr/lib/sendmail -oi -f owner-ML@DOMAIN ML-outgoing