[Crash] error parsing email objects #40

Open
opened 2019-06-10 09:48:48 +00:00 by b3yond · 7 comments
Owner

Author: @b3yond Posted at: 25.09.2018 09:38

Expected Behavior

when an email is received, it searches for patterns in the body to check if it is appropriate.

Actual Behavior

it crashes, because the email body is not passed correctly - report.text needs to be a string.

Traceback:

Traceback (most recent call last):
  File "backend.py", line 36, in <module>
    if not user.is_appropriate(status):
  File "/srv/ticketfrei/user.py", line 65, in is_appropriate
    if pattern in report.text.lower():
AttributeError: 'list' object has no attribute 'lower'
Author: @b3yond Posted at: 25.09.2018 09:38 # Expected Behavior when an email is received, it searches for patterns in the body to check if it is appropriate. # Actual Behavior it crashes, because the email body is not passed correctly - report.text needs to be a string. # Traceback: ``` Traceback (most recent call last): File "backend.py", line 36, in <module> if not user.is_appropriate(status): File "/srv/ticketfrei/user.py", line 65, in is_appropriate if pattern in report.text.lower(): AttributeError: 'list' object has no attribute 'lower' ```
b3yond added the
bug
wait to be tested
labels 2019-06-10 09:48:48 +00:00
Author
Owner

Author: @d24phant Posted at: 07.10.2018 07:07

report.text is fed by the email.message.get_payload() function:

The payload is either a string or bytes object, in the case of simple message objects, or a list of EmailMessage objects, for MIME container documents such as multipart/* and message/rfc822 message objects.
(source: https://docs.python.org/3/library/email.message.html )

The case of a simple string or bytes object is well covered, the problem here is that it was the only test case ;)

We need to decide how we treat the EmailMessage objects in this list; do we want to put all of them in report.text?

Author: @d24phant Posted at: 07.10.2018 07:07 report.text is fed by the email.message.get_payload() function: > The payload is either a string or bytes object, in the case of simple message objects, or a list of EmailMessage objects, for MIME container documents such as multipart/* and message/rfc822 message objects. (source: https://docs.python.org/3/library/email.message.html ) The case of a simple string or bytes object is well covered, the problem here is that it was the only test case ;) We need to decide how we treat the EmailMessage objects in this list; do we want to put all of them in report.text?
Author
Owner

Author: @b3yond Posted at: 07.10.2018 16:51

untreated MIMEtypes which are multipart are logged - we should revisit this once in a while.

Author: @b3yond Posted at: 07.10.2018 16:51 untreated MIMEtypes which are multipart are logged - we should revisit this once in a while.
Author
Owner

Author: @b3yond Posted at: 07.10.2018 21:18

doesn't work yet, not even text works anymore.

test case:

1. send text email to testfrei@ticketfrei.links-tech.org

1. send signed text email to testfrei@ticketfrei.links-tech.org

1. send html email reply to testfrei@ticketfrei.links-tech.org

1. send signed html email reply to testfrei@ticketfrei.links-tech.org

1. send html email to testfrei@ticketfrei.links-tech.org

1. send signed html email to testfrei@ticketfrei.links-tech.org

expected:

all are tweeted

actual:

all landed in /var/mail/tech, but none was tweeted.
2 and 3 were posted via mail.
after some delay, fixes, and a restart, 1, 3, and 5 got posted via mail and tweeted.
Author: @b3yond Posted at: 07.10.2018 21:18 doesn't work yet, not even text works anymore. test case: ``` 1. send text email to testfrei@ticketfrei.links-tech.org 1. send signed text email to testfrei@ticketfrei.links-tech.org 1. send html email reply to testfrei@ticketfrei.links-tech.org 1. send signed html email reply to testfrei@ticketfrei.links-tech.org 1. send html email to testfrei@ticketfrei.links-tech.org 1. send signed html email to testfrei@ticketfrei.links-tech.org expected: all are tweeted actual: all landed in /var/mail/tech, but none was tweeted. 2 and 3 were posted via mail. after some delay, fixes, and a restart, 1, 3, and 5 got posted via mail and tweeted. ```
Author
Owner

Author: @b3yond Posted at: 07.10.2018 21:27

During the test, there were some shutdowns:

Shutdown.
Traceback (most recent call last):
  File "backend.py", line 34, in <module>
    reports = bot.crawl(user)
  File "/srv/ticketfrei/active_bots/mailbot.py", line 26, in crawl
    reports.append(make_report(msg, user))
  File "/srv/ticketfrei/active_bots/mailbot.py", line 66, in make_report
    if p.get_content_type() == "text":
AttributeError: 'str' object has no attribute 'get_content_type'

quickfix on master

Author: @b3yond Posted at: 07.10.2018 21:27 During the test, there were some shutdowns: ``` Shutdown. Traceback (most recent call last): File "backend.py", line 34, in <module> reports = bot.crawl(user) File "/srv/ticketfrei/active_bots/mailbot.py", line 26, in crawl reports.append(make_report(msg, user)) File "/srv/ticketfrei/active_bots/mailbot.py", line 66, in make_report if p.get_content_type() == "text": AttributeError: 'str' object has no attribute 'get_content_type' ``` quickfix on master
Author
Owner

Author: @b3yond Posted at: 07.10.2018 21:46

pgp signed mails don't get posted yet, but the other mails went through.

another test run would be nice, but I'm too fucking tired.

Author: @b3yond Posted at: 07.10.2018 21:46 pgp signed mails don't get posted yet, but the other mails went through. another test run would be nice, but I'm too fucking tired.
Author
Owner

Author: @b3yond Posted at: 08.10.2018 13:17

pgp signed mails don't throw errors anymore. They are still not posted. Nasty, but I would not consider it a release blocker.

Author: @b3yond Posted at: 08.10.2018 13:17 pgp signed mails don't throw errors anymore. They are still not posted. Nasty, but I would not consider it a release blocker.
Author
Owner

Author: @d24phant Posted at: 08.10.2018 18:00

Me neither ;) Not perfect, but shouldn't prevent from releasing!

Author: @d24phant Posted at: 08.10.2018 18:00 Me neither ;) Not perfect, but shouldn't prevent from releasing!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: b3yond/ticketfrei#40
No description provided.