Private
Public Access
1
0

some fixes email processing

This commit is contained in:
Sander Roosendaal
2017-11-10 11:40:47 +01:00
parent 768d1540e6
commit d19ddec79e
5 changed files with 32 additions and 15 deletions

View File

@@ -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