mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-22 07:53:19 +01:00
Make sure binary MIME attachments will be base64 decoded
This commit is contained in:
parent
ef0ba19a3b
commit
a40bbdbecb
14
helpdesk/management/commands/get_email.py
Normal file → Executable file
14
helpdesk/management/commands/get_email.py
Normal file → Executable file
@ -21,6 +21,8 @@ from os.path import isfile, join
|
||||
import poplib
|
||||
import re
|
||||
import socket
|
||||
import base64
|
||||
import binascii
|
||||
from time import ctime
|
||||
|
||||
from email_reply_parser import EmailReplyParser
|
||||
@ -332,8 +334,16 @@ def ticket_from_message(message, queue, logger):
|
||||
if not name:
|
||||
ext = mimetypes.guess_extension(part.get_content_type())
|
||||
name = "part-%i%s" % (counter, ext)
|
||||
files.append(SimpleUploadedFile(name, encoding.smart_bytes(part.get_payload()), part.get_content_type()))
|
||||
logger.debug("Found MIME attachment %s" % name)
|
||||
payload = part.get_payload()
|
||||
payloadToWrite = payload
|
||||
try:
|
||||
logger.debug("Try to base64 decode the attachment payload")
|
||||
payloadToWrite = base64.decodestring(payload)
|
||||
except binascii.Error:
|
||||
logger.debug("Payload was not base64 encoded, using raw bytes")
|
||||
payloadToWrite = payload
|
||||
files.append(SimpleUploadedFile(name, encoding.smart_bytes(payloadToWrite), part.get_content_type()))
|
||||
logger.info("Found MIME attachment %s" % name)
|
||||
|
||||
counter += 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user