Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Update from address
Browse files Browse the repository at this point in the history
  • Loading branch information
OllieJC committed Nov 2, 2023
1 parent a91603a commit 8dad6f6
Showing 1 changed file with 56 additions and 21 deletions.
77 changes: 56 additions & 21 deletions lambda/email-forwarder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,68 @@
from botocore.exceptions import ClientError
from botocore.client import Config

region = os.environ["Region"]
incoming_email_bucket = os.environ["MailS3Bucket"]
system_domain = os.environ["MailSenderDomain"]
region = os.getenv("Region", None)
incoming_email_bucket = os.getenv("MailS3Bucket", None)
system_domain = os.getenv("MailSenderDomain", None)

client_s3 = boto3.client("s3", config=Config(signature_version="s3v4"))

forward_mapping = {
"contact": ["[email protected]"],
"security": ["[email protected]"],
"im": ["[email protected]"],
"report": ["[email protected]"],
"incident": ["[email protected]"],
"incidents": ["[email protected]"],
"vm": ["[email protected]"],
"vulnerability": ["[email protected]"],
"data": ["[email protected]"],
"threat": ["[email protected]"],
"ollie": ["[email protected]"],
"contact": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"security": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"im": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"report": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"incident": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"incidents": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"vm": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"vulnerability": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"data": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"threat": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
"ollie": {
"system_email": "[email protected]",
"reply_from": "[email protected]",
},
}

_asam = os.getenv("allowed_send_as_emails", "")
allowed_send_as_emails = [x.lower().strip() for x in _asam.split(",") if "@" in x]


def get_forward_mappings(email: str):
for f in forward_mapping:
if email.startswith(f):
return forward_mapping[f]
if email.endswith(f):
return forward_mapping[f]
return []
for fm in forward_mapping:
if email.startswith(f"{fm}@"):
return forward_mapping[fm]
return {}


def get_message_from_s3(object_path):
Expand Down Expand Up @@ -310,7 +341,11 @@ def lambda_handler(event, context):
for mapped_email in get_forward_mappings(dest):
if mapped_email:
# Create the message.
message = create_message(file_dict, mapped_email, dest)
message = create_message(
file_dict,
mapped_email["system_email"],
mapped_email["reply_from"],
)
if message:
print(message)
# Send the email and print the result.
Expand Down

0 comments on commit 8dad6f6

Please sign in to comment.