35 lines
1.2 KiB
Python
Executable File
35 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import urllib.parse
|
|
|
|
parser = argparse.ArgumentParser(prog='composeMails')
|
|
parser.add_argument("-s", "--subject", required=True, dest="subject")
|
|
parser.add_argument("-t", "--template", required=True, dest="template")
|
|
parser.add_argument("-r", "--in-reply-to", required=True, dest="inReplyTo")
|
|
parser.add_argument("-f", "--really", dest="really", action="store_true")
|
|
parser.add_argument("-l", "--limit", dest="limit")
|
|
args = parser.parse_args()
|
|
|
|
body_raw = None
|
|
with open(args.template, "r") as tmpl:
|
|
body_raw = "\n\n" + tmpl.read()
|
|
cwd = os.getcwd()
|
|
|
|
if not args.really:
|
|
print("# This is a dry run")
|
|
|
|
parsed = json.load(sys.stdin)
|
|
for [addr, name, vocative, filename] in parsed:
|
|
if args.limit is not None and args.limit not in name:
|
|
continue
|
|
body = body_raw.replace("@@VOCATIVE@@", vocative)
|
|
print(f"Creating mail for {addr}")
|
|
if args.really:
|
|
subprocess.run(["aerc", f"mailto:{name} <{addr}>?account=gbl&subject={urllib.parse.quote_plus(args.subject)}&in-reply-to={urllib.parse.quote_plus(args.inReplyTo)}&body={urllib.parse.quote_plus(body)}"], check=True)
|
|
subprocess.run(["aerc", ":attach", filename])
|