53 lines
1.5 KiB
Python
Executable file
53 lines
1.5 KiB
Python
Executable file
#! /usr/bin/env python
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
# Licence : GPLv2
|
|
|
|
import sys, smtplib
|
|
sys.path.append('/usr/scripts/gestion')
|
|
|
|
from ldap_crans import smtpserv
|
|
from whos import machine_details, club_details, adher_details
|
|
from ldap_crans import adherent, club, machine
|
|
|
|
def mail_details (Objets, Subject = "Modifications dans la base LDAP", To = ['roots@crans.org'], From = 'roots@crans.org', no_ascii = False ) :
|
|
"""
|
|
Envoie un mail à toutes les personnes de la liste 'To', avec les
|
|
informations détaillées des objets contenus dans 'Objets'
|
|
(instances des classes adherent, machine ou club)
|
|
|
|
Si no_ascii est à True, on vire la couleur
|
|
"""
|
|
|
|
if not len(Objets) :
|
|
return True
|
|
|
|
base_txt_mail = """From: %(From)s
|
|
To: %(To)s
|
|
Subject: %(Subject)s
|
|
|
|
%(Text)s"""
|
|
|
|
details = []
|
|
|
|
for i in Objets :
|
|
if i.__class__ == machine :
|
|
details.append(machine_details(i))
|
|
elif i.__class__ == adherent :
|
|
details.append(adher_details(i))
|
|
elif i.__class__ == club :
|
|
details.append(club_details(i))
|
|
else :
|
|
ok = False
|
|
|
|
texte = '\n\n- - - - = = = = # # # # # # = = = = - - - -\n\n'.join(details)
|
|
|
|
if no_ascii :
|
|
import sre
|
|
texte = sre.sub('\x1b\[1;([0-9]|[0-9][0-9])m','',texte)
|
|
|
|
mail_complet = base_txt_mail % { 'From' : From, 'To' : ','.join(To), 'Subject' : Subject, 'Text' : texte.encode('iso8859-15') }
|
|
|
|
conn=smtplib.SMTP(smtpserv)
|
|
conn.sendmail(From, To , mail_complet)
|
|
conn.quit()
|