new: Add redirects in notifications, optional reply-to

pull/79/head
Raphaël Vinot 2020-05-27 15:15:37 +02:00
parent ccad142dd0
commit 5ebb35c161
4 changed files with 21 additions and 2 deletions

View File

@ -3,6 +3,8 @@ Dear {recipient},
Please have a look at this capture on lookyloo:
* https://{domain}/tree/{uuid}
{redirects}
{comment}

View File

@ -252,12 +252,23 @@ class Lookyloo():
return pickle.load(_p)
return None
def send_mail(self, capture_uuid: str, comment: str='') -> None:
def send_mail(self, capture_uuid: str, email: str='', comment: str='') -> None:
if not self.get_config('enable_mail_notification'):
return
redirects = ''
capture_dir = self.lookup_capture_dir(capture_uuid)
if capture_dir:
cache = self.capture_cache(capture_dir)
if cache:
redirects = "Redirects:\n"
redirects += '\n'.join(cache['redirects'])
email_config = self.get_config('email')
msg = EmailMessage()
msg['From'] = email_config['from']
if email:
msg['Reply-To'] = email
msg['To'] = email_config['to']
msg['Subject'] = email_config['subject']
body = get_email_template()
@ -265,6 +276,7 @@ class Lookyloo():
recipient=msg['To'].addresses[0].display_name,
domain=email_config['domain'],
uuid=capture_uuid,
redirects=redirects,
comment=comment,
sender=msg['From'].addresses[0].display_name,
)

View File

@ -377,8 +377,9 @@ def cache_tree(tree_uuid: str):
@app.route('/tree/<string:tree_uuid>/send_mail', methods=['POST', 'GET'])
def send_mail(tree_uuid: str):
email: str = request.form.get('email') if request.form.get('email') else '' # type: ignore
comment: str = request.form.get('comment') if request.form.get('comment') else '' # type: ignore
lookyloo.send_mail(tree_uuid, comment)
lookyloo.send_mail(tree_uuid, email, comment)
return redirect(url_for('tree', tree_uuid=tree_uuid))

View File

@ -216,6 +216,10 @@
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="email">Email address - used to get back in touch with you if needed (optional)</label>
<input type="email" class="form-control" name="email" id="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="comment">Please write a comment (optional)</label>
<textarea class="form-control" name="comment" id=comment rows="3"></textarea>