summaryrefslogtreecommitdiff
path: root/alot/db/utils.py
diff options
context:
space:
mode:
authorLucas Hoffmann <l-m-h@web.de>2016-12-17 13:07:59 +0100
committerLucas Hoffmann <l-m-h@web.de>2016-12-18 09:49:26 +0100
commitf8635602757502fe27d63794c3a3511fc312f9ad (patch)
treec4ba8dc4af68f3070732c09c16ebb2d23f85eced /alot/db/utils.py
parenta2e3fb3a164766a9356e5082561acecccca1dbf5 (diff)
Use with blocks to write to temp files
Diffstat (limited to 'alot/db/utils.py')
-rw-r--r--alot/db/utils.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py
index 188a4b3a..ab20e26b 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -314,13 +314,11 @@ def extract_body(mail, types=None, field_key='copiousoutput'):
# open tempfile, respect mailcaps nametemplate
nametemplate = entry.get('nametemplate', '%s')
prefix, suffix = parse_mailcap_nametemplate(nametemplate)
- tmpfile = tempfile.NamedTemporaryFile(delete=False,
- prefix=prefix,
- suffix=suffix)
- # write payload to tmpfile
- tmpfile.write(raw_payload)
- tmpfile.close()
- tempfile_name = tmpfile.name
+ with tempfile.NamedTemporaryFile(
+ delete=False, prefix=prefix, suffix=suffix) \
+ as tmpfile:
+ tmpfile.write(raw_payload)
+ tempfile_name = tmpfile.name
else:
stdin = raw_payload