[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nmh-workers] A script for threading

From: Joel Reicher
Subject: Re: [Nmh-workers] A script for threading
Date: Mon, 16 Jan 2006 19:45:48 +1100

> > 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

Some feedback would be nice. I like to think the script works. :)


        - Joel


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)

        scanline["<fake-root-id>"]="THIS SHOULD NOT APPEAR"

        for(j=1; j<=NF; j++)
                if("<"==substr($j, 1, 1) && ">"==substr($j, length($j), 
        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; 
        getline scanline[$NF]

        for(i=0; i<lastkid["<fake-root-id>"]; i++)
                if(("<fake-root-id>", i) in kids)
                        pruneshow(kids["<fake-root-id>", i])


reply via email to

[Prev in Thread] Current Thread [Next in Thread]