Skip to content

Commit

Permalink
Merge pull request #752 from jkoelker/pipeto_field_key
Browse files Browse the repository at this point in the history
Allow specifing the mailcap field key for `pipeto`
  • Loading branch information
pazz committed Dec 6, 2016
2 parents 8774731 + a7d8886 commit da31729
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 8 additions & 2 deletions alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ def matches(msgt):
'help': 'let the shell interpret the command'}),
(['--notify_stdout'], {'action': 'store_true',
'help': 'display cmd\'s stdout as notification'}),
(['--field_key'], {'help': 'mailcap field key for decoding',
'default': 'copiousoutput'}),
],
)
class PipeCommand(Command):
Expand All @@ -608,7 +610,8 @@ class PipeCommand(Command):
def __init__(self, cmd, all=False, separately=False, background=False,
shell=False, notify_stdout=False, format='raw',
add_tags=False, noop_msg='no command specified',
confirm_msg='', done_msg=None, **kwargs):
confirm_msg='', done_msg=None, field_key='copiousoutput',
**kwargs):
"""
:param cmd: shellcommand to open
:type cmd: str or list of str
Expand Down Expand Up @@ -637,6 +640,8 @@ def __init__(self, cmd, all=False, separately=False, background=False,
:type confirm_msg: str
:param done_msg: notification message to show upon success
:type done_msg: str
:param field_key: malcap field key for decoding
:type field_key: str
"""
Command.__init__(self, **kwargs)
if isinstance(cmd, unicode):
Expand All @@ -652,6 +657,7 @@ def __init__(self, cmd, all=False, separately=False, background=False,
self.noop_msg = noop_msg
self.confirm_msg = confirm_msg
self.done_msg = done_msg
self.field_key = field_key

@inlineCallbacks
def apply(self, ui):
Expand Down Expand Up @@ -697,7 +703,7 @@ def apply(self, ui):
pipestrings.append(mail.as_string())
elif self.output_format == 'decoded':
headertext = extract_headers(mail)
bodytext = extract_body(mail)
bodytext = extract_body(mail, field_key=self.field_key)
msgtext = '%s\n\n%s' % (headertext, bodytext)
pipestrings.append(msgtext.encode('utf-8'))

Expand Down
5 changes: 2 additions & 3 deletions alot/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def extract_headers(mail, headers=None):
return headertext


def extract_body(mail, types=None):
def extract_body(mail, types=None, field_key='copiousoutput'):
"""
returns a body text string for given mail.
If types is `None`, `text/*` is used:
Expand Down Expand Up @@ -301,8 +301,7 @@ def extract_body(mail, types=None):
body_parts.append(string_sanitize(raw_payload))
else:
# get mime handler
key = 'copiousoutput'
handler, entry = settings.mailcap_find_match(ctype, key=key)
handler, entry = settings.mailcap_find_match(ctype, key=field_key)
tempfile_name = None
stdin = None

Expand Down

0 comments on commit da31729

Please sign in to comment.