maj doc
ne faire un multipart que si c'est nécessaire
This commit is contained in:
		
							parent
							
								
									b29e4f21b1
								
							
						
					
					
						commit
						677750f50b
					
				@ -5,6 +5,11 @@ u"""%(scriptname)s: Afficher un mail correctement encodé pour son envoi
 | 
			
		||||
 
 | 
			
		||||
USAGE
 | 
			
		||||
    %(scriptname)s [options] <SUBJECT> RECIPIENTS... <<<"BODY" | /usr/sbin/sendmail -i
 | 
			
		||||
    %(scriptname)s [options] <SUBJECT> RECIPIENTS... <<<"BODY" | /usr/sbin/sendmail RECIPIENTS...
 | 
			
		||||
 | 
			
		||||
La deuxième forme est pour les implémentations compatible de sendmail qui
 | 
			
		||||
ignorent l'argument -i. Il faut alors spécifier tous les destinataires en
 | 
			
		||||
argument.
 | 
			
		||||
 | 
			
		||||
OPTIONS
 | 
			
		||||
    -f FROM
 | 
			
		||||
@ -19,6 +24,8 @@ OPTIONS
 | 
			
		||||
    BODY
 | 
			
		||||
        Corps du mail"""
 | 
			
		||||
 | 
			
		||||
DEFAULT_FROM = 'no-reploy@univ-reunion.fr'
 | 
			
		||||
 | 
			
		||||
import i_need_py25 # nécessite module email version 4.0
 | 
			
		||||
 | 
			
		||||
import os, sys, mimetypes
 | 
			
		||||
@ -45,7 +52,7 @@ def run_umail():
 | 
			
		||||
        ('a:', 'attach=', "Attacher un fichier"),
 | 
			
		||||
        ])
 | 
			
		||||
    options, args = get_args(None, options, longoptions)
 | 
			
		||||
    mfrom = 'no-reply@univ-reunion.fr'
 | 
			
		||||
    mfrom = DEFAULT_FROM
 | 
			
		||||
    subject = None
 | 
			
		||||
    mtos = []
 | 
			
		||||
    body = None
 | 
			
		||||
@ -67,11 +74,14 @@ def run_umail():
 | 
			
		||||
    lines = BLines()
 | 
			
		||||
    lines.readlines(sys.stdin)
 | 
			
		||||
 | 
			
		||||
    if not afiles:
 | 
			
		||||
        # Sans attachement, faire un message simple
 | 
			
		||||
        msg = MIMEText('\n'.join(lines), 'plain')
 | 
			
		||||
        msg.set_charset('utf-8')
 | 
			
		||||
    else:
 | 
			
		||||
        # Il y a des attachement, faire un multipart
 | 
			
		||||
        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')
 | 
			
		||||
@ -113,6 +123,9 @@ def run_umail():
 | 
			
		||||
                encoders.encode_base64(part)
 | 
			
		||||
            part.add_header('Content-Disposition', 'attachment', filename=path.basename(afile))
 | 
			
		||||
            msg.attach(part)
 | 
			
		||||
    msg['From'] = mfrom
 | 
			
		||||
    msg['To'] = ', '.join(mtos)
 | 
			
		||||
    msg['Subject'] = Header(subject, 'utf-8')
 | 
			
		||||
 | 
			
		||||
    Generator(sys.stdout).flatten(msg)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user