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

Can't open e-mails without a body #1538

Open
mmartin opened this issue Jul 30, 2020 · 1 comment
Open

Can't open e-mails without a body #1538

mmartin opened this issue Jul 30, 2020 · 1 comment

Comments

@mmartin
Copy link
Contributor

mmartin commented Jul 30, 2020

Describe the bug
I received an e-mail without a body, just an attachment. Alot fails to open it.

Software Versions

  • Python version: 3.8.2
  • Notmuch version: 0.29.3
  • Alot version: master

To Reproduce
Steps to reproduce the behaviour:

  1. try to open an e-mail without a body;
  2. Alot fails to open it.

Error Log

Traceback (most recent call last):
  File "/home/martins/code/alot/alot/ui.py", line 195, in _apply_fire
    await self.apply_commandline(cmdline)
  File "/home/martins/code/alot/alot/ui.py", line 283, in apply_commandline
    self._error_handler(e)
  File "/home/martins/code/alot/alot/ui.py", line 160, in _error_handler
    self.notify(msg, priority='error')
  File "/home/martins/code/alot/alot/ui.py", line 624, in notify
    self.update()
  File "/home/martins/code/alot/alot/ui.py", line 660, in update
    lines.append(self.build_statusbar())
  File "/home/martins/code/alot/alot/ui.py", line 677, in build_statusbar
    info = cb.get_info()
  File "/home/martins/code/alot/alot/buffers/thread.py", line 60, in get_info
    self.get_selected_message().get_mime_part().get_content_type())
AttributeError: 'str' object has no attribute 'get_content_type'

This is due to this function:

alot/alot/db/utils.py

Lines 469 to 491 in 32b885d

def get_body_part(mail, mimetype=None):
"""Returns an EmailMessage.
This consults :ref:`prefer_plaintext <prefer-plaintext>`
to determine if a "text/plain" alternative is preferred over a "text/html"
part.
:param mail: the mail to use
:type mail: :class:`email.message.EmailMessage`
:returns: The combined text of any parts to be used
:rtype: str
"""
if not mimetype:
mimetype = 'plain' if settings.get('prefer_plaintext') else 'html'
preferencelist = {
'plain': ('plain', 'html'), 'html': ('html', 'plain')}[mimetype]
body_part = mail.get_body(preferencelist)
if body_part is None: # if no part matching preferredlist was found
return ""
return body_part

Despite that :rtype: says str, it normally returns email.message.EmailMessage. And when there is no body it returns an empty string.

Which fails in

info['mimetype'] = (
self.get_selected_message().get_mime_part().get_content_type())

via

alot/alot/db/message.py

Lines 277 to 280 in 32b885d

def get_mime_part(self):
if not self._mime_part:
self._mime_part = get_body_part(self.get_email())
return self._mime_part

@kbingham
Copy link
Contributor

I have a similar issue but presenting a different trace.. (also on a mail that was a 'blank' body - but had content in the attachments...


ERROR:ui:Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/alot-0.9.1-py3.9.egg/alot/ui.py", line 723, in apply_command
    cmd.apply(self)
  File "/usr/local/lib/python3.9/dist-packages/alot-0.9.1-py3.9.egg/alot/commands/search.py", line 43, in apply
    tb.unfold_matching(query)
  File "/usr/local/lib/python3.9/dist-packages/alot-0.9.1-py3.9.egg/alot/buffers/thread.py", line 341, in unfold_matching
    MT.expand(MT.root)
  File "/usr/local/lib/python3.9/dist-packages/alot-0.9.1-py3.9.egg/alot/widgets/thread.py", line 215, in expand
    self.reassemble()
  File "/usr/local/lib/python3.9/dist-packages/alot-0.9.1-py3.9.egg/alot/widgets/thread.py", line 189, in reassemble
    self._maintree._treelist = self._assemble_structure()
  File "/usr/local/lib/python3.9/dist-packages/alot-0.9.1-py3.9.egg/alot/widgets/thread.py", line 235, in _assemble_structure
    bodytree = self._get_body()
  File "/usr/local/lib/python3.9/dist-packages/alot-0.9.1-py3.9.egg/alot/widgets/thread.py", line 269, in _get_body
    bodytxt = self._message.get_body_text()
  File "/usr/local/lib/python3.9/dist-packages/alot-0.9.1-py3.9.egg/alot/db/message.py", line 287, in get_body_text
    return extract_body_part(self.get_mime_part())
  File "/usr/local/lib/python3.9/dist-packages/alot-0.9.1-py3.9.egg/alot/db/utils.py", line 499, in extract_body_part
    **{'field_key': 'view'} if body_part.get_content_type() == 'text/plain'
AttributeError: 'str' object has no attribute 'get_content_type'

Software Versions

  • Python version: 3.9.5
  • Notmuch version: 0.31.4
  • Alot version: 0.9.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants