Skip to content

Commit

Permalink
editnew: Use raw body text instead of rendered version
Browse files Browse the repository at this point in the history
Rendering mail content via mailcap makes sense when viewing email, but
not when reusing the email for composing a new message, as it is
desirable to rather edit the "original" content and, if mailcap
rendering produces ANSI CSI escapes, the user would be left with a bunch
of garbarge characters.

Make sure that the editnew command do not render the body when creating
the envelope.
  • Loading branch information
guludo committed Feb 19, 2024
1 parent c1137ea commit fd4b284
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
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

0 comments on commit fd4b284

Please sign in to comment.