| 259 | |
| 260 | |
| 261 | class MessagesResource: |
| 262 | def __init__(self, api: MessagesApi, client: E2AClient) -> None: |
| 263 | self._api = api |
| 264 | self._c = client |
| 265 | |
| 266 | def list( |
| 267 | self, |
| 268 | email: str, |
| 269 | *, |
| 270 | direction: Optional[str] = None, |
| 271 | read_status: Optional[str] = None, |
| 272 | sort: Optional[str] = None, |
| 273 | from_: Optional[str] = None, |
| 274 | subject_contains: Optional[str] = None, |
| 275 | conversation_id: Optional[str] = None, |
| 276 | labels: Optional[List[str]] = None, |
| 277 | since: Optional[str] = None, |
| 278 | until: Optional[str] = None, |
| 279 | limit: Optional[int] = None, |
| 280 | ) -> AutoPager[MessageSummaryView]: |
| 281 | # `from` is a Python keyword; expose the idiomatic `from_` (PEP 8 trailing |
| 282 | # underscore) and translate to the generated base's `var_from` here so the |
| 283 | # generator's mangled name never leaks into the public SDK surface. |
| 284 | async def fetch(cursor: Optional[str]) -> Page: |
| 285 | resp = await self._c._read( |
| 286 | lambda h: self._api.list_messages( |
| 287 | email, |
| 288 | direction=direction, |
| 289 | read_status=read_status, |
| 290 | sort=sort, |
| 291 | var_from=from_, |
| 292 | subject_contains=subject_contains, |
| 293 | conversation_id=conversation_id, |
| 294 | labels=labels, |
| 295 | since=since, |
| 296 | until=until, |
| 297 | cursor=cursor, |
| 298 | limit=limit, |
| 299 | _headers=h, |
| 300 | ) |
| 301 | ) |
| 302 | return _page(resp.items, resp.next_cursor) |
| 303 | |
| 304 | return AutoPager(fetch) |
| 305 | |
| 306 | async def get(self, email: str, message_id: str) -> MessageView: |
| 307 | return await self._c._read(lambda h: self._api.get_message(email, message_id, _headers=h)) |
| 308 | |
| 309 | async def get_attachment( |
| 310 | self, email: str, message_id: str, index: int, *, inline: bool = False |
| 311 | ) -> AttachmentView: |
| 312 | # Metadata + a short-lived download_url (+ expires_at). inline=True also |
| 313 | # returns base64 `data` for small attachments (<=256 KB; larger error). |
| 314 | return await self._c._read( |
| 315 | lambda h: self._api.get_attachment(email, message_id, index, inline=inline, _headers=h) |
| 316 | ) |
| 317 | |
| 318 | async def send( |