From 452a34ad72b11f6dad343be3f0b77d86a5f70415 Mon Sep 17 00:00:00 2001 From: Ross Poulton Date: Wed, 29 Jan 2014 23:08:33 +1100 Subject: [PATCH] Smart email parsing (closes #203): Use email-reply-parser to ignore cruft in incoming emails --- README.rst | 3 ++- helpdesk/management/commands/get_email.py | 4 +++- requirements.txt | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index f094f27b..4e7f3dbf 100644 --- a/README.rst +++ b/README.rst @@ -25,12 +25,13 @@ LICENSE.3RDPARTY for license terms for included packages. Dependencies (pre-flight checklist) ----------------------------------- -1. Python 2.5+ +1. Python 2.6+ 2. Django (1.4 or newer) 3. South for database migrations (highly recommended, but not required). Download from http://south.aeracode.org/ 4. An existing WORKING Django project with database etc. If you cannot log into the Admin, you won't get this product working. 5. `pip install django-bootstrap-form` and add `bootstrapform` to `settings.INSTALLED_APPS` +6. `pip install email-reply-parser` to get smart email reply handling **NOTE REGARDING SQLITE AND SEARCHING:** If you use sqlite as your database, the search function will not work as diff --git a/helpdesk/management/commands/get_email.py b/helpdesk/management/commands/get_email.py index e3893711..8d4fede6 100644 --- a/helpdesk/management/commands/get_email.py +++ b/helpdesk/management/commands/get_email.py @@ -21,6 +21,8 @@ from email.header import decode_header from email.Utils import parseaddr, collapse_rfc2231_value from optparse import make_option +from email_reply_parser import EmailReplyParser + from django.core.files.base import ContentFile from django.core.management.base import BaseCommand from django.db.models import Q @@ -192,7 +194,7 @@ def ticket_from_message(message, queue, quiet): if part.get_content_maintype() == 'text' and name == None: if part.get_content_subtype() == 'plain': - body_plain = decodeUnknown(part.get_content_charset(), part.get_payload(decode=True)) + body_plain = EmailReplyParser.parse_reply(decodeUnknown(part.get_content_charset(), part.get_payload(decode=True))) else: body_html = part.get_payload(decode=True) else: diff --git a/requirements.txt b/requirements.txt index 3a6519ca..0b809e40 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Django>1.4 django-bootstrap-form +email-reply-parser