mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-04-10 13:58:53 +02:00
Merged in better handling of attachments, for #468
This commit is contained in:
commit
40ab600ad6
@ -25,6 +25,7 @@ except ImportError:
|
|||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.utils import six
|
||||||
from django.utils.encoding import smart_text
|
from django.utils.encoding import smart_text
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
@ -123,13 +124,16 @@ def send_templated_mail(template_name,
|
|||||||
for filename, filefield in files:
|
for filename, filefield in files:
|
||||||
mime = mimetypes.guess_type(filename)
|
mime = mimetypes.guess_type(filename)
|
||||||
if mime[0] is not None and mime[0] == "text/plain":
|
if mime[0] is not None and mime[0] == "text/plain":
|
||||||
with open(filefield.path, 'r') as file:
|
with open(filefield.path, 'r') as attachedfile:
|
||||||
content = file.read()
|
content = attachedfile.read()
|
||||||
msg.attach(filename, content)
|
msg.attach(filename, content)
|
||||||
else:
|
else:
|
||||||
with open(filefield.path, 'rb') as file:
|
if six.PY3:
|
||||||
content = file.read()
|
msg.attach_file(filefield.path)
|
||||||
msg.attach(filename, content)
|
else:
|
||||||
|
with open(filefield.path, 'rb') as attachedfile:
|
||||||
|
content = attachedfile.read()
|
||||||
|
msg.attach(filename, content)
|
||||||
|
|
||||||
return msg.send(fail_silently)
|
return msg.send(fail_silently)
|
||||||
|
|
||||||
|
@ -337,6 +337,7 @@ def ticket_from_message(message, queue, logger):
|
|||||||
if not name:
|
if not name:
|
||||||
ext = mimetypes.guess_extension(part.get_content_type())
|
ext = mimetypes.guess_extension(part.get_content_type())
|
||||||
name = "part-%i%s" % (counter, ext)
|
name = "part-%i%s" % (counter, ext)
|
||||||
|
|
||||||
payload = part.get_payload()
|
payload = part.get_payload()
|
||||||
payloadToWrite = payload
|
payloadToWrite = payload
|
||||||
try:
|
try:
|
||||||
@ -345,8 +346,8 @@ def ticket_from_message(message, queue, logger):
|
|||||||
except binascii.Error:
|
except binascii.Error:
|
||||||
logger.debug("Payload was not base64 encoded, using raw bytes")
|
logger.debug("Payload was not base64 encoded, using raw bytes")
|
||||||
payloadToWrite = payload
|
payloadToWrite = payload
|
||||||
files.append(SimpleUploadedFile(name, encoding.smart_bytes(payloadToWrite), part.get_content_type()))
|
files.append(SimpleUploadedFile(name, part.get_payload(decode=True), mimetypes.guess_type(name)[0]))
|
||||||
logger.info("Found MIME attachment %s" % name)
|
logger.debug("Found MIME attachment %s" % name)
|
||||||
|
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user