From: Andrew Engelbrecht Date: Sun, 27 Jul 2014 07:08:56 +0000 (-0400) Subject: refactored a bit X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d437f8b2855e54672aa964d96eca0b8fa48e5ff7;p=edward.git refactored a bit this reduces the size of msg_walk() --- diff --git a/edward-bot b/edward-bot index 54a3839..15d5328 100755 --- a/edward-bot +++ b/edward-bot @@ -56,30 +56,13 @@ def msg_walk (msg): body = "" for part in msg.walk(): - if part.get_content_type() == 'multipart': - continue - - charset = part.get_content_charset() - payload_b = part.get_payload(decode=True) - - filename = part.get_filename() - conttype = part.get_content_type() - descrip_p = part.get_params(header='content-description') + payload, descript, filename, conttype = get_part_info(part) - if charset == None: - charset = 'utf-8' - - if payload_b == None: + if payload == None: continue - else: - payload = payload_b.decode(charset) - - - if descrip_p == None: - decript = "" - else: - descript = descrip_p[0][0] + if conttype == 'multipart': + continue if conttype == "application/pgp-encrypted": if descript == 'PGP/MIME version identification': @@ -88,7 +71,8 @@ def msg_walk (msg): + payload.strip(), file=sys.stderr) continue - elif (filename == "encrypted.asc") or (conttype == "pgp/mime"): + + if (filename == "encrypted.asc") or (conttype == "pgp/mime"): payload_dec = decrypt_payload(payload) body += payload_dec @@ -100,6 +84,31 @@ def msg_walk (msg): return body +def get_part_info (part): + + charset = part.get_content_charset() + payload_b = part.get_payload(decode=True) + + filename = part.get_filename() + conttype = part.get_content_type() + descrip_p = part.get_params(header='content-description') + + if charset == None: + charset = 'utf-8' + + if payload_b == None: + payload = None + else: + payload = payload_b.decode(charset) + + if descrip_p == None: + descript = None + else: + descript = descrip_p[0][0] + + + return payload, descript, filename, conttype + def decrypt_payload (payload):