some fixes email processing
This commit is contained in:
@@ -7,7 +7,12 @@ from rowers.tasks import (
|
|||||||
handle_sendemail_unrecognized,
|
handle_sendemail_unrecognized,
|
||||||
handle_sendemail_unrecognizedowner
|
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 rowers.models import User, Rower, RowerForm
|
||||||
|
|
||||||
from django.core.mail import EmailMessage
|
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')
|
dosummary = (fileformat != 'fit')
|
||||||
|
|
||||||
if name == '':
|
if name == '':
|
||||||
name = 'imported through email'
|
name = 'Workout from Background Queue'
|
||||||
|
|
||||||
id, message = dataprep.save_workout_database(
|
id, message = dataprep.save_workout_database(
|
||||||
datafilename, rower,
|
datafilename, rower,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import time
|
|||||||
from time import strftime
|
from time import strftime
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
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.core.urlresolvers import reverse
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
@@ -21,6 +21,9 @@ from rowingdata import rowingdata as rrdata
|
|||||||
import rowers.uploads as uploads
|
import rowers.uploads as uploads
|
||||||
from rowers.mailprocessing import make_new_workout_from_email, send_confirm
|
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!
|
# 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$')
|
||||||
sys.path.append('$path_to_root_of_project$/$project_name$')
|
sys.path.append('$path_to_root_of_project$/$project_name$')
|
||||||
@@ -104,7 +107,11 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
"""Run the Email processing command """
|
"""Run the Email processing command """
|
||||||
def handle(self, *args, **options):
|
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:
|
if 'testing' in options:
|
||||||
testing = options['testing']
|
testing = options['testing']
|
||||||
else:
|
else:
|
||||||
@@ -114,10 +121,13 @@ class Command(BaseCommand):
|
|||||||
extension = attachment.document.name[-3:].lower()
|
extension = attachment.document.name[-3:].lower()
|
||||||
try:
|
try:
|
||||||
message = Message.objects.get(id=attachment.message_id)
|
message = Message.objects.get(id=attachment.message_id)
|
||||||
#if message.text:
|
if message.text:
|
||||||
# body = "\n".join(message.text.splitlines())
|
body = "\n".join(message.text.splitlines())
|
||||||
#else:
|
else:
|
||||||
body = message.get_body()
|
body = message.get_body()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uploadoptions = uploads.upload_options(body)
|
uploadoptions = uploads.upload_options(body)
|
||||||
from_address = message.from_address[0].lower()
|
from_address = message.from_address[0].lower()
|
||||||
@@ -162,6 +172,9 @@ class Command(BaseCommand):
|
|||||||
attachment.delete()
|
attachment.delete()
|
||||||
except WindowsError:
|
except WindowsError:
|
||||||
pass
|
pass
|
||||||
|
except:
|
||||||
|
message.mailbox = failedmailbox
|
||||||
|
message.save()
|
||||||
|
|
||||||
if message.attachments.exists() is False:
|
if message.attachments.exists() is False:
|
||||||
# no attachments, so can be deleted
|
# no attachments, so can be deleted
|
||||||
|
|||||||
BIN
rowers/testdata/emails/noname
vendored
Normal file
BIN
rowers/testdata/emails/noname
vendored
Normal file
Binary file not shown.
@@ -48,12 +48,6 @@ class DjangoTestCase(TestCase, MockTestCase):
|
|||||||
|
|
||||||
# Create your tests here.
|
# 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):
|
class C2Objects(DjangoTestCase):
|
||||||
def test_strokedata(self):
|
def test_strokedata(self):
|
||||||
with open('rowers/testdata/c2stroketestdata.txt','r') as infile:
|
with open('rowers/testdata/c2stroketestdata.txt','r') as infile:
|
||||||
@@ -336,11 +330,16 @@ class EmailTests(TestCase):
|
|||||||
nu = datetime.datetime.now()
|
nu = datetime.datetime.now()
|
||||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||||
workoutsbox.save()
|
workoutsbox.save()
|
||||||
|
failbox = Mailbox.objects.create(name='Failed')
|
||||||
|
failbox.save()
|
||||||
|
|
||||||
for filename in os.listdir('rowers/testdata/emails'):
|
for filename in os.listdir('rowers/testdata/emails'):
|
||||||
m = Message(mailbox=workoutsbox,
|
m = Message(mailbox=workoutsbox,
|
||||||
from_header = u.email,
|
from_header = u.email,
|
||||||
subject = filename)
|
subject = filename,
|
||||||
|
body="""
|
||||||
|
chart time
|
||||||
|
""")
|
||||||
m.save()
|
m.save()
|
||||||
a2 = 'media/mailbox_attachments/'+filename
|
a2 = 'media/mailbox_attachments/'+filename
|
||||||
copyfile('rowers/testdata/emails/'+filename,a2)
|
copyfile('rowers/testdata/emails/'+filename,a2)
|
||||||
|
|||||||
BIN
static/img/praha.jpeg
Normal file
BIN
static/img/praha.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 139 KiB |
Reference in New Issue
Block a user