{"id":4095,"library":"mail-parser","title":"mail-parser","description":"mail-parser is a production-grade, RFC-compliant email parsing library that enhances the Python standard library's email module. It extracts all details into a comprehensive object, including headers, plain text and HTML bodies, attachments, and routing information, with a strong focus on security analysis and defect detection. It provides access to parsed elements as Python objects, raw strings, and JSON. The library is actively maintained.","status":"active","version":"4.2.1","language":"en","source_language":"en","source_url":"https://github.com/SpamScope/mail-parser","tags":["email","parsing","MIME","RFC","security","forensics","outlook"],"install":[{"cmd":"pip install mail-parser","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Runtime environment","package":"python","version":">=3.9, <3.15"}],"imports":[{"note":"Main library import for accessing parsing functions.","symbol":"mailparser","correct":"import mailparser"},{"note":"One of several factory methods to parse emails from different sources (string, bytes, file, etc.).","symbol":"parse_from_string","correct":"mail = mailparser.parse_from_string(raw_email_string)"}],"quickstart":{"code":"import mailparser\n\nraw_email = (\n    \"From: Sender Name <sender@example.com>\\n\"\n    \"To: Recipient Name <recipient@example.com>\\n\"\n    \"Subject: Test Email from mail-parser\\n\"\n    \"Content-Type: text/plain; charset=\\\"utf-8\\\"\\n\"\n    \"\\n\"\n    \"Hello, this is the plain text body of the email.\\n\"\n    \"It was parsed using the mail-parser library.\"\n)\n\nmail = mailparser.parse_from_string(raw_email)\n\nprint(f\"From: {mail.from_}\")\nprint(f\"Subject: {mail.subject}\")\nif mail.text_plain:\n    print(f\"Body: {mail.text_plain[0]}\")\n\n# Example of accessing the 'to' address list\nfor recipient in mail.to:\n    print(f\"To Name: {recipient[0]}, Address: {recipient[1]}\")","lang":"python","description":"Parses a raw email string and extracts basic headers and the plain text body. Demonstrates accessing structured email components like sender, subject, and body content."},"warnings":[{"fix":"Review existing parsing logic and test against the new version. Consult GitHub issues or the project's changelog for specific changes if parsing failures occur. Consider reporting new regressions if unaddressed.","message":"Some parsing behavior for complex or malformed emails may have changed between versions 3.x and 4.x. A GitHub issue indicates a regression where emails parse successfully in 3.15.0 but fail in 4.0.0. Users upgrading from 3.x to 4.x should thoroughly test their email parsing routines, especially for edge cases.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"On Debian/Ubuntu: `sudo apt-get install libemail-outlook-message-perl`. For other operating systems, consult the project's documentation for equivalent dependencies or alternatives.","message":"Parsing Microsoft Outlook .msg files requires an external system dependency on Debian-based systems. You need to install `libemail-outlook-message-perl` for this functionality.","severity":"gotcha","affected_versions":"All"},{"fix":"Always verify the PyPI project page (https://pypi.org/project/mail-parser/) and the GitHub repository (https://github.com/SpamScope/mail-parser) to confirm you have the correct package. Use `pip install mail-parser` for installation.","message":"The `mail-parser` library can be confused with other similarly named Python packages (e.g., `fast_mail_parser`, `mailparse`, `msg-parser`) or web services (e.g., `Mailparser.io`). Ensure you are importing and using the correct library from the `SpamScope` organization.","severity":"gotcha","affected_versions":"All"},{"fix":"Always append an underscore when referring to the 'From' header attribute, e.g., `parsed_mail.from_`.","message":"When accessing the 'From' header, use `mail.from_` (with an underscore) instead of `mail.from` because `from` is a reserved keyword in Python. Attempting to use `mail.from` will result in a `SyntaxError`.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}