def get_email_thread_id()

in backend-apis/app/utils/utils_workspace.py [0:0]


def get_email_thread_id(email_thread: dict) -> tuple:
    """

    Args:
        email_thread:

    Raises:
        HTTPException:

    Returns:

    """
    email_thread_id = ""
    email_message_id = ""
    try:
        # Get thread ID from the first message
        for header in email_thread["messages"][0]["payload"]["headers"]:
            if header["name"].lower() == "message-id":
                email_thread_id = header["value"]

        # Get message ID from the last message
        for header in email_thread["messages"][-1]["payload"]["headers"]:
            if header["name"].lower() == "message-id":
                email_message_id = header["value"]
    except Exception as e:
        raise HTTPException(status_code=400, detail=str(e)) from e

    return email_thread_id, email_message_id