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.
Metadata
Release files for RTFDE 0.1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rtfde-0.1.2.2.tar.gz | 33.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rtfde-0.1.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 70.1 kB
Release files / rtfde-0.1.2.2.tar.gz
| Download URL | rtfde-0.1.2.2.tar.gz |
|---|---|
| Size | 33.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f0cd6ecd644071e39452e6fc4f4a1435453af0ec7c90ea86fb4fc96010c7f1b
|
|
BLAKE2b-256 checksum How to use checksums |
9e5c116a016b38af589e8141160bc9b034b73dde2e50c22a921751f4d982a7ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / rtfde-0.1.2.2-py3-none-any.whl
| Download URL | rtfde-0.1.2.2-py3-none-any.whl |
|---|---|
| Size | 36.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d43868c74f21ae9ea5acbfd4176d5de1f2cfae0ff7f267698471c606287c04ec
|
|
BLAKE2b-256 checksum How to use checksums |
14245a653278259be44c1845ddd56dd30cfa7265281ba149b9342b79f9d4f788
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|