6c86f0f571
- integrated request-module into module registry - moved backend into modules/request-module - added manifest.json and module.py - implemented dynamic router mounting - implemented dynamic static mounting - removed direct dependencies from platform core - verified startup with request-module - verified startup without request-module - added implementation_report_003.md
68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
"""Email message model for conversation threads."""
|
|
|
|
from sqlalchemy import Column, Text, DateTime, ForeignKey, Integer, String, Boolean
|
|
from sqlalchemy.orm import relationship
|
|
from request_app.models.base import Base, TimestampMixin
|
|
|
|
|
|
class EmailMessage(Base, TimestampMixin):
|
|
"""Email message model for ticket conversation threads."""
|
|
|
|
__tablename__ = "email_messages"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
ticket_id = Column(Integer, ForeignKey("tickets.id", ondelete="CASCADE"), nullable=False)
|
|
|
|
# Email metadata
|
|
direction = Column(String(10), nullable=False) # 'incoming' or 'outgoing'
|
|
message_id = Column(String(500)) # RFC 2822 Message-ID for threading
|
|
in_reply_to = Column(String(500)) # In-Reply-To for threading
|
|
references = Column(Text) # References header for threading
|
|
|
|
# Email addresses
|
|
from_address = Column(String(500), nullable=False)
|
|
to_addresses = Column(Text, nullable=False) # Comma-separated
|
|
cc_addresses = Column(Text)
|
|
|
|
# Content
|
|
subject = Column(String(4000))
|
|
body_text = Column(Text) # Plain text body
|
|
body_html = Column(Text) # HTML body
|
|
|
|
# Status
|
|
is_read = Column(Boolean, default=False)
|
|
sent_at = Column(DateTime) # When the email was actually sent
|
|
received_at = Column(DateTime) # When the email was received
|
|
|
|
# User who sent the reply (for outgoing)
|
|
sent_by = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"))
|
|
|
|
# Relationships
|
|
ticket = relationship("Ticket", back_populates="email_messages")
|
|
sender = relationship("User", foreign_keys=[sent_by])
|
|
attachments = relationship("EmailAttachment", back_populates="email_message", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<EmailMessage(id={self.id}, direction='{self.direction}', subject='{self.subject}')>"
|
|
|
|
|
|
class EmailAttachment(Base, TimestampMixin):
|
|
"""Email attachment model."""
|
|
|
|
__tablename__ = "email_attachments"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
email_message_id = Column(Integer, ForeignKey("email_messages.id", ondelete="CASCADE"), nullable=False)
|
|
|
|
# File info
|
|
filename = Column(String(500), nullable=False)
|
|
content_type = Column(String(255))
|
|
file_size = Column(Integer) # Size in bytes
|
|
file_path = Column(String(1000)) # Path to stored file
|
|
|
|
# Relationships
|
|
email_message = relationship("EmailMessage", back_populates="attachments")
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<EmailAttachment(id={self.id}, filename='{self.filename}')>"
|