if in_reply_to is None:
        raise ValueError
    thread_id = msg["threadId"]
    thread = service.users().threads().get(userId="me", id=thread_id).execute()
    messages = thread["messages"]
    response_email = None
    for message in messages:
        email_data = message["payload"]["headers"]
        for values in email_data:
            if values["name"] == "Message-ID":
                message_id = values["value"]
                if message_id == in_reply_to:
                    response_email = message
    if response_email is None:
        raise ValueError
    starter_content = _extract_email_content(response_email)
    return ChatSession(messages=[starter_content, message_content])
[docs]class GMailLoader(BaseChatLoader):
    """Load data from `GMail`.
    There are many ways you could want to load data from GMail.
    This loader is currently fairly opinionated in how to do so.
    The way it does it is it first looks for all messages that you have sent.
    It then looks for messages where you are responding to a previous email.
    It then fetches that previous email, and creates a training example
    of that email, followed by your email.
    Note that there are clear limitations here. For example,
    all examples created are only looking at the previous email for context.
    To use:
    - Set up a Google Developer Account:
        Go to the Google Developer Console, create a project,
        and enable the Gmail API for that project.
        This will give you a credentials.json file that you'll need later.
    """
[docs]    def __init__(self, creds: Any, n: int = 100, raise_error: bool = False) -> None:
        super().__init__()