pazz / alot

Terminal-based Mail User Agent
GNU General Public License v3.0
696 stars 164 forks source link

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

Open mmartin opened 4 years ago

mmartin commented 4 years ago

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

Software Versions

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:

https://github.com/pazz/alot/blob/32b885d07e8a32695fbb6ebd92a41a7052b148c3/alot/db/utils.py#L469-L491

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

https://github.com/pazz/alot/blob/32b885d07e8a32695fbb6ebd92a41a7052b148c3/alot/buffers/thread.py#L59-L60

via

https://github.com/pazz/alot/blob/32b885d07e8a32695fbb6ebd92a41a7052b148c3/alot/db/message.py#L277-L280

kbingham commented 2 years ago

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