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

editnew: Use raw body text instead of rendered version #1648

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ async def apply(self, ui):
'signed', 'encrypted', 'unread', 'attachment'})
tags = list(tags)
# set body text
mailcontent = self.message.get_body_text()
mailcontent = self.message.get_body_text(render=False)
envelope = Envelope(bodytext=mailcontent, tags=tags)

# copy selected headers
Expand Down
4 changes: 2 additions & 2 deletions alot/db/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ def get_mime_part(self):
def set_mime_part(self, mime_part):
self._mime_part = mime_part

def get_body_text(self):
def get_body_text(self, render=True):
""" returns bodystring extracted from this mail """
return extract_body_part(self.get_mime_part())
return extract_body_part(self.get_mime_part(), render=render)

def matches(self, querystring):
"""tests if this messages is in the resultset for `querystring`"""
Expand Down
22 changes: 16 additions & 6 deletions alot/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,23 @@ def get_body_part(mail, mimetype=None):
return body_part


def extract_body_part(body_part):
"""Returns a string view of a Message."""
def extract_body_part(body_part, render=True):
"""
Returns a string view of a Message.

:param render: If true (the default), try to render the content with
`render_part`; otherwise skip rendering.
:type render: bool
"""
displaystring = ""
rendered_payload = render_part(
body_part,
**{'field_key': 'view'} if body_part.get_content_type() == 'text/plain'
else {})
if render:
rendered_payload = render_part(
body_part,
**{'field_key': 'view'} if body_part.get_content_type() == 'text/plain'
else {})
else:
rendered_payload = None

if rendered_payload: # handler had output
displaystring = string_sanitize(rendered_payload)
elif body_part.get_content_type() == 'text/plain':
Expand Down
Loading