python3 changes

pull/4/head
Sascha Rommelfangen 2017-05-24 15:50:05 +02:00
parent 09a4c83772
commit 8992f7557c
1 changed files with 15 additions and 14 deletions

View File

@ -44,26 +44,27 @@ if debug:
target.write("New debug session opened") target.write("New debug session opened")
try: try:
email_subject = b'M2M - ' if not sys.stdin.isatty():
email_data = b'' email_subject = b'M2M - '
mailcontent = "".join(sys.stdin) email_data = b''
msg = email.message_from_string(mailcontent) mailcontent = "".join(sys.stdin)
mail_subject = msg.get('Subject').encode() msg = email.message_from_string(mailcontent)
for part in msg.walk(): mail_subject = msg.get('Subject').encode()
if part.get_content_maintype() == 'multipart': for part in msg.walk():
continue if part.get_content_maintype() == 'multipart':
if part.get_content_maintype() == 'text': continue
email_data += part.get_payload(decode=True) if part.get_content_maintype() == 'text':
email_subject += mail_subject email_data += part.get_payload(decode=True)
stdin_used = True email_subject += mail_subject
stdin_used = True
except Exception as e: except Exception as e:
print(e) print(e)
pass pass
try: try:
if not stdin_used: if not stdin_used:
email_data = str(sys.argv[1]) email_data = sys.argv[1].encode()
email_subject = str(sys.argv[2]) email_subject = sys.argv[2].encode()
except: except:
if debug: if debug:
target.write("FATAL ERROR: Not all required input received") target.write("FATAL ERROR: Not all required input received")