comparison mailer.py @ 4:2d7c91f89f6b

later ecclerig version
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 09 Mar 2020 17:38:52 +0000
parents e07789816ca5
children 1cef0e5f5851 b1ec44d254c6
comparison
equal deleted inserted replaced
3:26d9c0308fcf 4:2d7c91f89f6b
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]* 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] 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
15 -SA for static attachment files 15 -SA for static attachment files
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 21
21 COLSPEC is of the form a[:n[:f[:g]]] selects from addr-file, which must be tsv 22 COLSPEC is of the form a[:n[:f[:g]]] selects from addr-file, which must be tsv
22 a gives the column for an email address 23 a gives the column for an email address
23 n (optional) gives column for a name 24 n (optional) gives column for a name
24 f gives format for the name: FS, SF or S.F for 25 f gives format for the name: FS, SF or S.F for
245 atm.add_header('Content-Disposition','attachment', 246 atm.add_header('Content-Disposition','attachment',
246 filename=os.path.basename(att)) 247 filename=os.path.basename(att))
247 msg.attach(atm) 248 msg.attach(atm)
248 249
249 dryrun=False 250 dryrun=False
251 replyTo=None
252
250 sys.argv.pop(0) 253 sys.argv.pop(0)
251 doSub=False 254 doSub=False
255
252 pats=[] 256 pats=[]
253 someExpand=False 257 someExpand=False
254 codec='iso-8859-1' 258 codec='iso-8859-1'
255 staticAtts=[] 259 staticAtts=[]
256 while sys.argv: 260 while sys.argv:
316 sys.argv.pop(0) 320 sys.argv.pop(0)
317 if sys.argv: 321 if sys.argv:
318 pats.append(sys.argv.pop(0)) 322 pats.append(sys.argv.pop(0))
319 else: 323 else:
320 usage('pat') 324 usage('pat')
325 elif sys.argv[0]=='-R':
326 sys.argv.pop(0)
327 if sys.argv:
328 replyTo=sys.argv.pop(0)
329 else:
330 usage('reply to')
321 elif sys.argv[0][0]=='-': 331 elif sys.argv[0][0]=='-':
322 print sys.argv 332 print sys.argv
323 usage() 333 usage()
324 else: 334 else:
325 break 335 break
404 for att in staticAtts: 414 for att in staticAtts:
405 doAtt(msg,att,codec) 415 doAtt(msg,att,codec)
406 if attCols: 416 if attCols:
407 for att in addrList(addrFields,attCols,True): 417 for att in addrList(addrFields,attCols,True):
408 doAtt(msg,att,codec) 418 doAtt(msg,att,codec)
419 if replyTo is not None:
420 msg["Reply-To"]=replyTo
409 if dryrun: 421 if dryrun:
410 print recips 422 print recips
423 print msg.keys()
411 print msg.as_string() 424 print msg.as_string()
412 exit() 425 exit()
413 print "mailing to %s"%recips 426 print "mailing to %s"%recips
414 mailer.sendmail("ht@inf.ed.ac.uk",recips,msg.as_string()) 427 mailer.sendmail("ht@inf.ed.ac.uk",recips,msg.as_string())
415 mailer.quit() 428 mailer.quit()