pyulib/umail: possibilité de spécifier le type de contenu
This commit is contained in:
parent
14c2751d80
commit
4024b2a2c8
|
@ -57,6 +57,7 @@ def run_umail():
|
||||||
('c:', 'cc=', "Destinataires en copie"),
|
('c:', 'cc=', "Destinataires en copie"),
|
||||||
('b:', 'bcc=', "Destinataires en copie cachée"),
|
('b:', 'bcc=', "Destinataires en copie cachée"),
|
||||||
('a:', 'attach=', "Attacher un fichier"),
|
('a:', 'attach=', "Attacher un fichier"),
|
||||||
|
('t:', 'content-type=', "Spécifier le type de contenu du fichier"),
|
||||||
('f:', 'body=', "Spécifier un fichier contenant le corps du message"),
|
('f:', 'body=', "Spécifier un fichier contenant le corps du message"),
|
||||||
])
|
])
|
||||||
options, args = get_args(None, options, longoptions)
|
options, args = get_args(None, options, longoptions)
|
||||||
|
@ -68,6 +69,7 @@ def run_umail():
|
||||||
body = None
|
body = None
|
||||||
bodyfile = None
|
bodyfile = None
|
||||||
afiles = []
|
afiles = []
|
||||||
|
amimetypes = []
|
||||||
for option, value in options:
|
for option, value in options:
|
||||||
if option in ('-h', '--help'):
|
if option in ('-h', '--help'):
|
||||||
display_help()
|
display_help()
|
||||||
|
@ -80,6 +82,8 @@ def run_umail():
|
||||||
mbccs.extend(value.split(','))
|
mbccs.extend(value.split(','))
|
||||||
elif option in ('-a', '--attach'):
|
elif option in ('-a', '--attach'):
|
||||||
afiles.append(value)
|
afiles.append(value)
|
||||||
|
elif option in ('-t', '--content-type'):
|
||||||
|
amimetypes.append(value)
|
||||||
elif option in ('-f', '--body'):
|
elif option in ('-f', '--body'):
|
||||||
bodyfile = value
|
bodyfile = value
|
||||||
if bodyfile == "-":
|
if bodyfile == "-":
|
||||||
|
@ -117,9 +121,14 @@ def run_umail():
|
||||||
body = MIMEText('\n'.join(lines), 'plain')
|
body = MIMEText('\n'.join(lines), 'plain')
|
||||||
body.set_charset('utf-8')
|
body.set_charset('utf-8')
|
||||||
msg.attach(body)
|
msg.attach(body)
|
||||||
|
i = 0
|
||||||
for afile in afiles:
|
for afile in afiles:
|
||||||
if not path.isfile(afile): die("%s: Fichier introuvable" % afile)
|
if not path.isfile(afile): die("%s: Fichier introuvable" % afile)
|
||||||
mimetype, encoding = mimetypes.guess_type(afile)
|
mimetype = amimetypes[i:i + 1] and amimetypes[i] or None
|
||||||
|
encoding = None
|
||||||
|
i += 1
|
||||||
|
if mimetype is None:
|
||||||
|
mimetype, encoding = mimetypes.guess_type(afile)
|
||||||
if mimetype is None or encoding is not None:
|
if mimetype is None or encoding is not None:
|
||||||
mimetype = 'application/octet-stream'
|
mimetype = 'application/octet-stream'
|
||||||
maintype, subtype = mimetype.split('/', 1)
|
maintype, subtype = mimetype.split('/', 1)
|
||||||
|
|
Loading…
Reference in New Issue