summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alot/commands/envelope.py5
-rw-r--r--alot/commands/globals.py6
-rw-r--r--alot/db/message.py5
-rw-r--r--alot/helper.py3
4 files changed, 10 insertions, 9 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py
index 2c35c2aa..52ce5be9 100644
--- a/alot/commands/envelope.py
+++ b/alot/commands/envelope.py
@@ -324,10 +324,9 @@ class EditCommand(Command):
# get input
# tempfile will be removed on buffer cleanup
- f = open(self.envelope.tmpfile.name)
enc = settings.get('editor_writes_encoding')
- template = string_decode(f.read(), enc)
- f.close()
+ with open(self.envelope.tmpfile.name) as f:
+ template = string_decode(f.read(), enc)
# call post-edit translate hook
translate = settings.get_hook('post_edit_translate')
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index 7d5c1d3e..437b3644 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -733,7 +733,8 @@ class ComposeCommand(Command):
priority='error')
return
try:
- self.envelope.parse_template(open(path).read())
+ with open(path) as f:
+ self.envelope.parse_template(f.read())
except Exception as e:
ui.notify(str(e), priority='error')
return
@@ -792,7 +793,8 @@ class ComposeCommand(Command):
self.envelope.attach(sig, filename=name)
logging.debug('attached')
else:
- sigcontent = open(sig).read()
+ with open(sig) as f:
+ sigcontent = f.read()
enc = helper.guess_encoding(sigcontent)
mimetype = helper.guess_mimetype(sigcontent)
if mimetype.startswith('text'):
diff --git a/alot/db/message.py b/alot/db/message.py
index 91a0f420..0a129992 100644
--- a/alot/db/message.py
+++ b/alot/db/message.py
@@ -70,9 +70,8 @@ class Message(object):
"Message file is no longer accessible:\n%s" % path
if not self._email:
try:
- f_mail = open(path)
- self._email = message_from_file(f_mail)
- f_mail.close()
+ with open(path) as f:
+ self._email = message_from_file(f)
except IOError:
self._email = email.message_from_string(warning)
return self._email
diff --git a/alot/helper.py b/alot/helper.py
index f968306d..ba68bd45 100644
--- a/alot/helper.py
+++ b/alot/helper.py
@@ -465,7 +465,8 @@ def libmagic_version_at_least(version):
# TODO: make this work on blobs, not paths
def mimewrap(path, filename=None, ctype=None):
- content = open(path, 'rb').read()
+ with open(path, 'rb') as f:
+ content = f.read()
if not ctype:
ctype = guess_mimetype(content)
# libmagic < 5.12 incorrectly detects excel/powerpoint files as