You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
# backend/app/connectors/mail/__init__.py
|
|
# 메일 페이지 읽기 커넥터. Email 테이블을 직접 읽는다(Gmail/Outlook sync 가 적재한 실데이터).
|
|
# 발송은 결재→OutboundMail→connector.send_mail 경로(여기엔 mock 발송 없음, phase-16+).
|
|
from abc import ABC, abstractmethod
|
|
|
|
from sqlmodel import Session, select
|
|
|
|
from ...models import Email
|
|
|
|
|
|
class MailConnector(ABC):
|
|
@abstractmethod
|
|
def list_inbox(self, s: Session, account: str | None) -> list[Email]: ...
|
|
|
|
@abstractmethod
|
|
def get(self, s: Session, email_id: str) -> Email | None: ...
|
|
|
|
|
|
class MailReadConnector(MailConnector):
|
|
"""Email 테이블 읽기(실데이터). 실 메일 유입은 phase-13 sync 프레임워크가 같은 테이블에 적재."""
|
|
|
|
def list_inbox(self, s, account):
|
|
# 최신순(received_at DESC). received_at 없는(레거시/시드/mock) 행은 NULL → 뒤로 가고,
|
|
# 그 사이에선 sort_order(시드 의도) → created_at 으로 결정적으로 정렬.
|
|
q = (
|
|
select(Email)
|
|
.where(Email.archived == False) # noqa: E712
|
|
.order_by(
|
|
Email.received_at.desc(),
|
|
Email.sort_order,
|
|
Email.created_at.desc(),
|
|
)
|
|
)
|
|
if account:
|
|
q = q.where(Email.account == account)
|
|
# 프로모션/소셜도 숨기지 않고 함께 반환 — 프론트의 카테고리 탭(기본/프로모션/…)에서 분류.
|
|
return list(s.exec(q).all())
|
|
|
|
def get(self, s, email_id):
|
|
return s.get(Email, email_id)
|
|
|
|
|
|
def get_mail_connector() -> MailConnector:
|
|
return MailReadConnector()
|