It is also possible the script has bugs. :) I don't have a large amount
of email threads archived to test it on. Weird things will happen with
really nasty message-id, in-reply-to, and references headers, but what
I've written probably sanitizes those as well as most other software.
*sigh* There's a bug. Some messages don't display under certain
conditions.
Ok, here's a fix. Firstly, the main bug I observed appears to have been
a bug in an old version of gawk, exposed by the unnecessarily large
input lines spin uses. I've moved the getline call to the end, which
works around this. Secondly, there was a real bug, but it would have
taken loop-causing headers to expose it, so it probably didn't happen
to anyone who might have tried the script so far.
I've also removed the hardcoded paths for cat and echo I had before (a
habit of mine), but the other paths remain and need to be changed for
each site. Any other changes in the script you see are just matters of
style.
Some feedback would be nice. I like to think the script works. :)
Cheers,
- Joel
#!/bin/sh
AWK=/usr/bin/awk
SCANLINE_FORMAT=`cat /etc/nmh/scan.default`
TERMINAL_WIDTH=`echo "$TERMCAP" | $AWK 'BEGIN { RS=":"; FS="#" } "co"==$1 {
cols=$2 } END { print cols?cols:80 }'`
/usr/local/bin/scan $* -width 4096 -format "<fake-root-id> %{references}
%{in-reply-to} %{message-id}\n$SCANLINE_FORMAT\n" | $AWK '
function pruneshow(x, prefix, i) {
if(x in scanline) {
print prefix substr(scanline[x], 1, width-1-length(prefix))
prefix=prefix " "
}
for(i=0; i<lastkid[x]; i++)
if((x, i) in kids)
pruneshow(kids[x, i], prefix)
}
BEGIN {
scanline["<fake-root-id>"]="THIS SHOULD NOT APPEAR"
}
{
i=0
for(j=1; j<=NF; j++)
if("<"==substr($j, 1, 1) && ">"==substr($j, length($j),
length($j)))
$++i=$j
NF=i
for(midsuffix=""; ($NF midsuffix) in scanline; midsuffix++)
;
$NF=$NF midsuffix
if($NF in parent) {
delete kids[parent[$NF], kidnumber[$NF]]
delete parent[$NF]
}
for(i=1; i<NF; i++)
if(!($(i+1) in parent)) {
for(ancestor=$i; ancestor in parent;
ancestor=parent[ancestor])
;
if(ancestor==$(i+1))
$i="<fake-root-id>"
kids[parent[$(i+1)]=$i,
kidnumber[$(i+1)]=lastkid[$i]++]=$(i+1)
}
getline scanline[$NF]
}
END {
for(i=0; i<lastkid["<fake-root-id>"]; i++)
if(("<fake-root-id>", i) in kids)
pruneshow(kids["<fake-root-id>", i])
}
' width=$TERMINAL_WIDTH
_______________________________________________
Nmh-workers mailing list
Nmh-workers@nongnu.org
http://lists.nongnu.org/mailman/listinfo/nmh-workers