How to use the libratom.lib.constants.BodyType function in libratom

To help you get started, we’ve selected a few libratom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libratom / libratom / tests / unit / test_libratom.py View on Github external
            BodyType.RTF,
            "foo",
        ),
        ("<table><tbody><tr><td>foo</td></tr></tbody></table>", BodyType.HTML, "foo"),
    ],
)
def test_cleanup_message_body(body, body_type, result):
    assert cleanup_message_body(body, body_type) == result
github libratom / libratom / tests / unit / test_libratom.py View on Github external
        (Mock(), BodyType.PLAIN),
        (Mock(plain_text_body=None), BodyType.RTF),
        (Mock(plain_text_body=None, rtf_body=None), BodyType.HTML),
        (Mock(plain_text_body=None, rtf_body=None, html_body=None), None),
    ],
)
def test_get_message_body(message, body_type):
    assert PffArchive().get_message_body(message)[1] is body_type
github libratom / libratom / libratom / lib / utils.py View on Github external
def cleanup_message_body(
    body: AnyStr, body_type: BodyType, size_threshold: int = 0
) -&gt; str:
    # Decode first
    body = decode(body)

    if body_type is BodyType.RTF:
        # Strip formatting
        body = rtf_to_text(body)

    elif body_type is BodyType.HTML:
        # Strip markup
        body = BeautifulSoup(body, "html.parser").get_text()

    # Strip what might be lines of base64 encoded data
    if len(body) &gt; size_threshold:
        body = re.sub(r"^[&gt;\s]*[A-Za-z0-9+/]{76,}\n?", "", body, flags=re.MULTILINE)

    # Strip uuencoded attachments
    if len(body) &gt; size_threshold:
        body = re.sub(r"begin [0-7]{3}.*?end", "", body, flags=re.DOTALL)

    # Strip notes/calendar data
    if len(body) &gt; size_threshold:
        body = re.sub(
            r"&lt;(OMNI|omni)([^&gt;]*?)&gt;.*?(\s)*", "", body, flags=re.DOTALL
        )
github libratom / libratom / libratom / lib / pff.py View on Github external
def get_message_body(message: pypff.message) -> Tuple[str, Optional[BodyType]]:
        """Takes a pypff.message object and returns a body and body type

        Args:
            message: A pypff.message object

        Returns:
            A string and a body type
        """

        # Try the plain text body first
        if message.plain_text_body:
            return message.plain_text_body, BodyType.PLAIN

        if message.rtf_body:
            return message.rtf_body, BodyType.RTF

        if message.html_body:
            return message.html_body, BodyType.HTML

        return "", None
github libratom / libratom / libratom / lib / pff.py View on Github external
def get_message_body(message: pypff.message) -> Tuple[str, Optional[BodyType]]:
        """Takes a pypff.message object and returns a body and body type

        Args:
            message: A pypff.message object

        Returns:
            A string and a body type
        """

        # Try the plain text body first
        if message.plain_text_body:
            return message.plain_text_body, BodyType.PLAIN

        if message.rtf_body:
            return message.rtf_body, BodyType.RTF

        if message.html_body:
            return message.html_body, BodyType.HTML

        return "", None
github libratom / libratom / libratom / lib / mbox.py View on Github external
def get_message_body(message: Message) -> Tuple[str, Optional[BodyType]]:
        """
        Returns the message body along with a plain body type
        """
        return MboxArchive.format_message(message), BodyType.PLAIN
github libratom / libratom / libratom / lib / utils.py View on Github external
def cleanup_message_body(
    body: AnyStr, body_type: BodyType, size_threshold: int = 0
) -> str:
    # Decode first
    body = decode(body)

    if body_type is BodyType.RTF:
        # Strip formatting
        body = rtf_to_text(body)

    elif body_type is BodyType.HTML:
        # Strip markup
        body = BeautifulSoup(body, "html.parser").get_text()

    # Strip what might be lines of base64 encoded data
    if len(body) > size_threshold:
        body = re.sub(r"^[>\s]*[A-Za-z0-9+/]{76,}\n?", "", body, flags=re.MULTILINE)

    # Strip uuencoded attachments
    if len(body) > size_threshold:
        body = re.sub(r"begin [0-7]{3}.*?end", "", body, flags=re.DOTALL)

    # Strip notes/calendar data