diff --git a/rowers/mailprocessing.py b/rowers/mailprocessing.py index c25fb535..da8073fc 100644 --- a/rowers/mailprocessing.py +++ b/rowers/mailprocessing.py @@ -7,7 +7,12 @@ from rowers.tasks import ( handle_sendemail_unrecognized, handle_sendemail_unrecognizedowner ) -from django_mailbox.models import Message, MessageAttachment +from django_mailbox.models import Message, MessageAttachment,Mailbox + +workoutmailbox = Mailbox.objects.get(name='workouts') +failedmailbox = Mailbox.objects.get(name='Failed') + + from rowers.models import User, Rower, RowerForm from django.core.mail import EmailMessage @@ -148,7 +153,7 @@ def make_new_workout_from_email(rower, datafile, name, cntr=0,testing=False): dosummary = (fileformat != 'fit') if name == '': - name = 'imported through email' + name = 'Workout from Background Queue' id, message = dataprep.save_workout_database( datafilename, rower, diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index de9d1351..686d3ced 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -9,7 +9,7 @@ import time from time import strftime from django.core.management.base import BaseCommand -from django_mailbox.models import Message, MessageAttachment +from django_mailbox.models import Message, MessageAttachment,Mailbox from django.core.urlresolvers import reverse from django.conf import settings @@ -21,6 +21,9 @@ from rowingdata import rowingdata as rrdata import rowers.uploads as uploads from rowers.mailprocessing import make_new_workout_from_email, send_confirm +workoutmailbox = Mailbox.objects.get(name='workouts') +failedmailbox = Mailbox.objects.get(name='Failed') + # If you find a solution that does not need the two paths, please comment! sys.path.append('$path_to_root_of_project$') sys.path.append('$path_to_root_of_project$/$project_name$') @@ -104,7 +107,11 @@ class Command(BaseCommand): """Run the Email processing command """ def handle(self, *args, **options): - attachments = MessageAttachment.objects.all() + messages = Message.objects.filter(mailbox_id = workoutmailbox.id) + message_ids = [m.id for m in messages] + attachments = MessageAttachment.objects.filter( + message_id__in=message_ids + ) if 'testing' in options: testing = options['testing'] else: @@ -114,10 +121,13 @@ class Command(BaseCommand): extension = attachment.document.name[-3:].lower() try: message = Message.objects.get(id=attachment.message_id) - #if message.text: - # body = "\n".join(message.text.splitlines()) - #else: - body = message.get_body() + if message.text: + body = "\n".join(message.text.splitlines()) + else: + body = message.get_body() + + + uploadoptions = uploads.upload_options(body) from_address = message.from_address[0].lower() @@ -162,6 +172,9 @@ class Command(BaseCommand): attachment.delete() except WindowsError: pass + except: + message.mailbox = failedmailbox + message.save() if message.attachments.exists() is False: # no attachments, so can be deleted diff --git a/rowers/testdata/emails/noname b/rowers/testdata/emails/noname new file mode 100644 index 00000000..4eb4a5b2 Binary files /dev/null and b/rowers/testdata/emails/noname differ diff --git a/rowers/tests.py b/rowers/tests.py index 8f54b43e..fb8a67fd 100644 --- a/rowers/tests.py +++ b/rowers/tests.py @@ -48,12 +48,6 @@ class DjangoTestCase(TestCase, MockTestCase): # Create your tests here. -class EmailProcessTest(TestCase): - def test_emailprocessing(self): - out = StringIO() - call_command('processemail', stdout=out) - self.assertIn('Successfully processed email attachments',out.getvalue()) - class C2Objects(DjangoTestCase): def test_strokedata(self): with open('rowers/testdata/c2stroketestdata.txt','r') as infile: @@ -336,11 +330,16 @@ class EmailTests(TestCase): nu = datetime.datetime.now() workoutsbox = Mailbox.objects.create(name='workouts') workoutsbox.save() + failbox = Mailbox.objects.create(name='Failed') + failbox.save() for filename in os.listdir('rowers/testdata/emails'): m = Message(mailbox=workoutsbox, from_header = u.email, - subject = filename) + subject = filename, + body=""" + chart time + """) m.save() a2 = 'media/mailbox_attachments/'+filename copyfile('rowers/testdata/emails/'+filename,a2) diff --git a/static/img/praha.jpeg b/static/img/praha.jpeg new file mode 100644 index 00000000..c2f40b04 Binary files /dev/null and b/static/img/praha.jpeg differ