diff --git a/tools/findcommonlists b/tools/findcommonlists new file mode 100755 index 0000000000000000000000000000000000000000..0dd71849f0ee88fa1365e8e40821c2ae1777f2a7 --- /dev/null +++ b/tools/findcommonlists @@ -0,0 +1,42 @@ +#!/usr/bin/perl -w +# findcommonlists - given a list of addresses find the top lists with them subscribed +# NOTE: this script requires the current user has read access to the db +# Matt Taggart <taggart@riseup.net> 2019-08 + +$limit=20; +$count=0; + +if (!$ARGV[0]) { + print "usage: findcommonlists <file>\n"; + exit; +} + +$file=$ARGV[0]; + +$listsql='mysql -N --batch --database=sympa --execute "select list_subscriber,user_subscriber from subscriber_table, list_table where list_subscriber=list_table.name_list and list_table.status_list=\'open\'"'; + +open(ADDRESSES, "$file") or die "cannot open $file\n"; +open(LISTDUMP, "$listsql|") or die "cannot get dump of address+list pairs from database\n"; + +while (<ADDRESSES>) { + chomp; + $addresses{$_}=1; +} + +while (<LISTDUMP>) { + chomp; + # match list and sane address + m/^(.*)\t<?(.*\@.*?)>?\s*$/; + $list=$1; + $address=$2; + + if ( exists($addresses{$address}) ) { + $found{$list}++; + } +} + +foreach $list ( sort { $found{$b} <=> $found{$a} } keys %found) { + $count++; + print "$found{$list} $list\n"; + if ( $count == $limit ) {last;} +}