]> git.phdru.name Git - mimedecode.git/blobdiff - mimedecode/mimedecode.py
Version 3.2.0: Copy `mailcap.py` from Python 3.12
[mimedecode.git] / mimedecode / mimedecode.py
index ead1ab38493c7e5119d8204a8731747cc534647c..c5c80b0185524cbcde9ca47d1ee8e1d52794021d 100644 (file)
@@ -1,6 +1,7 @@
 """Decode MIME message"""
 
 import os
+import shutil
 import subprocess
 import sys
 
@@ -215,7 +216,10 @@ caps = None  # Globally stored mailcap database; initialized only if needed
 def decode_body(msg, s):
     "Decode body to plain text using first copiousoutput filter from mailcap"
 
-    import mailcap
+    try:
+        import mailcap
+    except ImportError:  # Python 3.13
+        from mimedecode import mailcap_312 as mailcap
     import tempfile
 
     global caps
@@ -528,4 +532,5 @@ def open_output_file(filename):
         return open(fullpath, 'wb')
     except Exception:
         if create:
-            os.removedirs(full_dir)
+            shutil.rmtree(full_dir)
+        raise