{"id":2243,"library":"python-oxmsg","title":"Python-OXMSG","description":"Python-OXMSG is a library designed to parse Outlook MSG (.msg) files to extract email messages and their attachments. Its primary use case focuses on extracting message text and accessing attachments, rather than modifying messages or creating them from scratch. The library also allows access to other message properties like sent-date. The current version is 0.0.2.","status":"active","version":"0.0.2","language":"en","source_language":"en","source_url":"https://github.com/scanny/python-oxmsg","tags":["outlook","msg","email","attachments","parser"],"install":[{"cmd":"pip install python-oxmsg","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Used for the command-line interface.","package":"click","optional":false},{"reason":"Handles the underlying OLE Structured Storage format of .msg files.","package":"olefile","optional":false},{"reason":"Provides backported and experimental type hints.","package":"typing_extensions","optional":false}],"imports":[{"note":"Main class for loading and parsing .msg files.","symbol":"Message","correct":"from oxmsg import Message"}],"quickstart":{"code":"import os\nfrom oxmsg import Message\n\n# Create a dummy .msg file for demonstration purposes\n# In a real scenario, you would have an actual .msg file\ndummy_msg_content = b\"\"\"\nThis is a placeholder for a .msg file content.\nIn a real application, this would be binary data.\n\"\"\"\nwith open(\"message.msg\", \"wb\") as f:\n    f.write(dummy_msg_content)\n\ntry:\n    msg = Message.load(\"message.msg\")\n    print(f\"Message Class: {msg.message_class}\")\n    print(f\"Attachment Count: {msg.attachment_count}\")\n\n    if msg.attachment_count > 0:\n        attachment = msg.attachments[0]\n        print(f\"  Attachment File Name: {attachment.file_name}\")\n        print(f\"  Attachment MIME Type: {attachment.mime_type}\")\n        print(f\"  Attachment Size: {attachment.size}\")\n        if attachment.attached_by_value:\n            print(f\"  Attachment Bytes (first 20): {attachment.file_bytes[:20]}...\")\n            # Example of saving attachment:\n            # with open(attachment.file_name, \"wb\") as f:\n            #     f.write(attachment.file_bytes)\n        else:\n            print(\"  Attachment bytes not available directly (attached by reference).\")\n    else:\n        print(\"No attachments found.\")\n\nexcept Exception as e:\n    print(f\"Error processing MSG file: {e}\")\nfinally:\n    # Clean up the dummy file\n    if os.path.exists(\"message.msg\"):\n        os.remove(\"message.msg\")\n","lang":"python","description":"Loads a .msg file, accesses its properties like message class and attachment count, and demonstrates how to retrieve attachment details, including their content if available. Note that a real .msg file is required for actual parsing."},"warnings":[{"fix":"Do not attempt to use `python-oxmsg` for writing or altering .msg files; consider libraries like `msgforge` or `tutao/oxmsg` if creation/modification is needed (though `tutao/oxmsg` is a JavaScript library).","message":"The library explicitly states that it does not support modifying or creating Outlook MSG files. Its functionality is limited to parsing and extracting data.","severity":"gotcha","affected_versions":"0.0.1 and later"},{"fix":"Always check `attachment.attached_by_value` before attempting to read `attachment.file_bytes` to avoid unexpected empty byte strings or errors.","message":"When accessing attachment content, the `attachment.file_bytes` property is only populated if the attachment's `attached_by_value` property is `True`. If `attached_by_value` is `False`, the bytes are not directly available through this property, indicating it's an attachment by reference (e.g., a linked file).","severity":"gotcha","affected_versions":"0.0.1 and later"},{"fix":"Upgrade your Python environment to version 3.9 or newer. Python 3.9 reached end-of-life, so it is recommended to use actively supported versions like Python 3.10, 3.11, or 3.12.","message":"Python-OXMSG requires Python 3.9 or higher. Users running older Python versions will encounter installation or runtime errors.","severity":"breaking","affected_versions":"0.0.1 and later"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}