From 583914a19dcb0c4d9ca9b8ddbbfe9c27ddeb942a Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Mon, 2 Dec 2013 14:45:33 +0100 Subject: [PATCH] =?utf8?q?Une=20fonction=20pour=20pouvoir=20taper=20sur=20?= =?utf8?q?les=20gmail=20users=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- mailman_bad_guys.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mailman_bad_guys.py b/mailman_bad_guys.py index ba2942b..3005445 100755 --- a/mailman_bad_guys.py +++ b/mailman_bad_guys.py @@ -13,6 +13,7 @@ import socket if socket.gethostname() != "redisdead": print("Not on redisdead, might not work") +import re import sys sys.path.append("/var/lib/mailman/bin") @@ -38,8 +39,10 @@ def list_members(ml): moderators = [i for i in ml.moderator] return [members, admins, moderators] -def get_all(): +def get_all(dico=None): """Retourne un dico nom_de_ml -> [membres, admins, moderateurs]""" + if dico: + return dico return {n: list_members(n) for n in list_lists()} def get_field_from_mail(mail, fieldno, all=None): @@ -85,6 +88,20 @@ def exterminate_this_guy(bad_guy, dico=None): else: print("No mailing list found") +def find_modadmin_domain(domain, dico=None): + """Retourne un dico ``mail`` -> ``[liste de MLs dont mail est admin, liste de MLs dont mail est modéro]`` + où mail est un mail dont la partie domaine matche la regexp domain.""" + all = get_all(dico) + # On récupère toutes les adresses d'admins et de modéros dans le même panier + suspects = sum([ml[1] + ml[2] for ml in all.values()], []) + suspects = list(set(suspects)) + # On matche + regexp = re.compile(".*@%s" % domain) + coupables = [mail for mail in suspects if regexp.match(mail)] + # On retrouve les MLs correspondantes + coupables = {mail : [get_admins_from_mail(mail, all), get_moderators_from_mail(mail, all)] for mail in coupables} + return coupables + if __name__ == "__main__": bad_guy = sys.argv[1].decode("utf-8").lower() exterminate_this_guy(bad_guy) -- 2.39.2