Skip to content

Extract email headers

Upload an email and get its headers.

Code example
import asyncio
from pathlib import Path
from ptsandbox import Sandbox, SandboxKey

async def example() -> None:
    async with Sandbox(key=SandboxKey(...)) as sandbox:
        with open("./email-headers", "wb") as fd:
            async for chunk in sandbox.get_email_headers(Path("./email.bin")):
                await asyncio.to_thread(fd.write, chunk)

ptsandbox.sandbox.sandbox.Sandbox.get_email_headers async

get_email_headers(file: str | Path | bytes | BinaryIO) -> AsyncIterator[bytes]

Upload an email to receive headers

Parameters:

  • file (str | Path | bytes | BinaryIO) –

    path to .eml file, its content or a binary stream

Returns:

  • AsyncIterator[bytes] –

    The header file

Raises:

  • SandboxException –

    if the file type is not supported or the file cannot be opened

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors

ptsandbox.sandbox.api._analysis.AnalysisMixin.get_email_headers async

get_email_headers(data: str | Path | bytes | BinaryIO) -> AsyncIterator[bytes]

Upload an email to receive headers

Parameters:

  • data (str | Path | bytes | BinaryIO) –

    path to .eml file, its content or a binary stream

Returns:

  • AsyncIterator[bytes] –

    The header file

Raises:

  • ClientResponseError –

    if the server returns an error status

  • ClientError –

    on connection or transport errors