From e09611236b7289ded6444012abcb55710bdb99f1 Mon Sep 17 00:00:00 2001 From: chove Date: Wed, 12 Jan 2005 19:54:12 +0100 Subject: [PATCH] petite modif pour que le mail soit envoy depuis l'adresse du cableur darcs-hash:20050112185412-4ec08-8a5804614b636c28fca83c6a4fb78c15b4fa297c.gz --- admin/mail_invalide.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/admin/mail_invalide.py b/admin/mail_invalide.py index b57215bc..8640563b 100755 --- a/admin/mail_invalide.py +++ b/admin/mail_invalide.py @@ -4,11 +4,21 @@ import sys,os,string,time,locale locale.setlocale(locale.LC_ALL,'') +# Import de la base de données sys.path.append('/usr/scripts/gestion') from ldap_crans import crans_ldap +db = crans_ldap() + +# Détermination de l'uid du cableur +uid = os.getenv('SUDO_UID') +if not uid : + print "Impossible de déterminer l'utilisateur" + sys.exit(1) +cableur = db.search('uidNumber=%s' % os.getenv('SUDO_UID'),'w')['adherent'][0] os.chdir("/usr/scripts/admin/") +# Nom des fichiers headers = "mail_invalide_debut.tex" texsrc = "mail_invalide_texte.tex" pdf = time.strftime("mail_invalide-%d-%m-%Y_%Hh%M.pdf",time.localtime(time.time())) @@ -38,7 +48,7 @@ Voici les fiches d'avertissement pour les informer que l'adresse mail qu'ils ont fourni n'est pas valide.\n\n \ Il faut donc imprimer les feuilles et les mettre dans les boîtes aux\n \ lettres correspondantes.\n\n" -text += "-- \nUn script exécuté par %s\n\n" % os.getlogin() +text += "-- \nUn script exécuté par %s\n\n" % cableur.Nom().encode('iso8859-1') text += os.popen("/usr/games/fortune",'r').read() os.system("cp %s %s" % (headers, mailtex)) @@ -101,8 +111,8 @@ from email.Encoders import encode_base64 msg = MIMEMultipart() msg['Subject'] = "Fiche(s) d'avertissement de mail invalide - %s" % time.strftime("%d/%m/%Y",time.localtime(time.time())) -msg['From'] = "Bureau " -msg['To'] = "bureau@crans.org" +msg['From'] = "%s <%s>" % (cableur.Nom(), cableur.mail()) +msg['To'] = "Bureau " msg['Cc'] = "Disconnect Team " # msg.preamble = text # Guarantees the message ends in a newline @@ -127,9 +137,7 @@ while (1 == 1): # Send the email via our own SMTP server. s = smtplib.SMTP() s.connect() - s.sendmail('bureau@crans.org', - ('bureau@crans.org','disconnect@crans.org'), - msg.as_string()) + s.sendmail(msg['From'], (msg['To'],msg['Cc']), msg.as_string()) s.close() print "Mail envoyé !" break