File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
django_inbound_email/backends Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 11import json
22import logging
3+ import base64
34
45from django .core .mail import EmailMultiAlternatives
56from django .http import HttpRequest
@@ -20,9 +21,12 @@ class MandrillRequestParser(RequestParser):
2021
2122 def _process_attachments (self , email , attachments ):
2223 for key , attachment in attachments .iteritems ():
24+ is_base64 = attachment .get ('base64' )
2325 name = attachment .get ('name' )
2426 mimetype = attachment .get ('type' )
2527 content = attachment .get ('content' , u"" )
28+ if is_base64 :
29+ content = base64 .b64decode (content )
2630 content = smart_bytes (content , strings_only = True )
2731
2832 if len (content ) > self .max_file_size :
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22from os import path
33import json
4+ import base64
45
56from django .conf import settings
67from django .core .mail import EmailMultiAlternatives
@@ -550,7 +551,13 @@ def _parse_from(name, email):
550551 if has_html :
551552 self .assertEqual (e .alternatives [0 ][0 ], msg ['html' ])
552553 for name , contents , mimetype in e .attachments :
553- self .assertEqual (msg ['attachments' ][name ]['content' ], contents )
554+ # Check that base64 contents are decoded
555+ is_base64 = msg ['attachments' ][name ].get ('base64' )
556+ req_contents = msg ['attachments' ][name ]['content' ]
557+ if is_base64 :
558+ req_contents = base64 .b64decode (req_contents )
559+
560+ self .assertEqual (req_contents , contents )
554561 self .assertEqual (msg ['attachments' ][name ]['type' ], mimetype )
555562 self .assertEqual (e .body , msg ['text' ])
556563
You can’t perform that action at this time.
0 commit comments