#!/opt/local/bin/gawk -f # # $Id: filtrage.awk 552 2006-05-26 11:46:13Z patpro $ # # header filtering script derived from `mailparser` by Laurent Sebilleau # # a .forward (for example), feeds the email message into the script # "Received:" headers are aggregated and processed to compute inter-server delays # the output is transmitted to email_delay_tracking shell script for further # processing. BEGIN { flag=0; mdat=""; i=0; } (flag > 0) { # used for catching folded lines in headers if ($0 ~ /^[\t\ ]/) { if (flag == 5) {sub(/^[\t\ ]*/,"",$0); mdat = mdat " " $0;} next; } #print mdat; # we ensure that we don't process headers added by local delivery (pop and after) if (match(mdat,/by MACHINE-D-ANALYSE/)==0 && match(mdat,/fetchmail/)==0) { # process and store date into an array coupe=match(mdat,/; ?[a-zA-Z]*, [0-9]* [a-zA-Z]* 20[0-9][0-9] [012][0-9]:[0-6][0-9]:[0-6][0-9] [+0-9]* \([A-Z]*\)/) madate=substr(mdat,coupe); sub(/^; ?/,"",madate); madate=convDate(madate); rec[i]=madate; } else { i=i-1 } # reset value mdat=""; # check #print rec[i]; # set flag to 0 flag = 0; } /^[Rr]eceived:/ { # Received: header to catch sub(/^[Rr]eceived:/,""); i=i+1 if (mdat == "") { # mdat = $0; flag = 5; } next; } END { j=1; listing=""; while (jnum table monthnum["Jan"]="01"; monthnum["Feb"]="02"; monthnum["Mar"]="03"; monthnum["Apr"]="04"; monthnum["May"]="05"; monthnum["Jun"]="06"; monthnum["Jul"]="07"; monthnum["Aug"]="08"; monthnum["Sep"]="09"; monthnum["Oct"]="10"; monthnum["Nov"]="11"; monthnum["Dec"]="12"; # Date: Thu, 13 Feb 2003 23:31:30 +0100 split(datebrut, dateelem, " "); day = dateelem[2]; # "13" if (length(day) == 1) { day = "0" day;} month = monthnum[(dateelem[3])]; # Feb -> "02" year = dateelem[4]; # "2003" split(dateelem[5], timeelem, ":"); hour = timeelem[1]; # "23" if (length(hour) == 1) { hour = "0" hour;} min = timeelem[2]; # "31" if (length(min) == 1) { min = "0" min;} sec = timeelem[3]; # "30" if (length(sec) == 1) { sec = "0" sec;} # AAAA MM JJ HH MM SS return (mktime(year " " month " " day " " hour " " min " " sec)); }