summaryrefslogtreecommitdiff
path: root/alot/db
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2013-03-20 20:29:20 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2013-03-20 20:29:20 +0000
commit8adffebc1371154f9c55e34b4c9d04a11923e637 (patch)
treef42af82aa010e33632cf4404bfddd0070dd1311d /alot/db
parent57913bf6705cf3f16c738278550777822f7c4584 (diff)
respect mailcap commands that expect stdin
This ensures that we respect if a command as specified per mailcap expects its input via stdin and not per tempfile. This was already done for opening of attachments but not for interpreting non-text/plain message parts. fix #584
Diffstat (limited to 'alot/db')
-rw-r--r--alot/db/utils.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py
index 2ee9e03e..1280667a 100644
--- a/alot/db/utils.py
+++ b/alot/db/utils.py
@@ -86,31 +86,43 @@ def extract_body(mail, types=None):
#get mime handler
key = 'copiousoutput'
handler, entry = settings.mailcap_find_match(ctype, key=key)
+ tempfile_name = None
+ stdin = None
if entry:
- # open tempfile, respect mailcaps nametemplate
- nametemplate = entry.get('nametemplate', '%s')
- prefix, suffix = parse_mailcap_nametemplate(nametemplate)
- tmpfile = tempfile.NamedTemporaryFile(delete=False,
- prefix=prefix,
- suffix=suffix)
- # write payload to tmpfile
- tmpfile.write(raw_payload)
- tmpfile.close()
+ handler_raw_commandstring = entry['view']
+ # in case the mailcap defined command contains no '%s',
+ # we pipe the files content to the handling command via stdin
+ if '%s' in handler_raw_commandstring:
+ # open tempfile, respect mailcaps nametemplate
+ nametemplate = entry.get('nametemplate', '%s')
+ prefix, suffix = parse_mailcap_nametemplate(nametemplate)
+ tmpfile = tempfile.NamedTemporaryFile(delete=False,
+ prefix=prefix,
+ suffix=suffix)
+ # write payload to tmpfile
+ tmpfile.write(raw_payload)
+ tmpfile.close()
+ tempfile_name = tmpfile.name
+ else:
+ stdin = raw_payload
# read parameter, create handler command
parms = tuple(map('='.join, part.get_params()))
# create and call external command
cmd = mailcap.subst(entry['view'], ctype,
- filename=tmpfile.name, plist=parms)
+ filename=tempfile_name, plist=parms)
logging.debug('command: %s' % cmd)
logging.debug('parms: %s' % str(parms))
cmdlist = split_commandstring(cmd)
# call handler
- rendered_payload, errmsg, retval = helper.call_cmd(cmdlist)
+ rendered_payload, errmsg, retval = helper.call_cmd(cmdlist, stdin=stdin)
+
# remove tempfile
- os.unlink(tmpfile.name)
+ if tempfile_name:
+ os.unlink(tempfile_name)
+
if rendered_payload: # handler had output
body_parts.append(string_sanitize(rendered_payload))
return u'\n\n'.join(body_parts)