From 83bf44daf82a574378950441483e22ba38b882e4 Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Thu, 14 Nov 2013 10:05:10 +0400 Subject: [PATCH] =?UTF-8?q?int=C3=A9gration=20de=20umail.py=20utiliser=20p?= =?UTF-8?q?ywrapper=20pour=20wofixsql.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/uinst/conf | 2 +- pyulib/src/uapps/umail.py | 59 +++++++++++++++++++++ wofixsql.py => pyulib/src/uapps/wofixsql.py | 0 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100755 pyulib/src/uapps/umail.py rename wofixsql.py => pyulib/src/uapps/wofixsql.py (100%) diff --git a/lib/uinst/conf b/lib/uinst/conf index 9e4ad35..228a0e3 100644 --- a/lib/uinst/conf +++ b/lib/uinst/conf @@ -8,7 +8,7 @@ cd "$scriptdir/../.." rm -rf pyulib/{build,devel,migrate,test} # liens pour les scripts python -for i in plver plbck uencdetect urandomize; do +for i in plver plbck uencdetect urandomize umail wofixsql; do ln -s lib/pywrapper "$i" done diff --git a/pyulib/src/uapps/umail.py b/pyulib/src/uapps/umail.py new file mode 100755 index 0000000..c77912d --- /dev/null +++ b/pyulib/src/uapps/umail.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 mode: python -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 + +u"""%(scriptname)s: Afficher un mail correctement encodé pour son envoi + +USAGE + %(scriptname)s [options] [-f from] recipients... <<<"body" | /usr/sbin/sendmail -i""" + +import os, sys +from os import path + +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText +from email.header import Header + +from ulib.all import * + +def display_help(): + uprint(__doc__ % globals()) + +def run_pyumail(): + options, longoptions = build_options([ + ('h', 'help', "Afficher l'aide"), + ('f:', 'from=', "Spécifier l'expéditeur"), + ]) + options, args = get_args(None, options, longoptions) + mfrom = 'no-reply@univ-reunion.fr' + subject = None + mtos = [] + body = None + for option, value in options: + if option in ('-h', '--help'): + display_help() + sys.exit(0) + elif option in ('-f', '--from'): + mfrom = value + + if not args[0:1]: die("Vous devez spécifier le sujet") + subject = args[0] + if not args[1:]: die("Vous devez spécifier les destinataires") + mtos = args[1:] + + lines = BLines() + lines.readlines(sys.stdin) + + msg = MIMEMultipart() + #msg.set_charset('utf-8') + msg['From'] = mfrom + msg['To'] = ', '.join(mtos) + msg['Subject'] = Header(subject, 'utf-8') + if lines: + body = MIMEText('\n'.join(lines), 'plain') + body.set_charset('utf-8') + msg.attach(body) + + print msg.as_string() + +if __name__ == '__main__': + run_pyumail() diff --git a/wofixsql.py b/pyulib/src/uapps/wofixsql.py similarity index 100% rename from wofixsql.py rename to pyulib/src/uapps/wofixsql.py