Skip to content

Commit

Permalink
Merge pull request #22 from techx/evan/add-emails-to-docs
Browse files Browse the repository at this point in the history
adding sent emails to documents
  • Loading branch information
azliu0 authored May 8, 2024
2 parents 53fd5b6 + 7bb876f commit dd9d0cb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions server/controllers/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,13 @@ def get_full_message_id(message_id):
return f"<{message_id}@us-east-2.amazonses.com>"


def clean_up(text):
r"""Clean text by removing html tags and replacing <br /> with \n."""
breaked_line_text = text.replace("<br/>", "\n")
clean_regex = re.compile("<.*?>")
return re.sub(clean_regex, " ", breaked_line_text)


@emails.route("/send_email", methods=["POST"])
def send_email():
"""POST /send_email"""
Expand All @@ -372,14 +379,17 @@ def send_email():
if not thread:
return {"message": "Thread not found"}, 400

# replace <br /> with \n in body
breaked_line_text = data["body"].replace("<br/>", "\n")
clean_regex = re.compile("<.*?>")
clean_text = re.sub(clean_regex, " ", breaked_line_text)
clean_text = clean_up(data["body"])
context = {"body": data["body"]}
template = env.get_template("template.html")
body = template.render(**context)

# add body to documents
question = clean_up(reply_to_email.body)
new_doc = Document(question, reply_to_email.subject, clean_text, "HackMIT team")
db.session.add(new_doc)
db.session.commit()

client = boto3.client(
"ses",
region_name=AWS_REGION,
Expand Down

0 comments on commit dd9d0cb

Please sign in to comment.