Skip to content

Commit c8a854a

Browse files
Adding optional reference field
1 parent 8177739 commit c8a854a

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

server.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ def sanitize_filename(filename):
4040

4141
def parse_form(form):
4242
"""
43-
Parses the form data to extract the message, recipient, and attachments.
43+
Parses the form data to extract the message, recipient, reference, and attachments.
4444
"""
4545
text = form['message']
4646
recipient = form['recipient']
47+
reference = form.get('reference', '')
4748

4849
all_attachments = []
4950
for i in range(Config.NUMBER_OF_ATTACHMENTS):
@@ -53,7 +54,7 @@ def parse_form(form):
5354
continue
5455
sanitized_filename = sanitize_filename(filename)
5556
all_attachments.append((sanitized_filename, attachment))
56-
return text, recipient, all_attachments
57+
return text, recipient, reference, all_attachments
5758

5859
def valid_recipient(recipient):
5960
"""
@@ -72,15 +73,19 @@ def get_identifier(recipient, now=None, randint=None):
7273
randint = Random().randint(1000, 9999)
7374
return f'{recipient}:{now.strftime("%Y:%m:%d:%H:%M:%S")}:{randint}'
7475

75-
def create_email(to_email, identifier, text, all_attachments):
76+
def create_email(to_email, identifier, text, all_attachments, reference=''):
7677
"""
7778
Creates an email message with attachments.
7879
"""
7980
plain_text = text.replace('<br />', '\n')
81+
subject = f'Secure Form Submission {identifier}'
82+
if reference:
83+
subject = f'{reference} {subject}'
84+
8085
message = Mail(
8186
from_email=FROMEMAIL,
8287
to_emails=to_email,
83-
subject=f'Secure Form Submission {identifier}',
88+
subject=subject,
8489
plain_text_content=plain_text)
8590

8691
for item in all_attachments:
@@ -156,6 +161,7 @@ def submit():
156161
# Extract fields from JSON data
157162
message = data['message']
158163
recipient = data['recipient']
164+
reference = data.get('reference', '')
159165
files = data['files']
160166

161167
if not message:
@@ -173,9 +179,11 @@ def submit():
173179
identifier = get_identifier(recipient)
174180

175181
log_data = f"{date} - message to: {recipient}, identifier: {identifier}, length: {message_length}, file count: {file_count}"
182+
if reference:
183+
log_data += f", reference: {reference}"
176184
logging.info(log_data)
177185

178-
message = create_email(to_email, identifier, message, files)
186+
message = create_email(to_email, identifier, message, files, reference)
179187

180188
if Config.DEBUG_MODE:
181189
print(f"Attempt to send email to {to_email}")

static/js/app.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ function acceptEncryptedData(data) {
8787
console.log('all chunks received, submitting form');
8888
const gRecaptchaBlock = document.getElementById('gRecaptcha');
8989
const recipient = document.getElementById("recipientSelect");
90+
const reference = document.getElementById("reference");
9091

9192
dataArray['g-recaptcha-response'] = gRecaptchaBlock ? grecaptcha.getResponse() : null;
9293
dataArray['recipient'] = recipient.value;
94+
dataArray['reference'] = reference.value;
9395

9496
postData('/submit-encrypted-data', dataArray)
9597
.then(response => {
@@ -216,4 +218,4 @@ function displayResult(status, message) {
216218
const formElement = document.getElementById("submission-form");
217219
const statusText = (status == "success") ? "Success!" : "Error";
218220
formElement.innerHTML = `<fieldset><legend>${statusText}</legend><span class='pure-form-message'>${message}</span><br><br><span class='pure-form-message'><a href="#" onclick="location.reload()">Send one more submission</a></span></fieldset>`
219-
}
221+
}

templates/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
{% if 0 %}<option value="oleh">Oleh</option>{% endif %}
2727
</select>
2828
<br>
29+
<label id="referenceLabel" for="reference">Reference (optional):</label>
30+
<input id="reference" name="reference" type="text" placeholder="Example: FY24-XXXX">
31+
<br>
2932
<label id="messageLabel" for="text">Message:</label>
3033
<textarea id="text" name="text" type="text" placeholder="Write a message. Please mention your name or email and short description of the file contents."></textarea>
3134
<br>

0 commit comments

Comments
 (0)