The 'API' is written but untested

This commit is contained in:
Daniel Quinn
2016-02-08 23:46:16 +00:00
parent 212752f46e
commit 0eaed36420
6 changed files with 127 additions and 11 deletions

View File

@@ -12,6 +12,7 @@ from dateutil import parser
from django.conf import settings
from .consumer import Consumer
from .models import Sender
class MailFetcherError(Exception):
@@ -28,10 +29,6 @@ class Message(object):
and n attachments, and that we don't care about the message body.
"""
# This regex is probably more restrictive than it needs to be, but it's
# better safe than sorry.
SAFE_SUBJECT_REGEX = re.compile(r"^[\w\- ,.']+$")
def _set_time(self, message):
self.time = datetime.datetime.now()
message_time = message.get("Date")
@@ -58,7 +55,7 @@ class Message(object):
if self.subject is None:
raise InvalidMessageError("Message does not have a subject")
if not self.SAFE_SUBJECT_REGEX.match(self.subject):
if not Sender.SAFE_REGEX.match(self.subject):
raise InvalidMessageError("Message subject is unsafe")
print('Fetching email: "{}"'.format(self.subject))