nmh-workers
[Top] [All Lists]

sorting uniquely by message-id

2020-09-18 16:48:15

Due to the way that IETF lists and aliases work, I often get two, three
sometimes four copies of an email.  I attach a mh-e view of a thread below.
I really want to just keep the copy that went through the list, because
that's the one that went into the public archive, and replies will work
better on that version.
But, sometimes some of the messages get copied to me only, and can't lose them.

I can see which is which mostly, because I've added "List-Id" to my scan
output that mh-e shows me.

I started thinking that I could do something with:
  sortm -textfield message-id:
  
but then I realized I don't want to change the order of the folder.
Instead, I am doing:

  scan -format '%5(msg),%{message-id},%<(addr{List-Id})%>' +inbox'

and then process this with Perl to do the right thing....
I think that I ought to use something other than , that can't appear in any
of the relevant fields.  ASCII defined this "FS" character (ASCII 29 or
something), and I wonder why we don't use it more often...  i wonder if the
format spec ought to make this easily accessible?

Before:
 142 -09/16 ["Rob Wilton \(r]     asdf.ietf.or Re: [Asdf] Robert Wilton's Block 
 156 %09/16   [To:"Rob Wilton ]     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block 
 164 %09/17     [Carsten Bormann]     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block 
 175 %09/17     ["Rob Wilton (rw]                  RE: [Asdf] Robert Wilton's 
Block 
 176 %09/17   ["Rob Wilton (rw]                  RE: [Asdf] Robert Wilton's 
Block 
 177 %09/17     <"Rob Wilton \(r>     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block 
 178 %09/17     [Carsten Bormann]                  Re: [Asdf] Robert Wilton's 
Block 
 179 %09/17       <Carsten Bormann>     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block 
 187 %09/17       [David Kemp     ]                  Re: [Asdf] Robert Wilton's 
Block 
 188 %09/17         <David Kemp     >     asdf.ietf.or Re: [Asdf] Robert 
Wilton's Block 
 200 %09/17         [Carsten Bormann]                  Re: [Asdf] Robert 
Wilton's Block 
 201 %09/17           <Carsten Bormann>     asdf.ietf.or Re: [Asdf] Robert 
Wilton's Block 
 180 %09/17   <"Rob Wilton (rw>                  RE: [Asdf] Robert Wilton's 
Block 
 181 %09/17     <"Rob Wilton \(r>     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block 
 184+%09/17     [Carsten Bormann]     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block 
 185 %09/17       <Carsten Bormann>                  Re: [Asdf] Robert Wilton's 
Block 
 189 %09/17       ["Rob Wilton (rw]                  RE: [Asdf] Robert Wilton's 
Block 
 190 %09/17         <"Rob Wilton \(r>     asdf.ietf.or Re: [Asdf] Robert 
Wilton's Block 
 193 %09/17         [Alexander Pelov]                  Re: [Asdf] Robert 
Wilton's Block 
 194 %09/17           <Alexander Pelov>     asdf.ietf.or Re: [Asdf] Robert 
Wilton's Block 
 196 %09/17         [Barry Leiba    ]                  Re: [Asdf] Robert 
Wilton's Block 
 197 %09/17           <Barry Leiba    >                  Re: [Asdf] Robert 
Wilton's Block 
 198 %09/17           ["Rob Wilton \(r]     asdf.ietf.or Re: [Asdf] Robert 
Wilton's Block 
 199 %09/17             <"Rob Wilton (rw>                  RE: [Asdf] Robert 
Wilton's Block 
 327 %09/18           [Carsten Bormann]                  Re: [Asdf] Robert 
Wilton's Block 

After:

 142 -09/16 ["Rob Wilton \(r]     asdf.ietf.or Re: [Asdf] Robert Wilton's Block 
on charter-ietf-as
 156 %09/16   [To:"Rob Wilton ]     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block on charter-ietf-
 164 %09/17     [Carsten Bormann]     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block on charter-iet
 175 %09/17     ["Rob Wilton (rw]                  RE: [Asdf] Robert Wilton's 
Block on charter-iet
 177 %09/17   ["Rob Wilton \(r]     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block on charter-ietf-
 179 %09/17     [Carsten Bormann]     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block on charter-iet
 188 %09/17       [David Kemp     ]     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block on charter-i
 201 %09/17         [Carsten Bormann]     asdf.ietf.or Re: [Asdf] Robert 
Wilton's Block on charter
 181 %09/17   <"Rob Wilton \(r>     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block on charter-ietf-
 185 %09/17     [Carsten Bormann]                  Re: [Asdf] Robert Wilton's 
Block on charter-iet
 190 %09/17       ["Rob Wilton \(r]     asdf.ietf.or Re: [Asdf] Robert Wilton's 
Block on charter-i
 194 %09/17         [Alexander Pelov]     asdf.ietf.or Re: [Asdf] Robert 
Wilton's Block on charter
 197 %09/17         [Barry Leiba    ]                  Re: [Asdf] Robert 
Wilton's Block on charter
 199 %09/17           ["Rob Wilton (rw]                  RE: [Asdf] Robert 
Wilton's Block on chart
 327 %09/18           [Carsten Bormann]                  Re: [Asdf] Robert 
Wilton's Block on chart

the script:

#!/usr/bin/perl

my %msglist;
my %msgnum;
my @todelete;

open(MESSAGES, "scan -format '%5(msg),%{message-id},%<(addr{List-Id})%>' 
+inbox". "|");
while(<MESSAGES>) {
    chomp;
    my($msgnum, $msgid, $listid) = split(/,/);

    #print STDERR "processing: $_\n";
    #print STDERR " -> $msgnum, $msgid, $listid\n";
    
    if(defined($msgnum{$msgid})) { # it is a duplicate, see which one to keep.
        #print "$msgnum seen $msgid before at ${msgnum{$msgid}}\n";

        if(defined($msglist{$msgid})) { # keep the other one, delete this one!
            #print "Keeping other one: $msgnum{$msgid} not $msgnum\n";
            @todelete << $msgnum;
        } else {
            #print "Keeping  this one: $msgnum not $msgnum{$msgid}\n";
            # delete the other one, keep this one.
            $msglist{$msgid} = $listid;
            push(@todelete, $msgnum{$msgid});
        }
    } else {
        $msgnum{$msgid} = $msgnum;
    }
}

print "rmm +inbox", join(" ", @todelete), "\n";


-- 
]               Never tell me the odds!                 | ipv6 mesh networks [ 
]   Michael Richardson, Sandelman Software Works        | network architect  [ 
]     mcr@sandelman.ca  http://www.sandelman.ca/        |   ruby on rails    [ 
        

Attachment: signature.asc
Description: PGP signature

<Prev in Thread] Current Thread [Next in Thread>