Create the directory for the output files (-O) if it doesn't exits.
Add option -O to set the destination directory for output files.
+ Create the directory for the output files (-O) if it doesn't exits.
+
Fix a minor bug: if a multipart message (or a subpart) lacks any textual
content - avoid putting an excessive newline.
<term>-O dest_dir</term>
<listitem>
<para>
- Set destination directory for the output files; the directory must
- exist. Default is current directory.
+ Set destination directory for the output files; if the directory
+ doesn't exist it will be created. Default is current directory.
</para>
</listitem>
</varlistentry>
def open_output_file(filename):
- return open(os.path.join(g.destination_dir, filename), 'w')
+ fullpath = os.path.abspath(os.path.join(g.destination_dir, filename))
+ full_dir = os.path.dirname(fullpath)
+ create = not os.path.isdir(full_dir)
+ if create:
+ os.makedirs(full_dir)
+ try:
+ return open(fullpath, 'w')
+ except:
+ if create:
+ os.removedirs(full_dir)
class GlobalOptions: