diff options
author | Kali Kaneko <kali@leap.se> | 2014-02-07 05:50:55 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2014-02-17 11:39:44 -0400 |
commit | b92e63c316c1cf9f8b6481dbfa70737acfb3eee9 (patch) | |
tree | e60e9b6e5367ad185c9f387f2ff6af9fd6c726f9 /src/leap/mail/utils.py | |
parent | 813db4a356141592337f39f9c801203367c63193 (diff) |
separate better dirty/new flags; add cdocs
Diffstat (limited to 'src/leap/mail/utils.py')
-rw-r--r-- | src/leap/mail/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/leap/mail/utils.py b/src/leap/mail/utils.py index 942acfb..8b75cfc 100644 --- a/src/leap/mail/utils.py +++ b/src/leap/mail/utils.py @@ -94,6 +94,7 @@ def lowerdict(_dict): PART_MAP = "part_map" +PHASH = "phash" def _str_dict(d, k): @@ -130,6 +131,24 @@ def stringify_parts_map(d): return d +def phash_iter(d): + """ + A recursive generator that extracts all the payload-hashes + from an arbitrary nested parts-map dictionary. + + :param d: the dictionary to walk + :type d: dictionary + :return: a list of all the phashes found + :rtype: list + """ + if PHASH in d: + yield d[PHASH] + if PART_MAP in d: + for key in d[PART_MAP]: + for phash in phash_iter(d[PART_MAP][key]): + yield phash + + class CustomJsonScanner(object): """ This class is a context manager definition used to monkey patch the default |