Mercurial > hg > python
comparison mailer.py @ 18:1cef0e5f5851
add -m for .sig
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Mon, 20 Jul 2020 11:21:30 +0100 |
parents | 2d7c91f89f6b |
children | 535e3327ed1b |
comparison
equal
deleted
inserted
replaced
17:6c9e371b0325 | 18:1cef0e5f5851 |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 '''Attempt at flexible mailout functionality | 2 '''Attempt at flexible mailout functionality |
3 Usage: mailer.py [-n] [-s] [-C cc string] [-c COLSPEC[,COLSPEC]*] [-B bcc string] [-b COLSPEC[,COLSPEC]*] [-S col[,col]*] [-a COLSPEC[,COLSPEC]*] [-p COLPAT]* [-SA file[,file]*] [-R reply-to] COLSPEC[,COLSPEC]* subject {addr-file|-} body-file | 3 Usage: mailer.py [-n] [-s] [-C cc string] [-c COLSPEC[,COLSPEC]*] [-B bcc string] [-b COLSPEC[,COLSPEC]*] [-S col[,col]*] [-a COLSPEC[,COLSPEC]*] [-p COLPAT]* [-SA file[,file]*] [-R reply-to] [-m .sigfilename] COLSPEC[,COLSPEC]* subject {addr-file|-} body-file |
4 | 4 |
5 Sends the body as a message from me with subject to destinations per | 5 Sends the body as a message from me with subject to destinations per |
6 lines in the addr-file selected by COLSPECs (to:) or -c/-b COLSPECs (Cc:/Bcc:) | 6 lines in the addr-file selected by COLSPECs (to:) or -c/-b COLSPECs (Cc:/Bcc:) |
7 | 7 |
8 -n for dry run, prints to stdout | 8 -n for dry run, prints to stdout |
16 -u Use unicode for attachments | 16 -u Use unicode for attachments |
17 -s for substitute into body | 17 -s for substitute into body |
18 -S for columns to substitute as such | 18 -S for columns to substitute as such |
19 -p for augmentation pattern for a column | 19 -p for augmentation pattern for a column |
20 -R for replyTo address | 20 -R for replyTo address |
21 -m for .sig file, None for none | |
21 | 22 |
22 COLSPEC is of the form a[:n[:f[:g]]] selects from addr-file, which must be tsv | 23 COLSPEC is of the form a[:n[:f[:g]]] selects from addr-file, which must be tsv |
23 a gives the column for an email address | 24 a gives the column for an email address |
24 n (optional) gives column for a name | 25 n (optional) gives column for a name |
25 f gives format for the name: FS, SF or S.F for | 26 f gives format for the name: FS, SF or S.F for |
247 filename=os.path.basename(att)) | 248 filename=os.path.basename(att)) |
248 msg.attach(atm) | 249 msg.attach(atm) |
249 | 250 |
250 dryrun=False | 251 dryrun=False |
251 replyTo=None | 252 replyTo=None |
253 sigfile=None | |
252 | 254 |
253 sys.argv.pop(0) | 255 sys.argv.pop(0) |
254 doSub=False | 256 doSub=False |
255 | 257 |
256 pats=[] | 258 pats=[] |
326 sys.argv.pop(0) | 328 sys.argv.pop(0) |
327 if sys.argv: | 329 if sys.argv: |
328 replyTo=sys.argv.pop(0) | 330 replyTo=sys.argv.pop(0) |
329 else: | 331 else: |
330 usage('reply to') | 332 usage('reply to') |
333 elif sys.argv[0]=='-m': | |
334 sys.argv.pop(0) | |
335 if sys.argv: | |
336 sigfile=sys.argv.pop(0) | |
337 else: | |
338 usage('sig file name') | |
331 elif sys.argv[0][0]=='-': | 339 elif sys.argv[0][0]=='-': |
332 print sys.argv | 340 print sys.argv |
333 usage() | 341 usage() |
334 else: | 342 else: |
335 break | 343 break |
365 except: | 373 except: |
366 usage('body: %s'%sys.exc_value) | 374 usage('body: %s'%sys.exc_value) |
367 else: | 375 else: |
368 usage('body') | 376 usage('body') |
369 | 377 |
370 try: | 378 signature=None |
371 sig=open("/home/ht/.signature","r") | 379 if sigfile!='None': |
372 signature=sig.read().rstrip() | 380 if sigfile is None: |
373 except: | 381 sigfile="/home/ht/.signature" |
374 signature=None | 382 try: |
383 sig=open(sigfile,"r") | |
384 signature=sig.read().rstrip() | |
385 except: | |
386 if sigfile!="/home/ht/.signature": | |
387 raise | |
375 | 388 |
376 CS=', ' | 389 CS=', ' |
377 body=bodyFile.read().rstrip() | 390 body=bodyFile.read().rstrip() |
378 if not dryrun: | 391 if not dryrun: |
379 mailer=smtplib.SMTP() | 392 mailer=smtplib.SMTP() |