1
0
Эх сурвалжийг харах

add: image as dict work without maintype specified
It's redundant to specify maintype as it should be image when we embed
such to the body. Also slightly reworded the exception message to
prevent printing image data.

Mikael Koli 4 жил өмнө
parent
commit
80a62226a5
1 өөрчлөгдсөн 9 нэмэгдсэн , 3 устгасан
  1. 9 3
      redmail/email/body.py

+ 9 - 3
redmail/email/body.py

@@ -192,11 +192,17 @@ class HTMLBody(Body):
 
             elif isinstance(img, dict):
                 # Expecting dict explanation of bytes
-                # ie. {"maintype": "image", "subtype": "png", "content"}
-                required_keys = ("content", "maintype", "subtype")
+                # ie. {"maintype": "image", "subtype": "png", "content": b'...'}
+
+                # Setting defaults
+                img['maintype'] = img.get('maintype', 'image')
+
+                # Validation
+                required_keys = ("content", "subtype")
                 if any(key not in img for key in required_keys):
                     missing_keys = tuple(key for key in required_keys if key not in img)
-                    raise KeyError(f"Image {repr(img)} missing keys: {missing_keys}")
+                    raise KeyError(f"Dict representation of an image missing keys: {missing_keys}")
+                
                 img_content = img.pop("content")
                 kwds = img