X-Git-Url: https://git.madduck.net/etc/neomutt.git/blobdiff_plain/6648ac73321ea964c9882c4d4e391e0460c1a855..ecd2dcdf8b56f8a63c3c6a941fd5d004c6788889:/.config/neomutt/buildmimetree.py diff --git a/.config/neomutt/buildmimetree.py b/.config/neomutt/buildmimetree.py index f10158f..a4805b2 100755 --- a/.config/neomutt/buildmimetree.py +++ b/.config/neomutt/buildmimetree.py @@ -125,6 +125,11 @@ def parse_cli_args(*args, **kwargs): help="Only build, don't send the message", ) + parser.add_argument( + "--domain", + help="Domain to use in content IDs", + ) + parser.add_argument( "--tempdir", metavar="DIR", @@ -349,12 +354,12 @@ class ImageRegistry: def __init__(self): self._images = OrderedDict() - def register(self, path, description=None): + def register(self, path, description=None, *, domain=None): # path = str(pathlib.Path(path).expanduser()) path = os.path.expanduser(path) if path.startswith("/"): path = f"file://{path}" - cid = make_msgid()[1:-1] + cid = make_msgid(domain=domain)[1:-1] self._images[path] = InlineImageInfo(cid, description) return cid @@ -700,6 +705,7 @@ def convert_markdown_to_html( tempdir=None, extensions=None, extension_configs=None, + domain=None, ): # TODO extension_configs need to be handled differently extension_configs = extension_configs or {} @@ -734,7 +740,7 @@ def convert_markdown_to_html( for img in soup.find_all("img"): uri = img.attrs["src"] desc = img.attrs.get("title", img.attrs.get("alt")) - cid = image_registry.register(uri, desc) + cid = image_registry.register(uri, desc, domain=domain) img.attrs["src"] = f"cid:{cid}" htmlsig = str(soup) @@ -964,6 +970,7 @@ def do_massage( only_build=False, max_other_attachments=20, tempdir=None, + domain=None, debug_commands=False, debug_walk=False, ): @@ -985,6 +992,7 @@ def do_massage( related_to_html_only=related_to_html_only, tempdir=tempdir, extensions=extensions, + domain=domain, ) mimetree = MIMETreeDFWalker(debug=debug_walk) @@ -1157,6 +1165,7 @@ if __name__ == "__main__": max_other_attachments=args.max_number_other_attachments, only_build=args.only_build, tempdir=args.tempdir, + domain=args.domain, debug_commands=args.debug_commands, debug_walk=args.debug_walk, ) @@ -1868,6 +1877,15 @@ try: assert not cid.endswith(">") assert const1 in reg + @pytest.mark.imgproc + def test_image_registry_domain(self, const1, const2): + reg = ImageRegistry() + cid = reg.register(const1, domain=const2) + assert f"@{const2}" in cid + assert not cid.startswith("<") + assert not cid.endswith(">") + assert const1 in reg + @pytest.mark.imgproc def test_image_registry_file_uri(self, const1): reg = ImageRegistry()