Skip to content

Commit

Permalink
Add pipeto --format=mimepart option.
Browse files Browse the repository at this point in the history
The most notable use case is piping html to a browser without extra
scripts such as those shared in #789.
  • Loading branch information
ryneeverett committed Mar 23, 2020
1 parent 25f5177 commit f163685
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from ..db.utils import extract_headers
from ..db.utils import clear_my_address
from ..db.utils import ensure_unique_address
from ..db.utils import remove_cte
from ..db.utils import string_sanitize
from ..db.envelope import Envelope
from ..db.attachment import Attachment
from ..db.errors import DatabaseROError
Expand Down Expand Up @@ -630,7 +632,8 @@ def matches(msgt):
(['cmd'], {'help': 'shellcommand to pipe to', 'nargs': '+'}),
(['--all'], {'action': 'store_true', 'help': 'pass all messages'}),
(['--format'], {'help': 'output format', 'default': 'raw',
'choices': ['raw', 'decoded', 'id', 'filepath']}),
'choices': [
'raw', 'decoded', 'id', 'filepath', 'mimepart']}),
(['--separately'], {'action': 'store_true',
'help': 'call command once for each message'}),
(['--background'], {'action': 'store_true',
Expand Down Expand Up @@ -669,6 +672,7 @@ def __init__(self, cmd, all=False, separately=False, background=False,
'decoded': message content, decoded quoted printable,
'id': message ids, separated by newlines,
'filepath': paths to message files on disk
'mimepart': only pipe the currently selected mime part
:type format: str
:param add_tags: add 'Tags' header to the message
:type add_tags: bool
Expand Down Expand Up @@ -740,6 +744,9 @@ async def apply(self, ui):
bodytext = msg.get_body_text()
msgtext = '%s\n\n%s' % (headertext, bodytext)
pipestrings.append(msgtext)
elif self.output_format == 'mimepart':
pipestrings.append(string_sanitize(remove_cte(
msg.mime_part, as_string=True)))

if not self.separately:
pipestrings = [separator.join(pipestrings)]
Expand Down
2 changes: 1 addition & 1 deletion docs/source/usage/modes/thread.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The following commands are available in thread mode:

optional arguments
:---all: pass all messages
:---format: output format; valid choices are: 'raw','decoded','id','filepath' (defaults to: 'raw')
:---format: output format; valid choices are: 'raw','decoded','id','filepath','mimepart' (defaults to: 'raw')
:---separately: call command once for each message
:---background: don't stop the interface
:---add_tags: add 'Tags' header to the message
Expand Down

0 comments on commit f163685

Please sign in to comment.