Skip to main content

Python EML parser library

Project description

Code Health https://travis-ci.com/GOVCERT-LU/eml_parser.svg?branch=master Documentation Status https://badge.fury.io/py/eml-parser.svg

eml_parser serves as a python module for parsing eml files and returning various information found in the e-mail as well as computed information.

Extracted and generated information include but are not limited to:

  • attachments - hashes - names

  • from, to, cc

  • received servers path

  • subject

  • list of URLs parsed from the text content of the mail (including HTML body/attachments)

Please feel free to send me your comments / pull requests.

Install the latest version using pip:

pip install eml_parser[file-magic]

Note: If you don’t want to / cannot use file-magic (e.g. if you are using python-magic), install via:

pip install eml_parser

Note for OSX users:

Make sure to install libmagic, else eml_parser will not work.

Warning:

This release is only compatible with Python3. The last release to be compatible with
Python2 is v1.2. If you do require Python2 support, please download that version.
You are strongly encouraged though to use Python3 as there are many parsing improvements
and much better RFC support.
This release is only tested with Python >=3.5.

Example on how to use:

import datetime
import json
import eml_parser


def json_serial(obj):
    if isinstance(obj, datetime.datetime):
        serial = obj.isoformat()
        return serial


with open('sample.eml', 'rb') as fhdl:
    raw_email = fhdl.read()

parsed_eml = eml_parser.eml_parser.decode_email_b(raw_email)

print(json.dumps(parsed_eml, default=json_serial))

Which gives for a minimalistic EML file something like this:

{
  "body": [
    {
      "content_header": {
        "content-language": [
          "en-US"
        ]
      },
      "hash": "6c9f343bdb040e764843325fc5673b0f43a021bac9064075d285190d6509222d"
    }
  ],
  "header": {
    "received_src": null,
    "from": "john.doe@example.com",
    "to": [
      "test@example.com"
    ],
    "subject": "Sample EML",
    "received_foremail": [
      "test@example.com"
    ],
    "date": "2013-04-26T11:15:47+00:00",
    "header": {
      "content-language": [
        "en-US"
      ],
      "received": [
        "from localhost\tby mta.example.com (Postfix) with ESMTPS id 6388F684168\tfor <test@example.com>; Fri, 26 Apr 2013 13:15:55 +0200"
      ],
      "to": [
        "test@example.com"
      ],
      "subject": [
        "Sample EML"
      ],
      "date": [
        "Fri, 26 Apr 2013 11:15:47 +0000"
      ],
      "message-id": [
        "<F96257F63EAEB94C890EA6CE1437145C013B01FA@example.com>"
      ],
      "from": [
        "John Doe <john.doe@example.com>"
      ]
    },
    "received_domain": [
      "mta.example.com"
    ],
    "received": [
      {
        "with": "esmtps id 6388f684168",
        "for": [
          "test@example.com"
        ],
        "by": [
          "mta.example.com"
        ],
        "date": "2013-04-26T13:15:55+02:00",
        "src": "from localhost by mta.example.com (postfix) with esmtps id 6388f684168 for <test@example.com>; fri, 26 apr 2013 13:15:55 +0200"
      }
    ]
  }
}

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

eml_parser-1.11.5.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

eml_parser-1.11.5-py3-none-any.whl (37.7 kB view details)

Uploaded Python 3

File details

Details for the file eml_parser-1.11.5.tar.gz.

File metadata

  • Download URL: eml_parser-1.11.5.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2+

File hashes

Hashes for eml_parser-1.11.5.tar.gz
Algorithm Hash digest
SHA256 a9bf5c7ee243d51c020188b4abe1fda3d51009e1afa233352a80638400bd6faa
MD5 23f5f59e48a6fac654354365c93f94a4
BLAKE2b-256 3cf0ed71d99541f7d4b7cb98b7744878aba040a78756c6307b4206dc3857b658

See more details on using hashes here.

File details

Details for the file eml_parser-1.11.5-py3-none-any.whl.

File metadata

  • Download URL: eml_parser-1.11.5-py3-none-any.whl
  • Upload date:
  • Size: 37.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2+

File hashes

Hashes for eml_parser-1.11.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4602e4630fbb2874e0f9a57e08f7510b257f13c10f14f0476fc380195ec59b69
MD5 cff96914c10389f4867fcfa53f3bfb5e
BLAKE2b-256 5ee6b96a517eda4603d3402c047d8bd38ddd7185a59386e1bfb478f057b1cce6

See more details on using hashes here.

Supported by

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