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

Fix return type of message without a preferred body #1682

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

johslarsen
Copy link
Contributor

The get_body(...) call (and hence the nominal return of the get_body_part(...) method) returns a email.message.EmailMessage. So if there is no body return an empty such class instead of a string, because the callers expects that it behaves like a message. E.g.:

  File "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'

Someone sent me a message where the body was some encapsulated message. I still have not gotten it rendered properly, but showing up as an empty message is at least better than crashing alot

The `get_body(...)` call (and hence the nominal return of the
`get_body_part(...)` method) returns a email.message.EmailMessage. So if
there is no body return an empty such class instead of a string, because
the callers expects that it behaves like a message. E.g.:

      File "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'
Copy link
Owner

@pazz pazz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this. The code is simple and fixes a known issue.
Lont term it would perhaps be good to recurr in such situations but better displaying an empty mail than going belly up

@pazz pazz merged commit d7fae55 into pazz:master Oct 30, 2024
13 checks passed
@pazz
Copy link
Owner

pazz commented Oct 30, 2024

Thanks for your contribution :)

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

Successfully merging this pull request may close these issues.

2 participants