summaryrefslogtreecommitdiff
path: root/alot/commands/thread.py
diff options
context:
space:
mode:
Diffstat (limited to 'alot/commands/thread.py')
-rw-r--r--alot/commands/thread.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 9319fb2c..c304fa0c 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -666,19 +666,21 @@ class OpenAttachmentCommand(Command):
logging.info('open attachment')
mimetype = self.attachment.get_content_type()
- handler, entry = settings.mailcap_find_match(mimetype)
- if handler:
- afterwards = None
+ # returns pair of preliminary command string and entry dict containing
+ # more info. We only use the dict and construct the command ourselves
+ _, entry = settings.mailcap_find_match(mimetype)
+ if entry:
+ afterwards = None # callback, will rm tempfile if used
handler_stdin = None
tempfile_name = None
- handler_commandstring = entry['view']
+ handler_raw_commandstring = entry['view']
# read parameter
part = self.attachment.get_mime_representation()
parms = tuple(map('='.join, part.get_params()))
# in case the mailcap defined command contains no '%s',
# we pipe the files content to the handling command via stdin
- if '%s' in handler_commandstring:
+ if '%s' in handler_raw_commandstring:
nametemplate = entry.get('nametemplate', '%s')
prefix, suffix = parse_mailcap_nametemplate(nametemplate)
tmpfile = tempfile.NamedTemporaryFile(delete=False,
@@ -688,23 +690,26 @@ class OpenAttachmentCommand(Command):
tempfile_name = tmpfile.name
self.attachment.write(tmpfile)
tmpfile.close()
+
def afterwards():
os.remove(tempfile_name)
else:
handler_stdin = StringIO()
self.attachment.write(handler_stdin)
+ # create handler command list
+ handler_cmd = mailcap.subst(handler_raw_commandstring, mimetype,
+ filename=tempfile_name, plist=parms)
- # create and call external command
- handler = mailcap.subst(handler_commandstring, mimetype,
- filename=tempfile_name, plist=parms)
-
+ handler_cmd = handler_cmd.encode('utf-8', errors='ignore')
+ handler_cmdlist = shlex.split(handler_cmd)
# 'needsterminal' makes handler overtake the terminal
nt = entry.get('needsterminal', None)
overtakes = (nt is None)
- ui.apply_command(ExternalCommand(handler, stdin=handler_stdin,
+ ui.apply_command(ExternalCommand(handler_cmdlist,
+ stdin=handler_stdin,
on_success=afterwards,
thread=overtakes))
else: