diff options
author | Mike Crute <mike@crute.us> | 2023-11-21 21:19:38 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2023-11-21 21:19:38 -0800 |
commit | a6dcbdda8fb66393be7e12bd3a90b77c203987d1 (patch) | |
tree | 5be553d205eb689837f6a7972e46880c73681421 /bugzilla/usr/sbin/sendmail | |
parent | aad62a8b259005cb8353d6a7b4a3f60c85803d1f (diff) | |
download | dockerfiles-a6dcbdda8fb66393be7e12bd3a90b77c203987d1.tar.bz2 dockerfiles-a6dcbdda8fb66393be7e12bd3a90b77c203987d1.tar.xz dockerfiles-a6dcbdda8fb66393be7e12bd3a90b77c203987d1.zip |
Remove old builds
Diffstat (limited to 'bugzilla/usr/sbin/sendmail')
-rwxr-xr-x | bugzilla/usr/sbin/sendmail | 108 |
1 files changed, 0 insertions, 108 deletions
diff --git a/bugzilla/usr/sbin/sendmail b/bugzilla/usr/sbin/sendmail deleted file mode 100755 index 69e5816..0000000 --- a/bugzilla/usr/sbin/sendmail +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | #!/usr/bin/python | ||
2 | |||
3 | import os | ||
4 | import re | ||
5 | import sys | ||
6 | import email | ||
7 | import boto3 | ||
8 | import socket | ||
9 | import argparse | ||
10 | from botocore.exceptions import NoRegionError | ||
11 | |||
12 | # These are all the sendmail options we don't support but have to accept so we | ||
13 | # can ignore them without messing up the command line. | ||
14 | # | ||
15 | # Format is (argument, takes parameters) | ||
16 | IGNORED = ( | ||
17 | ("-4", False), ("-6", False), ("-au", True), ("-ap", True), | ||
18 | ("-am", True), ("-ba", False), ("-bd", False), ("-bi", False), | ||
19 | ("-bm", False), ("-bp", False), ("-bs", False), ("-bt", False), | ||
20 | ("-bv", False), ("-bz", False), ("-C", True), ("-d", True), | ||
21 | ("-E", False), ("-h", True), ("-m", False), ("-M", True), | ||
22 | ("-N", True), ("-n", False), ("-oA", True), ("-oc", False), | ||
23 | ("-od", True), ("-oD", False), ("-oe", False), ("-oF", True), | ||
24 | ("-of", False), ("-og", True), ("-oH", True), ("-oi", False), | ||
25 | ("-oL", True), ("-om", False), ("-oo", False), ("-oQ", True), | ||
26 | ("-or", True), ("-oS", True), ("-os", False), ("-oT", True), | ||
27 | ("-ot", False), ("-ou", True), ("-q", True), ("-R", True), | ||
28 | ("-v", False), ("-F", True), ("-t", True), | ||
29 | ) | ||
30 | |||
31 | # A rough approximation of an email address but should be good enough to pick | ||
32 | # emails out of a command line | ||
33 | SORTA_EMAIL = re.compile("\S+@\S+\.\S+") | ||
34 | |||
35 | if os.path.exists("/etc/mailname"): | ||
36 | with open("/etc/mailname", "r") as fp: | ||
37 | MAIL_DOMAIN = fp.read().strip() | ||
38 | else: | ||
39 | MAIL_DOMAIN = socket.getfqdn() | ||
40 | |||
41 | # Configuration comes from the environment or metadata service | ||
42 | try: | ||
43 | client = boto3.client("ses") | ||
44 | except NoRegionError: | ||
45 | # TODO: Handle this better | ||
46 | boto3.setup_default_session( | ||
47 | aws_access_key_id="AKIAJSJZAZDLGRZVT6ZQ", | ||
48 | aws_secret_access_key="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", | ||
49 | region_name="us-west-2") | ||
50 | client = boto3.client("ses") | ||
51 | |||
52 | |||
53 | |||
54 | def parse_args(): | ||
55 | parser = argparse.ArgumentParser(add_help=False) | ||
56 | parser.add_argument("-V", action="store_true", dest="display_version") | ||
57 | parser.add_argument("-f", nargs=1, dest="sender_addr") | ||
58 | parser.add_argument("-r", nargs=1, dest="sender_addr") | ||
59 | |||
60 | for arg, nargs in IGNORED: | ||
61 | parser.add_argument(arg, nargs="?" if nargs else None) | ||
62 | |||
63 | opts, args = parser.parse_known_args() | ||
64 | addresses = [a for a in args if SORTA_EMAIL.match(a)] | ||
65 | |||
66 | return opts, addresses | ||
67 | |||
68 | |||
69 | def main(): | ||
70 | opts, addresses = parse_args() | ||
71 | |||
72 | if opts.display_version: | ||
73 | print("SES raw mail sender (definitely not sendmail)") | ||
74 | sys.exit(0) | ||
75 | |||
76 | try: | ||
77 | sender = opts.sender_addr[0] | ||
78 | except (IndexError, TypeError): | ||
79 | sender = None | ||
80 | |||
81 | msg = email.message_from_string(sys.stdin.read().encode("us-ascii")) | ||
82 | |||
83 | # Fix up cron emails | ||
84 | if 'Cron Daemon' in msg.get("From"): | ||
85 | msg.replace_header("From", "cron-no-reply@{}".format(MAIL_DOMAIN)) | ||
86 | |||
87 | ses_args = {"RawMessage": {"Data": msg.as_string()}} | ||
88 | |||
89 | if sender and not SORTA_EMAIL.match(sender): | ||
90 | raise Exception("Sender email does not look like an email") | ||
91 | |||
92 | if sender: | ||
93 | ses_args["Source"] = sender | ||
94 | |||
95 | if addresses: | ||
96 | ses_args["Destinations"] = addresses | ||
97 | |||
98 | client.send_raw_email(**ses_args) | ||
99 | |||
100 | |||
101 | if __name__ == "__main__": | ||
102 | try: | ||
103 | main() | ||
104 | sys.exit(0) | ||
105 | except Exception as e: | ||
106 | print("Error during sending:") | ||
107 | print(e) | ||
108 | sys.exit(1) | ||