]>
git.madduck.net Git - etc/neomutt.git/blobdiff - .config/neomutt/buildmimetree.py
madduck's git repository
Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@ git. madduck. net .
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
SSH access, as well as push access can be individually
arranged .
If you use my repositories frequently, consider adding the following
snippet to ~/.gitconfig and using the third clone URL listed for each
project:
[url "git://git.madduck.net/madduck/"]
insteadOf = madduck:
class MIMETreeDFWalker:
def __init__(self, *, visitor_fn=None, debug=False):
class MIMETreeDFWalker:
def __init__(self, *, visitor_fn=None, debug=False):
- self._visitor_fn = visitor_fn
+ self._visitor_fn = visitor_fn or self._echovisit
+ 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`.
"""
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):
if isinstance(root, list):
- root = Multipart("mixed", children=root)
+ if len(root) > 1:
+ root = Multipart("mixed", children=root)
+ else:
+ root = root[0]
assert items[4][0].subtype == "relative"
assert items[4][1] == 0
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 = 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(
assert items[-1].subtype == "mixed"
def test_MIMETreeDFWalker_visitor_in_constructor(