Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff --git a/alot/buffers.py b/alot/buffers.py
index 866e149..51ef49b 100644
--- a/alot/buffers.py
+++ b/alot/buffers.py
@@ -2,6 +2,7 @@
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
import urwid
+import os
from notmuch import NotmuchError
import widgets
@@ -120,6 +121,10 @@ class EnvelopeBuffer(Buffer):
info['to'] = self.envelope.get('To', fallback='unset')
return info
+ def cleanup(self):
+ for tmp in self.envelope.tf:
+ os.unlink(tmp.name)
+
def rebuild(self):
displayed_widgets = []
hidden = settings.get('envelope_headers_blacklist')
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py
index 7f6bcc3..8afe2db 100644
--- a/alot/commands/envelope.py
+++ b/alot/commands/envelope.py
@@ -226,8 +226,9 @@ class EditCommand(Command):
# worry about encodings.
# get input
+ # tempfile will be removed on buffer cleanup
+
f = open(tf.name)
- os.unlink(tf.name)
enc = settings.get('editor_writes_encoding')
template = string_decode(f.read(), enc)
f.close()
@@ -277,6 +278,7 @@ class EditCommand(Command):
#write stuff to tempfile
tf = tempfile.NamedTemporaryFile(delete=False, prefix='alot.')
+ self.envelope.tf.append(tf) # for later cleanup
tf.write(content.encode('utf-8'))
tf.flush()
tf.close()
diff --git a/alot/db/envelope.py b/alot/db/envelope.py
index f464eba..cff8101 100644
--- a/alot/db/envelope.py
+++ b/alot/db/envelope.py
@@ -42,6 +42,7 @@ class Envelope(object):
assert isinstance(bodytext, unicode)
self.headers = {}
self.body = None
+ self.tf = list()
logging.debug('TEMPLATE: %s' % template)
if template:
self.parse_template(template)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.