intégration de umail.py
utiliser pywrapper pour wofixsql.py
This commit is contained in:
parent
f3afc12fe8
commit
83bf44daf8
|
@ -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
|
||||
|
||||
|
|
|
@ -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] <subject> 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()
|
Loading…
Reference in New Issue