Storing the temp file in the Mutt object worked. Here is the incremental diff.
=== modified file 'bzrlib/mail_client.py'
--- bzrlib/mail_client.py 2009-06-07 01:17:13 +0000
+++ bzrlib/mail_client.py 2009-06-08 17:43:56 +0000
@@ -271,16 +271,13 @@ message_options.extend(['-a', self._encode_path(attach_path, 'attachment')])
if body is not None:
- # mkstemp() is used instead of NamedTemporaryFile, so that
- # the file won't be deleted when the object gets garbage
- # collected, which may be before mutt can read it.
- fd, temp_file = tempfile.mkstemp(prefix="mutt-body-",
- suffix=".txt")
- try:
- os.write(fd, body)
- finally:
- os.close(fd)
- message_options.extend(['-i', temp_file])
+ # Store the temp file object in self, so that it does not get
+ # garbage collected and delete the file before mutt can read it.
+ self._temp_file = tempfile.NamedTemporaryFile(
+ prefix="mutt-body-", suffix=".txt")
+ self._temp_file.write(body)
+ self._temp_file.flush()
+ message_options.extend(['-i', self._temp_file.name])
if to is not None: message_options.extend(['--', self._encode_safe(to)])
return message_options
Storing the temp file in the Mutt object worked. Here is the incremental diff.
=== modified file 'bzrlib/ mail_client. py' mail_client. py 2009-06-07 01:17:13 +0000 mail_client. py 2009-06-08 17:43:56 +0000
message_ options. extend( ['-a',
self. _encode_ path(attach_ path, 'attachment')]) mkstemp( prefix= "mutt-body- ", options. extend( ['-i', temp_file]) NamedTemporaryF ile( "mutt-body- ", suffix=".txt") file.write( body) file.flush( ) options. extend( ['-i', self._temp_ file.name] )
message_ options. extend( ['--', self._encode_ safe(to) ])
--- bzrlib/
+++ bzrlib/
@@ -271,16 +271,13 @@
if body is not None:
- # mkstemp() is used instead of NamedTemporaryFile, so that
- # the file won't be deleted when the object gets garbage
- # collected, which may be before mutt can read it.
- fd, temp_file = tempfile.
- suffix=".txt")
- try:
- os.write(fd, body)
- finally:
- os.close(fd)
- message_
+ # Store the temp file object in self, so that it does not get
+ # garbage collected and delete the file before mutt can read it.
+ self._temp_file = tempfile.
+ prefix=
+ self._temp_
+ self._temp_
+ message_
if to is not None:
return message_options