Skip to main content

A library for extracting HTML content from RTF encapsulated HTML as commonly found in the exchange MSG email format.

Project description

RTFDE: RTF De-Encapsulator

A python3 library for extracting encapsulated HTML & plain text content from the RTF bodies of .msg files.

De-encapsulation enables previously encapsulated HTML and plain text content to be extracted and rendered as HTML and plain text instead of the encapsulating RTF content. After de-encapsulation, the HTML and plain text should differ only minimally from the original HTML or plain text content.

Features

  • De-encapsulate HTML from RTF encapsulated HTML.
  • De-encapsulate plain text from RTF encapsulated text.

Known Issues

  • This library fully unquotes text it de-encapsulates because it does not know which text was quoted in the RTF conversion process and which text was quoted in the original html/text. So, for instance escaped Quoted-Printable text will be returned un-escaped.
  • This library currently can't combine attachments from a .MSG Message object with the de-encapsulated HTML. This is mostly because I could not get a good set of examples of encapsulated HTML which had attachment objects that needed to be integrated back into the body of the HTML.

Anti-Features (I don't intend to have this library do this.)

  • Extract plain text from RTF encapsulated HTML. If you want this, then you will have to parse the HTML using another library.

Installation

To install from the pip package.

pip3 install RTFDE

Usage

De-encapsulating HTML or TEXT

from RTFDE.deencapsulate import DeEncapsulator

with open('rtf_file', 'rb') as fp:
    raw_rtf  = fp.read()
    rtf_obj = DeEncapsulator(raw_rtf)
    rtf_obj.deencapsulate()
    if rtf_obj.content_type == 'html':
        print(rtf_obj.html)
    else:
        print(rtf_obj.text)

Enabling Logging

Any logging (including how verbose the logging is) can be handled by configuring logging. You can enable RTFDE's logging at the highest level by getting and setting the "RTFDE" logger.

log = logging.getLogger("RTFDE")
log.setLevel(logging.INFO)

To see how to enable more in-depth logging for debugging check out the CONTRIBUTING.md file.

# Now, get the log that you want
# The main logger is simply called RTFDE. That will get you all the *normal* logs.
requests_log = logging.getLogger("RTFDE")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

Contribute

Please check the contributing guidelines

License

Please see the license file for license information on RTFDE. If you have further questions related to licensing PLEASE create an issue about it on github.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

RTFDE-0.1.1.tar.gz (43.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

RTFDE-0.1.1-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file RTFDE-0.1.1.tar.gz.

File metadata

  • Download URL: RTFDE-0.1.1.tar.gz
  • Upload date:
  • Size: 43.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for RTFDE-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9e43485e79b2dd1018127735d8134f65d2a9d73af314d2a101f10346333b241e
MD5 69a53d98e15a51ddc9eeb2fd84657816
BLAKE2b-256 8db00ac16842c6875ed36e48cb97e8bc70f9fdb742b10d590af51fe34311c87f

See more details on using hashes here.

File details

Details for the file RTFDE-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: RTFDE-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for RTFDE-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ea7ab0e0b9d4af08415f5017ecff91d74e24216a5e4e4682155cedc478035e99
MD5 901023d4260ef94b3beedcbcf0342744
BLAKE2b-256 e1d2b9136b0bedbe1ed03f27e439b6c2572d9f47a18e883da66093357c63c37b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page