X-Git-Url: https://git.madduck.net/etc/neomutt.git/blobdiff_plain/00a8a4417bbed5a609adb33039f47d711fd0e404..89d63f768f54f61056d0d4cec37800ac4dd9a0bc:/.config/neomutt/buildmimetree.py?ds=sidebyside diff --git a/.config/neomutt/buildmimetree.py b/.config/neomutt/buildmimetree.py index e2a23a7..779f60b 100755 --- a/.config/neomutt/buildmimetree.py +++ b/.config/neomutt/buildmimetree.py @@ -339,17 +339,22 @@ def convert_markdown_to_html( class MIMETreeDFWalker: def __init__(self, *, visitor_fn=None, debug=False): - self._visitor_fn = visitor_fn + self._visitor_fn = visitor_fn or self._echovisit self._debug = debug + def _echovisit(self, node, ancestry, debugprint): + debugprint(f"node={node} ancestry={ancestry}") + def walk(self, root, *, visitor_fn=None): """ Recursive function to implement a depth-dirst walk of the MIME-tree rooted at `root`. """ - if isinstance(root, list): - root = Multipart("mixed", children=root) + if len(root) > 1: + root = Multipart("mixed", children=root) + else: + root = root[0] self._walk( root, @@ -720,14 +725,17 @@ try: assert items[4][0].subtype == "relative" assert items[4][1] == 0 - def test_MIMETreeDFWalker_list_to_mixed(self, basic_mime_tree): + def test_MIMETreeDFWalker_list_to_mixed(self, const1): mimetree = MIMETreeDFWalker() items = [] def visitor_fn(item, stack, debugprint): items.append(item) - mimetree.walk([basic_mime_tree], visitor_fn=visitor_fn) + p = Part("text", "plain", const1) + mimetree.walk([p], visitor_fn=visitor_fn) + assert items[-1].subtype == "plain" + mimetree.walk([p, p], visitor_fn=visitor_fn) assert items[-1].subtype == "mixed" def test_MIMETreeDFWalker_visitor_in_constructor(