-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Create problem report for bounced delivery reports
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,10 @@ | |
|
||
import pytest | ||
|
||
from froide.foirequest.models.request import FoiRequest | ||
from froide.foirequest.tests import factories | ||
from froide.problem.models import ProblemReport | ||
|
||
from ..email_log_parsing import ( | ||
PostfixLogfileParser, | ||
PostfixLogLine, | ||
|
@@ -53,6 +57,17 @@ def p(path): | |
} | ||
|
||
|
||
@pytest.fixture | ||
def req_with_msgs(world): | ||
secret_address = "[email protected]" | ||
req = factories.FoiRequestFactory.create( | ||
site=world, secret_address=secret_address, closed=True | ||
) | ||
factories.FoiMessageFactory.create(request=req) | ||
factories.FoiMessageFactory.create(request=req, is_response=True) | ||
return req | ||
|
||
|
||
def test_parse_field_minimal(): | ||
assert PostfixLogfileParser._parse_fields(DEMO_FIELDS) == { | ||
"to": "[email protected]", | ||
|
@@ -234,3 +249,23 @@ def callback(**kwargs): | |
print(invocations[0]) | ||
assert invocations[0]["message_id"] == MAIL_1_ID | ||
assert invocations[0]["log"] == MAIL_1_LOG | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_bouncing_email(req_with_msgs: FoiRequest): | ||
msg = req_with_msgs.messages[0] | ||
msg.email_message_id = "<[email protected]>" | ||
msg.save() | ||
problem_reports_before = ProblemReport.objects.filter(message=msg).count() | ||
# Check that problem report gets created | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
check_delivery_from_log(p("maillog_006.txt"), str(tmpdir + "/mail_log.offset")) | ||
assert ( | ||
ProblemReport.objects.filter(message=msg).count() == problem_reports_before + 1 | ||
) | ||
# Check that problem report does not created again | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
check_delivery_from_log(p("maillog_006.txt"), str(tmpdir + "/mail_log.offset")) | ||
assert ( | ||
ProblemReport.objects.filter(message=msg).count() == problem_reports_before + 1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Jul 7 13:01:25 brooke postfix/smtpd[581830]: ABCDEF12345: client=localhost.localdomain[127.0.0.1], sasl_method=PLAIN, [email protected] | ||
Jul 7 13:01:25 brooke postfix/cleanup[580201]: ABCDEF12345: message-id=<[email protected]> | ||
Jul 7 13:01:25 brooke postfix/qmgr[61174]: ABCDEF12345: from=<[email protected]>, size=5264, nrcpt=1 (queue active) | ||
Jul 7 13:01:27 brooke postfix/smtp[586922]: ABCDEF12345: to=<[email protected]>, relay=exapmle.com[1.2.3.4]:25, delay=2.6, delays=0.09/0/1/1.4, dsn=5.0.0, status=bounced (host example.com[1.2.3.4] said: 550-Callout verification failed: 550-550 5.1.1 <[email protected]>: Recipient address rejected: 550 Ungueltige Mail-Domain example.com (in reply to RCPT TO command)) | ||
Jul 7 13:01:27 brooke postfix/bounce[589205]: ABCDEF12345: sender non-delivery notification: 12345ABCDEF | ||
Jul 7 13:01:27 brooke postfix/qmgr[61174]: ABCDEF12345: removed |