aboutsummaryrefslogtreecommitdiff
path: root/bugzilla/usr/sbin/sendmail
diff options
context:
space:
mode:
Diffstat (limited to 'bugzilla/usr/sbin/sendmail')
-rwxr-xr-xbugzilla/usr/sbin/sendmail108
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
3import os
4import re
5import sys
6import email
7import boto3
8import socket
9import argparse
10from 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)
16IGNORED = (
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
33SORTA_EMAIL = re.compile("\S+@\S+\.\S+")
34
35if os.path.exists("/etc/mailname"):
36 with open("/etc/mailname", "r") as fp:
37 MAIL_DOMAIN = fp.read().strip()
38else:
39 MAIL_DOMAIN = socket.getfqdn()
40
41# Configuration comes from the environment or metadata service
42try:
43 client = boto3.client("ses")
44except 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
54def 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
69def 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
101if __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)