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

Filtering invalid email addresses #564

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions froide/foirequest/tests/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ def test_html_only_mail(self):
self.assertIn(" ( https://", mail.body)
self.assertIn("*peter.mueller@kreis-steinfurt.de*", mail.body)

def test_invalid_mail_address(self):
Copy link
Member

Choose a reason for hiding this comment

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

Ideally this should be more a unit test (and less like a integration test): parsing a whole email just to test parsing of addresses makes this test not very specific. Also adding a large email with an image attachment (?!) is too much.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback! I agree this is to unspecific. I will remove this test and do it more like this (without parsing a whole email):

Suggested change
def test_invalid_mail_address(self):
def test_invalid_mail_address(self):
values = ["To: 'John Doe [#123]' <john.doe@example.com>"]
ret = get_address_list(values)
self.assertEqual('john.doe@example.com', ret[0].email)

with open(p("test_mail_14.txt"), "rb") as f:
mail = parse_email(f)
self.assertEqual('john.doe@example.com', mail.to[0][1])


class DeferredMessageTest(TestCase):
def setUp(self):
Expand Down