Skip to main content

Code Health Travis CI Documentation Status PyPI PyPI pyversions

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.

For the changelog, please see CHANGELOG.md.

Installation:

pip install eml_parser[filemagic]

⚠️ 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

Known Issues

OSX users

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

Python <=3.7.4 "rare header field parsing issue"

It has been reported (in #60) that there are parsing issues in some particular cases which seem to be caused by a bug in the email module of the Python standard library. At least versions <=3.7.4 are affected.

Python versions >=3.7.11 are not affected. If you do get KeyError exceptions on header field parsing, you should consider upgrading to a more recent version of Python.

-> Please open an issue if the error persists after upgrading.

Example usage:

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()

ep = eml_parser.EmlParser()
parsed_eml = ep.decode_email_bytes(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"
        }
      ]
    }
  }

Metadata

Release files for eml-parser 1.17.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eml-parser 1.17.4
File Size Uploaded Provenance Actions
eml_parser-1.17.4.tar.gz 1.0 MB Without provenance Details for eml_parser-1.17.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for eml-parser 1.17.4
File Interpreter ABI Platform Actions
eml_parser-1.17.4-py3-none-any.whl Python 3 none any Details for eml_parser-1.17.4-py3-none-any.whl

Total release size: 1.0 MB

Release files / eml_parser-1.17.4.tar.gz

Download URL eml_parser-1.17.4.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
faca2300b8cfe1b2152455d2d8a6b86cba249dbbd1b89d579c5e93fad0a127cc
BLAKE2b-256 checksum
How to use checksums
4fae90e378f63106876bd736de20f8fd25d815954dc3c533d3b6c8692fcec25c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Release files / eml_parser-1.17.4-py3-none-any.whl

Download URL eml_parser-1.17.4-py3-none-any.whl
Size 37.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1c44c3122d7f9502a28bef63909a57a0f64780be8a8860c5f6d30b6f04aeaaa
BLAKE2b-256 checksum
How to use checksums
574c24026eb203e2a7a088205512b5f77b0537d8da3a5b7fb72216af298e8e82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Security for eml-parser 1.17.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.17.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page