Skip to content

Commit

Permalink
retire Message.accumulate_body
Browse files Browse the repository at this point in the history
... in favour of get_body_text to de-clutter the Message class.
The functionality is implemented in alot.db.utils.extract_body, which
now contains the hard-coding of the html warning.
  • Loading branch information
pazz committed Aug 10, 2019
1 parent 0336d76 commit f4f0750
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
10 changes: 5 additions & 5 deletions alot/commands/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ async def apply(self, ui):
mailcontent = quotestring
quotehook = settings.get_hook('text_quote')
if quotehook:
mailcontent += quotehook(self.message.accumulate_body())
mailcontent += quotehook(self.message.get_body_text())
else:
quote_prefix = settings.get('quote_prefix')
for line in self.message.accumulate_body().splitlines():
for line in self.message.get_body_text().splitlines():
mailcontent += quote_prefix + line + '\n'

envelope = Envelope(bodytext=mailcontent, replied=self.message)
Expand Down Expand Up @@ -327,10 +327,10 @@ async def apply(self, ui):
mailcontent = quote
quotehook = settings.get_hook('text_quote')
if quotehook:
mailcontent += quotehook(self.message.accumulate_body())
mailcontent += quotehook(self.message.get_body_text())
else:
quote_prefix = settings.get('quote_prefix')
for line in self.message.accumulate_body().splitlines():
for line in self.message.get_body_text().splitlines():
mailcontent += quote_prefix + line + '\n'

envelope.body = mailcontent
Expand Down Expand Up @@ -463,7 +463,7 @@ async def apply(self, ui):
'signed', 'encrypted', 'unread', 'attachment'})
tags = list(tags)
# set body text
mailcontent = self.message.accumulate_body()
mailcontent = self.message.get_body_text()
envelope = Envelope(bodytext=mailcontent, tags=tags)

# copy selected headers
Expand Down
25 changes: 2 additions & 23 deletions alot/db/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@

charset.add_charset('utf-8', charset.QP, charset.QP, 'utf-8')

MISSING_HTML_MSG = ("This message contains a text/html part that was not "
"rendered due to a missing mailcap entry. "
"Please refer to item 5 in our FAQ: "
"http://alot.rtfd.io/en/latest/faq.html")


@functools.total_ordering
class Message:
Expand Down Expand Up @@ -265,25 +260,9 @@ def get_attachments(self):
self._attachments.append(Attachment(part))
return self._attachments

def accumulate_body(self):
"""
returns bodystring extracted from this mail
"""
# TODO: allow toggle commands to decide which part is considered body
eml = self.get_email()
bodytext = self.get_body_text()

# check if extracted body is empty dispite having a text/html body part
if eml is not None:
bodypart = eml.get_body()
if (bodypart and
bodypart.get_payload() and
eml.get_content_type() == 'text/html' and
not bodytext):
bodytext = MISSING_HTML_MSG
return bodytext

def get_body_text(self):
""" returns bodystring extracted from this mail """
# TODO: allow toggle commands to decide which part is considered body
return extract_body(self.get_email())

def matches(self, querystring):
Expand Down
9 changes: 9 additions & 0 deletions alot/db/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ def remove_cte(part, as_string=False):
return bp


MISSING_HTML_MSG = ("This message contains a text/html part that was not "
"rendered due to a missing mailcap entry. "
"Please refer to item 5 in our FAQ: "
"http://alot.rtfd.io/en/latest/faq.html")


def extract_body(mail):
"""Returns a string view of a Message.
Expand Down Expand Up @@ -488,6 +494,9 @@ def extract_body(mail):
rendered_payload = render_part(body_part)
if rendered_payload: # handler had output
displaystring = string_sanitize(rendered_payload)
else:
if body_part.get_content_type() == 'text/html':
displaystring = MISSING_HTML_MSG
return displaystring


Expand Down
2 changes: 1 addition & 1 deletion alot/widgets/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def _get_source(self):

def _get_body(self):
if self._bodytree is None:
bodytxt = self._message.accumulate_body()
bodytxt = self._message.get_body_text()
if bodytxt:
att = settings.get_theming_attribute('thread', 'body')
att_focus = settings.get_theming_attribute(
Expand Down

0 comments on commit f4f0750

Please sign in to comment.