From c326fbcec802ba49c2b5e4761691a5a3338c3b71 Mon Sep 17 00:00:00 2001
From: Matt Taggart <taggart@riseup.net>
Date: Thu, 8 Aug 2019 11:19:42 -0700
Subject: [PATCH] new script to determine which lists a list of addresses are
 on

---
 tools/findcommonlists | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100755 tools/findcommonlists

diff --git a/tools/findcommonlists b/tools/findcommonlists
new file mode 100755
index 0000000..0dd7184
--- /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;}
+}
-- 
GitLab