Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mime part pipeto support. #1481

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
from ..db.utils import decode_header
from ..db.utils import formataddr
from ..db.utils import get_body_part
from ..db.utils import extract_body_part
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 @@ -632,7 +635,9 @@ def apply(self, ui):
(['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',
'plain', 'html']}),
(['--separately'], {'action': 'store_true',
'help': 'call command once for each message'}),
(['--background'], {'action': 'store_true',
Expand Down Expand Up @@ -671,6 +676,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 @@ -733,15 +739,22 @@ async def apply(self, ui):
else:
for msg in to_print:
mail = msg.get_email()
mimepart = (getattr(ui.get_deep_focus(), 'mimepart', False)
or msg.get_mime_part())
if self.add_tags:
mail.add_header('Tags', ', '.join(msg.get_tags()))
if self.output_format == 'raw':
pipestrings.append(mail.as_string())
elif self.output_format == 'decoded':
headertext = extract_headers(mail)
bodytext = msg.get_body_text()
bodytext = extract_body_part(mimepart)
msgtext = '%s\n\n%s' % (headertext, bodytext)
pipestrings.append(msgtext)
elif self.output_format in ['mimepart', 'plain', 'html']:
if self.output_format in ['plain', 'html']:
mimepart = get_body_part(mail, self.output_format)
pipestrings.append(string_sanitize(remove_cte(
mimepart, 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','plain','html' (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