From fdaeb506a477d666a63ed02c969ebb7a1a259f57 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 9 Nov 2019 20:48:59 +0000 Subject: [PATCH] Extract text from binary --- daemon.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/daemon.py b/daemon.py index d4501e76f..55cacd7de 100644 --- a/daemon.py +++ b/daemon.py @@ -2656,15 +2656,15 @@ class PubServer(BaseHTTPRequestHandler): print('messageFields1: '+str(msg.get_payload(decode=False))) print('messageFields2: '+str(msg.get_payload(decode=True))) imageBoundary=b"Content-Disposition: form-data" - if imageBoundary in msg.get_payload(decode=True): - msg=msg.get_payload(decode=True).split(imageBoundary,1)[0] - print('messageFields3.1') - messageFields=msg.decode('utf-8').split(boundary) - print('messageFields3.2') - else: - messageFields=msg.get_payload(decode=True).decode('utf-8').split(boundary) + imageLocation=postBytes.find(imageBoundary) + print('messageFields3') + if imageLocation>-1: print('messageFields4') - print('messageFields5: '+str(messageFields)) + msg = email.parser.BytesParser().parsebytes(postBytes[:imageLocation]) + print('messageFields5') + messageFields=msg.get_payload(decode=True).decode('utf-8').split(boundary) + print('messageFields6') + print('messageFields7: '+str(messageFields)) fields={} filename=None attachmentMediaType=None