Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(conversations): keep mailgun stripped-signature in inbound email (#71875)

Alex V618183ad5bc1
diff --git a/products/conversations/backend/api/email_events.py b/products/conversations/backend/api/email_events.py
index 7ad82caf31b9..3fd91d3f60cf 100644
--- a/products/conversations/backend/api/email_events.py
+++ b/products/conversations/backend/api/email_events.py
@@ -368,8 +368,16 @@ def email_inbound_handler(request: HttpRequest) -> HttpResponse:
sender_email=sender_email,
)
- # 7. Get content (stripped by Mailgun to remove quotes/signatures)
- content = (request.POST.get("stripped-text", "") or request.POST.get("body-plain", ""))[:MAX_EMAIL_BODY_LENGTH]
+ # 7. Get content. Mailgun's stripped-text removes quoted replies, but its signature
+ # detection also cuts real content (e.g. a trailing list of bare emails/links), so we
+ # reattach stripped-signature to keep quote-stripping without losing customer text.
+ stripped_text = request.POST.get("stripped-text", "")
+ stripped_signature = request.POST.get("stripped-signature", "")
+ if stripped_text:
+ content = f"{stripped_text}\n\n{stripped_signature}" if stripped_signature else stripped_text
+ else:
+ content = request.POST.get("body-plain", "")
+ content = content[:MAX_EMAIL_BODY_LENGTH]
subject = request.POST.get("subject", "")[:500]
# 7b. Detect team member sender — only trust From when DKIM passes
diff --git a/products/conversations/backend/api/tests/test_email_endpoints.py b/products/conversations/backend/api/tests/test_email_endpoints.py
index 88cf31c17a69..eff8a5e6cd72 100644
--- a/products/conversations/backend/api/tests/test_email_endpoints.py
+++ b/products/conversations/backend/api/tests/test_email_endpoints.py
@@ -829,6 +829,62 @@ class TestEmailInboundMultiConfig(BaseTest):
assert ticket.email_config_id == config2.id
+class TestEmailInboundContent(BaseTest):
+ def setUp(self):
+ super().setUp()
+ self.client = Client()
+ self.team.conversations_settings = {"email_enabled": True}
+ self.team.save()
+ EmailChannel.objects.create(
+ team=self.team,
+ inbound_token="cc00dd11ee2233ff",
+ from_email="[email protected]",
+ from_name="Support",
+ domain="example.com",
+ domain_verified=True,
+ )
+
+ @parameterized.expand(
+ [
+ # Mailgun sometimes mis-classifies trailing content (e.g. a list of bare emails)
+ # as a signature — it must be reattached, not dropped.
+ (
+ "signature_reattached",
+ {"stripped-text": "Missing recordings for:", "stripped-signature": "[email protected]\[email protected]"},
+ "Missing recordings for:\n\[email protected]\[email protected]",
+ ),
+ (
+ "stripped_text_only",
+ {"stripped-text": "Just a question"},
+ "Just a question",
+ ),
+ (
+ "falls_back_to_body_plain",
+ {"body-plain": "Full body text"},
+ "Full body text",
+ ),
+ ]
+ )
+ @patch("products.conversations.backend.api.email_events.validate_webhook_signature", return_value=True)
+ def test_inbound_content_extraction(
+ self, _name: str, body_fields: dict[str, str], expected_content: str, _mock_sig: MagicMock
+ ):
+ response = self.client.post(
+ "/api/conversations/v1/email/inbound",
+ {
+ "recipient": "[email protected]",
+ "from": "[email protected]",
+ "Message-Id": f"<content-{_name}@test.com>",
+ "subject": "Help",
+ **body_fields,
+ },
+ )
+ assert response.status_code == 200
+
+ comment = Comment.objects.get(team=self.team, scope="conversations_ticket")
+ assert comment.content == expected_content
+
+
class TestSendEmailReplyMultiConfig(BaseTest):
def setUp(self):
super().setUp()