(body)
return mail
Get a email.message from a body email.

    Note: If there are problems encoding it, it will replace it to *ascii*.

    Args:
        body (:obj:`bytes` or :obj:`str`): The content, with or without
            headers, of a email message.

    Returns:
        email.message.Message: The object representing it.

    Raises:
        TypeError: If the content is empty.
Get a email.message from a body email.
Get a email . message from a body email .
def new_message(body):
    # type: (AnyStr) -> Email
    """Get a email.message from a body email.

    Note: If there are problems encoding it, it will replace it to *ascii*.

    Args:
        body (:obj:`bytes` or :obj:`str`): The content, with or without
            headers, of a email message.

    Returns:
        email.message.Message: The object representing it.

    Raises:
        TypeError: If the content is empty.

    """
    mail = None

    if isinstance(body, bytes):
        mail = email.message_from_bytes(body)  # pylint: disable=no-member
        if mail.as_bytes() in [b'', b'\n']:
            raise TypeError(
                __("body '{}' cannot be empty.".format(repr(body))))
        return mail

    try:
        mail = email.message_from_string(body)
    except UnicodeEncodeError:
        body = body.encode("ascii", errors='replace')
        mail = email.message_from_string(body)
    if mail.as_string() in ['', '\n']:
        raise TypeError(
            __("body '{}' cannot be empty.".format(repr(body))))
    return mail
def new_message ( body ) : # type: (AnyStr) -> Email mail = None if isinstance ( body , bytes ) : mail = email . message_from_bytes ( body ) # pylint: disable=no-member if mail . as_bytes ( ) in [ b'' , b'\n' ] : raise TypeError ( __ ( "body '{}' cannot be empty." . format ( repr ( body ) ) ) ) return mail try : mail = email . message_from_string ( body ) except UnicodeEncodeError : body = body . encode ( "ascii" , errors = 'replace' ) mail = email . message_from_string ( body ) if mail . as_string ( ) in [ '' , '\n' ] : raise TypeError ( __ ( "body '{}' cannot be empty." . format ( repr ( body ) ) ) ) return mail