Files
mail-intake/mail_intake/models/thread.py
Vishesh 'ironeagle' Bangotra 371b74806f chore(release): 0.0.3
Squash-merge lib-standardisation: adopt repo standards across packaging,
tooling, docs, and CI.

- standardize pyproject.toml (canonical packaging, lint config, extras, GSDFC pydoclint)
- add py.typed marker, modernize type hints and Google-style docstrings
- nest generated docs under docs/lib and docs/mcp; add hand-written wiki
- adopt standard Type A PyPI CI pipeline (tag==version guard + quality gate)
- promote generated CHANGELOG.md; bump version to 0.0.3
2026-10-17 02:16:46 +05:30

81 lines
2.2 KiB
Python

"""
# Summary
Thread domain models for Mail Intake.
This module defines the **canonical, provider-agnostic representation**
of an email thread as used internally by the Mail Intake ingestion pipeline.
Threads group related messages and serve as the primary unit of reasoning
for higher-level correspondence workflows.
"""
from dataclasses import dataclass, field
from datetime import datetime
from mail_intake.models.message import MailIntakeMessage
@dataclass
class MailIntakeThread:
"""
Canonical internal representation of an email thread.
Notes:
**Guarantees:**
- A thread groups multiple related messages under a single subject
and participant set.
- It is designed to support reasoning over conversational context
such as job applications, interviews, follow-ups, and ongoing discussions.
- This model is provider-agnostic and safe to persist.
"""
thread_id: str
"""
Provider-specific thread identifier.
"""
normalized_subject: str
"""
Normalized subject line used to group related messages.
"""
participants: set[str] = field(default_factory=set)
"""
Set of unique participant email addresses observed in the thread.
"""
messages: list[MailIntakeMessage] = field(default_factory=list)
"""
Ordered list of messages belonging to this thread.
"""
last_activity_at: datetime | None = None
"""
Timestamp of the most recent message in the thread.
"""
def add_message(self, message: MailIntakeMessage) -> None:
"""
Add a message to the thread and update derived fields.
Args:
message (MailIntakeMessage):
Parsed mail message to add to the thread.
Notes:
**Responsibilities:**
- Appends the message to the thread.
- Tracks unique participants.
- Updates the last activity timestamp.
"""
self.messages.append(message)
if message.from_email:
self.participants.add(message.from_email)
if self.last_activity_at is None or message.timestamp > self.last_activity_at:
self.last_activity_at = message.timestamp