From 4a082e0bfbae1de8e9cefb99db21834a1c508955 Mon Sep 17 00:00:00 2001 From: Ross Poulton Date: Tue, 5 Feb 2008 23:35:40 +0000 Subject: [PATCH] * Add smart e-mail parsing - if subject contains a ticket ID, the new e-mail is added as a followup to that ticket. * Add basic code to support Google Charts in a future revision * Improved use of Queue "Update" CC. --- README | 3 +++ forms.py | 8 +++++--- lib.py | 8 ++++++++ scripts/get_email.py | 36 +++++++++++++++++++++++++++++++----- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/README b/README index 12da5a25..0e88ec4b 100644 --- a/README +++ b/README @@ -52,6 +52,9 @@ LICENSE.JQUERY and LICENSE.NICEDIT for their respective license terms. 3. An existing WORKING Django project with database etc. If you cannot log into the Admin, you won't get this product working. +4. pygooglechart (needs minor mods to @staticmethod calls for python 2.3) + http://pygooglechart.slowchop.com/ + ######################### 3. Installation diff --git a/forms.py b/forms.py index 2d28769d..b0d56c32 100644 --- a/forms.py +++ b/forms.py @@ -102,12 +102,13 @@ class TicketForm(forms.Form): if t.submitter_email: send_multipart_mail('helpdesk/emails/submitter_newticket', context, '%s %s' % (t.ticket, t.title), t.submitter_email, q.from_address) - if t.assigned_to != user: + if t.assigned_to and t.assigned_to != user: send_multipart_mail('helpdesk/emails/owner_assigned', context, '%s %s (Opened)' % (t.ticket, t.title), t.assigned_to.email, q.from_address) if q.new_ticket_cc: send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), q.updated_ticket_cc, q.from_address) - elif q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc: + + if q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc: send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), q.updated_ticket_cc, q.from_address) return t @@ -170,7 +171,8 @@ class PublicTicketForm(forms.Form): if q.new_ticket_cc: send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), q.updated_ticket_cc, q.from_address) - elif q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc: + + if q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc: send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), q.updated_ticket_cc, q.from_address) return t diff --git a/lib.py b/lib.py index 1beba30b..2bd174a2 100644 --- a/lib.py +++ b/lib.py @@ -76,3 +76,11 @@ def send_multipart_mail(template_name, email_context, subject, recipients, sende return msg.send(fail_silently) +def normalise_to_100(data): + max_value = max(data) + if max_value > 100: + new_data = [] + for d in data: + new_data.append(int(d/float(max_value)*100)) + data = new_data + return data diff --git a/scripts/get_email.py b/scripts/get_email.py index 7e616112..5aa0dd3b 100644 --- a/scripts/get_email.py +++ b/scripts/get_email.py @@ -31,7 +31,7 @@ import imaplib from datetime import datetime, timedelta import email, mimetypes, re from email.Utils import parseaddr -from helpdesk.models import Queue,Ticket +from helpdesk.models import Queue,Ticket, FollowUp from helpdesk.lib import send_multipart_mail def process_email(): @@ -89,10 +89,10 @@ def ticket_from_message(message, queue): sender_email = parseaddr(message.get('from', 'Unknown Sender'))[1] - regex = re.compile("^\[\d+\]") + regex = re.compile("^\[[A-Za-z0-9]+-\d+\]") if regex.match(subject): # This is a reply or forward. - ticket = re.match(r"^\[(?P\d+)\]", subject).group('id') + ticket = re.match(r"^\[(?P[A-Za-z0-9]+)-(?P\d+)\]", subject).group('id') else: ticket = None counter = 0 @@ -147,10 +147,36 @@ def ticket_from_message(message, queue): 'queue': queue, } + update = "" + if sender_email: send_multipart_mail('helpdesk/emails/submitter_newticket', context, '%s %s' % (t.ticket, t.title), sender_email, queue.from_address) - - print " [%s-%s] %s" % (t.queue.slug, t.id, t.title) + + if queue.new_ticket_cc: + send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), queue.updated_ticket_cc, queue.from_address) + + if queue.updated_ticket_cc and queue.updated_ticket_cc != queue.new_ticket_cc: + send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), queue.updated_ticket_cc, queue.from_address) + + else: + f = FollowUp( + ticket = t, + title = 'E-Mail Received from %s' % sender_email, + date = datetime.now(), + public = True, + comment = body, + ) + f.save() + update = " (Updated)" + + if t.assigned_to: + send_multipart_mail('helpdesk/emails/owner_updated', context, '%s %s (Updated)' % (t.ticket, t.title), t.assigned_to.email, queue.from_address) + + if queue.updated_ticket_cc: + send_multipart_mail('helpdesk/emails/cc_updatedt', context, '%s %s (Updated)' % (t.ticket, t.title), queue.updated_ticket_cc, queue.from_address) + + + print " [%s-%s] %s%s" % (t.queue.slug, t.id, t.title, update) #for file in files: #data = file['content']