Skip to content

Commit

Permalink
Add a function to sanitize subject lines to prevent unwanted characters
Browse files Browse the repository at this point in the history
  • Loading branch information
makrohn committed May 12, 2016
1 parent bdd933d commit ebd0f3c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions feedbackRequestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
from email.mime.text import MIMEText
import settings
from validate_email import validate_email
import re


def sanitize(string):
"""Remove unwanted or dangerous character from a string"""
new_string = re.sub('[^a-zA-Z0-9 \n\.]', '_', string)
return new_string


def getIssuesFromToday():
Expand All @@ -27,9 +34,10 @@ def getIssuesFromToday():
def sendSurvey(issue):
"""Send a an email to the reporter of an issue"""
msg = MIMEText(
'Hello!\n\n The Help Desk has recently closed your ticket, "' +
issue['fields']['summary'] + '". If you have a moment, please fill out ' +
' this survey on how happy you are with your Help Desk experience.\n\n' +
'Hello!\n\n The Help Desk has recently closed your ticket, ' +
sanitize(issue['fields']['summary']) +
'. If you have a moment, please fill out this survey on how happy' +
' happy you are with your Help Desk experience.\n\n' +
settings.google_form_link + '?entry.' +
'settings.ticket_number_field' + '=' +
issue['key'] + '\n\nThanks!\nThe Help Desk Staff'
Expand Down Expand Up @@ -66,6 +74,6 @@ def addLabel(issue_key):

for ticket in todaysIssues['issues']:
if ('survey_sent' not in ticket['fields']['labels'] and
validate_email(issue['fields']['reporter']['emailAddress'])):
validate_email(ticket['fields']['reporter']['emailAddress'])):
sendSurvey(ticket)
addLabel(ticket['key'])

0 comments on commit ebd0f3c

Please sign in to comment.