Private
Public Access
1
0

passing all tests on py3

This commit is contained in:
Sander Roosendaal
2019-02-28 22:52:59 +01:00
parent ee4fa4c3b8
commit faeea73b0a
14 changed files with 76 additions and 21 deletions

View File

@@ -1,13 +1,17 @@
#!/srv/venv/bin/python
""" Process emails """
import sys
import os
PY3K = sys.version_info >= (3, 0)
import zipfile
import re
import time
from time import strftime
import io
from django.core.management.base import BaseCommand
from django_mailbox.models import Message, MessageAttachment,Mailbox
from django.core.urlresolvers import reverse
@@ -62,7 +66,7 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
# test if file exists and is not empty
try:
with open('media/'+filename,'r') as fop:
with io.open('media/'+filename,'rb') as fop:
line = fop.readline()
except (IOError, UnicodeEncodeError):
if testing:
@@ -164,6 +168,11 @@ def get_from_address(message):
except IndexError:
first_line = ''
try:
first_line = first_line.decode('utf-8')
except AttributeError:
pass
if "quiske" in first_line:
match = re.search(r'[\w\.-]+@[\w\.-]+', first_line)
return match.group(0)