diff options
author | Kali Kaneko <kali@leap.se> | 2014-01-23 10:49:30 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2014-01-23 10:49:30 -0400 |
commit | bded9833da985034a11c30b342388c397798a585 (patch) | |
tree | 16a2ad88af9aee28f05754505b8b5e51d14f1a5f /src/leap | |
parent | 8211666507652c10e4c0965947c93d220b6c744e (diff) |
add constants to dict keys
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/mail/walk.py | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/leap/mail/walk.py b/src/leap/mail/walk.py index 27d672c..856daa3 100644 --- a/src/leap/mail/walk.py +++ b/src/leap/mail/walk.py @@ -107,10 +107,16 @@ def walk_msg_tree(parts, body_phash=None): in the outer content doc for convenience. :type body_phash: basestring or None """ + PART_MAP = "part_map" + MULTI = "multi" + HEADERS = "headers" + PHASH = "phash" + BODY = "body" + # parts vector pv = list(get_parts_vector(parts)) - inner_headers = parts[1].get("headers", None) if ( + inner_headers = parts[1].get(HEADERS, None) if ( len(parts) == 2) else None if DEBUG: @@ -129,10 +135,10 @@ def walk_msg_tree(parts, body_phash=None): slic = parts[wind + 1:wind + 1 + nsub] # slice with subparts cwra = { - "multi": True, - "part_map": dict((index + 1, part) # content wrapper - for index, part in enumerate(slic)), - "headers": dict(parts[wind]['headers']) + MULTI: True, + PART_MAP: dict((index + 1, part) # content wrapper + for index, part in enumerate(slic)), + HEADERS: dict(parts[wind][HEADERS]) } # remove subparts and substitue wrapper @@ -153,19 +159,19 @@ def walk_msg_tree(parts, body_phash=None): main_pmap[last_part]['part_map'][partind] = parts[partind+1] outer = parts[0] - outer.pop('headers') - if not "part_map" in outer: + outer.pop(HEADERS) + if not PART_MAP in outer: # we have a multipart with 1 part only, so kind of fix it # although it would be prettier if I take this special case at # the beginning of the walk. - pdoc = {"multi": True, - "part_map": {1: outer}} - pdoc["part_map"][1]["multi"] = False - if not pdoc["part_map"][1].get("phash", None): - pdoc["part_map"][1]["phash"] = body_phash + pdoc = {MULTI: True, + PART_MAP: {1: outer}} + pdoc[PART_MAP][1][MULTI] = False + if not pdoc[PART_MAP][1].get(PHASH, None): + pdoc[PART_MAP][1][PHASH] = body_phash if inner_headers: - pdoc["part_map"][1]["headers"] = inner_headers + pdoc[PART_MAP][1][HEADERS] = inner_headers else: pdoc = outer - pdoc["body"] = body_phash + pdoc[BODY] = body_phash return pdoc |