Giter VIP home page Giter VIP logo

tnefparse's Introduction

tnefparse - TNEF decoding and attachment extraction

CI Status

This is a pure-python library for decoding Microsoft's Transport Neutral Encapsulation Format (TNEF), for Python versions 3.6+ and PyPy3. The last version to support Python2 was 1.3.1. For more information on TNEF, see for example wikipedia. The full TNEF specification is also available as a PDF download.

A tnefparse command-line utility is provided for listing contents of TNEF files, extracting attachments found inside them and so on:

usage: tnefparse [-h] [-o] [-a] [-p PATH] [-b] [-hb]
                 [-l LEVEL] [-c]
                 file [file ...]

Extract TNEF file contents. Show this help message if no arguments are given.

positional arguments:
  file                  space-separated list of paths to the TNEF files

optional arguments:
  -h, --help             show this help message and exit
  -o, --overview         show (possibly long) overview of TNEF file contents
  -a, --attachments      extract attachments, by default to current dir
  -z, --zip              extract attachments into a single zip file, by default to current dir
  -p PATH, --path PATH   optional explicit path to extract attachments to
  -b, --body             extract the body to stdout
  -hb, --htmlbody        extract the HTML body to stdout
  -rb, --rtfbody         extract the RTF body to stdout
  -l LEVEL, --log LEVEL  set log level to DEBUG, INFO, WARN or ERROR
  -c, --checksum         calculate checksums (off by default)
  -d, --dump             extract a json dump of the tnef contents

The library can also be used as a basis for applications that need to parse TNEF. To parse a TNEF attachment, run eg. :

>>> from tnefparse import TNEF
>>> with open("tests/examples/one-file.tnef", "rb") as tneffile:
...    tnefobj = TNEF(tneffile.read())

The parsed attachment contents are then available as TNEF object attributes:

  • signature - TNEF file signature
  • key - generated by TNEF enabled transports before using the TNEF implementation to generate a TNEF stream
  • codepage - a Windows code page string
  • objects - a collection of TNEFObject instances
  • attachments - a collection of TNEFAttachment instances
  • mapiprops - a collection of MAPI properties represented by TNEFMAPI_Attribute instances
  • body - message body (may contain both HTML and RTF)
  • htmlbody - a string containing just the HTML message body
  • rtfbody - just the RTF body

Some of the above properties may be empty, depending on what's contained in the attachment that was parsed.

Tests

To run the test suite, all you need is tox. tox will run all tests on all supported Python versions.

If you want to run the tests only for e.g. Python 3.8, just enter tox -e py38.

You also can run a subset of tests in a specific environment by invoking e.g. tox -e py38 -- -k test_cmdline.

With tox -e coverage you can generate a coverage report. The output will be shown in the terminal and a HTML coverage report will be generated in the htmlcov directory.

Contributing

Issues and pull requests welcome. Please however always provide an example TNEF file that can be used to demonstrate the bug or desired behavior, if at all possible.

Note: If you have understanding of TNEF and/or MIME internals or just need this package and want to help with maintaining it, I am open to giving you commit rights. Just let me know.

tnefparse's People

Contributors

petri avatar jugmac00 avatar eumiro avatar beercow avatar dmbaggett avatar styxman avatar albrechtd avatar mlaferrera avatar 1nf0rmed avatar rosspatterson avatar wataru-chocola avatar evomassiny avatar venilton avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.